-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathsetup.py
More file actions
275 lines (226 loc) · 7.63 KB
/
setup.py
File metadata and controls
275 lines (226 loc) · 7.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# coding: utf-8
# Copyright (c) 2025 inclusionAI.
import logging
import os
import sys
import re
import subprocess
from setuptools import setup, find_packages
from setuptools.command.sdist import sdist
from setuptools.command.install import install
from setuptools.dist import Distribution
from aworld.version_gen import __version__
logger = logging.getLogger("setup")
version_template = """
# auto generated
class VersionInfo(object):
@property
def build_date(self):
return "{BUILD_DATE}"
@property
def version(self):
return "{BUILD_VERSION}"
@property
def build_user(self):
return "{BUILD_USER}"
"""
def check_output(cmd):
import subprocess
output = subprocess.check_output(cmd)
return output.decode("utf-8")
def get_build_date():
import datetime
import time
ts = time.time()
return datetime.datetime.fromtimestamp(ts).strftime("%Y-%m-%d %H:%M:%S")
def build_version_template():
import getpass
return version_template.format(
BUILD_USER=getpass.getuser(),
BUILD_VERSION=__version__,
BUILD_DATE=get_build_date(),
)
def call_process(cmd, raise_on_error=True, logging=True):
if isinstance(cmd, str):
shell = True
else:
shell = False # cmd should be list of args
try:
subprocess.check_call(cmd, shell=shell, timeout=60)
except subprocess.CalledProcessError as e:
if raise_on_error:
raise e
logger.error(f"Fail to execute {cmd}, {e}")
return e.returncode
if logging:
logger.info(f"Successfully execute: {cmd}")
return 0
class AWorldPackage(sdist):
def run(self):
from aworld.version_gen import generate_version_info
home = os.path.join(os.path.dirname(__file__), "aworld")
with open(os.path.join(home, "version.py"), "w") as f:
version_info = build_version_template()
f.write(version_info)
generate_version_info(scenario="AWORLD_SDIST")
sdist.run(self)
class AWorldInstaller(install):
EXTRA_ENV = "AWORLD_EXTRA"
BASE = "framework"
BASE_OPT = "optional"
def __init__(self, *args, **kwargs):
super(AWorldInstaller, self).__init__(*args, **kwargs)
self._requirements = parse_requirements("aworld/requirements.txt")
self._extra = os.getenv(self.EXTRA_ENV)
logger.info(f"{os.getcwd()}: Install AWORLD using extra: {self._extra}")
def run(self):
# 1. build wheel using this setup.py, thus using the right install_requires according to ALPS_EXTRA
# 2. install this wheel into pip
install.run(self)
reqs = self._requirements.get(self.BASE, [])
self._install_reqs(reqs, ignore_error=True)
# install optional requirements here since pip install doesn't ignore requirement error
reqs = self._requirements.get(self.BASE_OPT, [])
self._install_reqs(reqs, ignore_error=True)
def _contains_module(self, module):
if self._extra is None:
return False
modules = [mod.strip() for mod in self._extra.split(",")]
try:
modules.index(module)
return True
except ValueError:
return False
@staticmethod
def _install_reqs(reqs, ignore_error=False, no_deps=False):
"""
Install a list of requirements using pip.
Use argument lists (no shell) to avoid quoting issues on Windows (single quotes are literal).
"""
base_cmd = [sys.executable, "-m", "pip", "install"]
if no_deps:
base_cmd.append("--no-deps")
if ignore_error:
# install requirements one by one so a failure doesn't stop the rest
for req in reqs:
try:
cmd = base_cmd + [req]
call_process(cmd)
logger.info(f"Installing optional package {req} have succeeded.")
except Exception:
logger.warning(
f"Installing optional package {req} is failed, Ignored."
) # ignore
elif reqs:
cmd = base_cmd + list(reqs)
call_process(cmd)
logger.info(f"Packages {str(reqs)} have been installed.")
def parse_requirements(req_fname):
requirements = {}
module_name = "unknown"
for line in open(req_fname, "r"):
match = re.match(r"#+\s+\[(\w+)\]\s+#+", line.strip())
if match:
# the beginning of a module
module_name = match.group(1)
else:
req = line.strip()
if not req or req.startswith("#"):
continue
# it's a requirement, strip trailing comments
pos = req.find("#")
if pos > 0:
req = req[:pos]
req = req.strip()
if module_name not in requirements:
requirements[module_name] = []
requirements[module_name].append(req)
return requirements
def get_install_requires(extra, requirements):
modules = [AWorldInstaller.BASE]
if extra is None:
# old style of `pip install alps`, install all requirements for compatibility
for mod in requirements:
if mod in [AWorldInstaller.BASE, AWorldInstaller.BASE_OPT]:
continue
modules.append(mod)
else:
for mod in extra.split(","):
mod = mod.strip()
if mod != AWorldInstaller.BASE:
modules.append(mod)
install_reqs = []
for mod in modules:
install_reqs.extend(requirements.get(mod, []))
return install_reqs
def get_python_requires():
return ">=3.10"
class BinaryDistribution(Distribution):
"""This class is needed in order to create OS specific wheels."""
@staticmethod
def has_ext_modules():
return True
requirements = parse_requirements("aworld/requirements.txt")
extra = os.getenv(AWorldInstaller.EXTRA_ENV, None)
setup(
name="aworld",
version=__version__,
description="Ant Agent Package",
url="https://github.com/inclusionAI/AWorld",
author="Ant AI",
author_email="",
long_description="",
long_description_content_type="text/markdown",
packages=find_packages(
where=".",
exclude=[
"tests",
"tests.*",
"*.tests",
"*.tests.*",
"test",
"*.test",
"*.test.*",
"test.*",
],
),
package_data={
"aworld": [
"virtual_environments/browsers/script/*.js",
"dataset/gaia/gaia.npy",
"requirements.txt",
"config/*.yaml",
"config/*.json",
"config/*.tiktoken",
"cmd/web/webui/public/trace_ui.html",
"cmd/web/webui/dist/**",
],
"examples": [
"**/mcp.json",
"gaia/GAIA/**",
],
},
license="MIT",
platforms=["any"],
keywords=["multi-agent", "agent", "environment", "tool", "sandbox"],
cmdclass={
"sdist": AWorldPackage,
"install": AWorldInstaller,
},
install_requires=get_install_requires(extra, requirements),
python_requires=get_python_requires(),
classifiers=[
"Development Status :: 5 - Production/Stable",
# Indicate who your project is intended for
"Intended Audience :: Developers",
"Topic :: Software Development :: Build Tools",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
],
entry_points={
"console_scripts": [
"aworld = aworld.__main__:main",
]
},
)