forked from facebook/Ax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
141 lines (116 loc) · 4.06 KB
/
setup.py
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
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
import subprocess
import numpy
from Cython.Build import cythonize
from setuptools import find_packages, setup
from setuptools.extension import Extension
EXTENSIONS = [
Extension(
"ax.utils.stats.sobol",
["ax/utils/stats/sobol.pyx"],
include_dirs=[numpy.get_include()],
)
]
REQUIRES = [
"botorch>=0.1.3",
"jinja2", # also a Plotly dep
"pandas",
"scipy",
"sklearn",
"plotly",
]
# pytest-cov requires pytest >= 3.6
DEV_REQUIRES = [
"beautifulsoup4",
"black",
"flake8",
"pytest>=3.6",
"pytest-cov",
"sphinx",
"sphinx-autodoc-typehints",
]
MYSQL_REQUIRES = ["SQLAlchemy>=1.1.13"]
NOTEBOOK_REQUIRES = ["jupyter"]
def get_git_version(abbreviate: bool = False) -> str:
"""Gets the latest Git tag (as a string), e.g. 0.1.2.
Note that `git describe --tags` works as follows:
- Finds the most recent tag that is reachable from a commit.
- If the tag points to the commit, then only the tag is shown.
- Otherwise, it suffixes the tag name with the number of additional commits
on top of the tag, and the abbreviated name of the most recent commit,
e.g. 0.1.2-9-g2118b21. If you add `--abbrev=0`, this suffix is removed.
This behavior is controlled by the `abbrev` parameter.
"""
cmd = ["git", "describe", "--tags"]
if abbreviate:
cmd.append("--abbrev=0")
try:
out = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
return out.strip().decode("ascii")
except (subprocess.SubprocessError, OSError):
return "Unknown"
def write_version_py(version: str) -> None:
"""Write the current package version to a Python file (ax/version.py)
This file will be imported by ax/__init__.py, so that users can determine
the current version by running `from ax import __version__`.
"""
content = """#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
# THIS FILE IS GENERATED FROM AX SETUP.PY
version = "%s"
"""
f = open("ax/version.py", "w")
try:
f.write(content % version)
finally:
f.close()
return version
def setup_package() -> None:
"""Used for installing the Ax package.
First, we determine the current version by getting the latest tag from Git.
We write this version to a file (ax/version.py), which is imported by
__init__.py. We also pass this version to setuptools below.
"""
# Grab current version from Git
# Abbreviated version (e.g. 0.1.2) will be used by setuptools
# Unabbreviated version (e.g. 0.1.2-9-g2118b21) will be used by __init__.py
abbreviated_version = get_git_version(abbreviate=True)
version = get_git_version(abbreviate=False)
# Write unabbreviated version to version.py
write_version_py(version)
with open("README.md", "r") as fh:
long_description = fh.read()
setup(
name="ax-platform",
version=abbreviated_version,
description="Adaptive Experimentation",
author="Facebook, Inc.",
license="MIT",
url="https://github.com/facebook/Ax",
keywords=["Experimentation", "Optimization"],
classifiers=[
"Development Status :: 4 - Beta",
"Operating System :: POSIX :: Linux",
"Operating System :: MacOS :: MacOS X",
"Programming Language :: Python :: 3",
],
long_description=long_description,
long_description_content_type="text/markdown",
python_requires=">=3.6",
setup_requires=["cython", "numpy"],
install_requires=REQUIRES,
packages=find_packages(),
ext_modules=cythonize(EXTENSIONS),
package_data={
# include all js, css, and html files in the package
"": ["*.js", "*.css", "*.html"]
},
extras_require={
"dev": DEV_REQUIRES,
"mysql": MYSQL_REQUIRES,
"notebook": NOTEBOOK_REQUIRES,
},
)
if __name__ == "__main__":
setup_package()