forked from awslabs/gluonts
-
Notifications
You must be signed in to change notification settings - Fork 9
/
setup.py
307 lines (245 loc) · 9.63 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
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# Standard library imports
import distutils.cmd
import distutils.log
import itertools
import logging
import os
import subprocess
import sys
from pathlib import Path
from textwrap import dedent
# Third-party imports
from setuptools import find_namespace_packages, setup
ROOT = Path(__file__).parent
SRC = ROOT / "src"
GPU_SUPPORT = 0 == int(
subprocess.call(
"nvidia-smi",
shell=True,
stdout=open(os.devnull, "w"),
stderr=open(os.devnull, "w"),
)
)
try:
from sphinx import apidoc, setup_command
HAS_SPHINX = True
except ImportError:
logging.warning(
"Package 'sphinx' not found. You will not be able to build the docs."
)
HAS_SPHINX = False
def read(*names, encoding="utf8"):
with (ROOT / Path(*names)).open(encoding=encoding) as fp:
return fp.read()
def find_requirements(filename):
with (ROOT / "requirements" / filename).open() as f:
mxnet_old = "mxnet"
mxnet_new = "mxnet-cu92mkl" if GPU_SUPPORT else mxnet_old
return [
line.rstrip().replace(mxnet_old, mxnet_new, 1)
for line in f
if not (line.startswith("#") or line.startswith("http"))
]
def get_version_and_cmdclass(version_file):
with open(version_file) as fobj:
code = fobj.read()
globals_ = {"__file__": str(version_file)}
exec(code, globals_)
return globals_["__version__"], globals_["cmdclass"]()
version, version_cmdclass = get_version_and_cmdclass("src/gluonts/_version.py")
class TypeCheckCommand(distutils.cmd.Command):
"""A custom command to run MyPy on the project sources."""
description = "run MyPy on Python source files"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
"""Run command."""
# import here (after the setup_requires list is loaded),
# otherwise a module-not-found error is thrown
import mypy.api
mypy_opts = ["--follow-imports=silent", "--ignore-missing-imports"]
mypy_args = [str(p.parent.resolve()) for p in SRC.glob("**/.typesafe")]
print(
"the following folders contain a `.typesafe` marker file "
"and will be type-checked with `mypy`:"
)
print("\n".join([" " + arg for arg in mypy_args]))
std_out, std_err, exit_code = mypy.api.run(mypy_opts + mypy_args)
print(std_out, file=sys.stdout)
print(std_err, file=sys.stderr)
if exit_code:
error_msg = dedent(
f"""
Mypy command
mypy {" ".join(mypy_opts + mypy_args)}
returned a non-zero exit code. Fix the type errors listed above
and then run
python setup.py type_check
in order to validate your fixes.
"""
).lstrip()
print(error_msg, file=sys.stderr)
sys.exit(exit_code)
class StyleCheckCommand(distutils.cmd.Command):
"""A custom command to run MyPy on the project sources."""
description = "run Black style check on Python source files"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
"""Run command."""
# import here (after the setup_requires list is loaded),
# otherwise a module-not-found error is thrown
import click
import black
black_opts = []
black_args = [
str(ROOT / folder)
for folder in ["src", "test", "examples"]
if (ROOT / folder).is_dir()
]
print(
"Python files in the following folders will be style-checked "
"with `black`:"
)
print("\n".join([" " + arg for arg in black_args]))
# a more direct way to call black
# this bypasses the problematic `_verify_python3_env` call in
# `click.BaseCommand.main`, which brakes things on Brazil builds
ctx = black.main.make_context(
info_name="black", args=["--check"] + black_opts + black_args
)
try:
exit_code = black.main.invoke(ctx)
except SystemExit as e:
exit_code = e.code
except click.exceptions.Exit as e:
exit_code = e.exit_code
if exit_code:
error_msg = dedent(
f"""
Black command
black {" ".join(['--check'] + black_opts + black_args)}
returned a non-zero exit code. Fix the files listed above with
black {" ".join(black_opts + black_args)}
and then run
python setup.py style_check
in order to validate your fixes.
"""
).lstrip()
print(error_msg, file=sys.stderr)
sys.exit(exit_code)
docs_require = find_requirements("requirements-docs.txt")
tests_require = find_requirements("requirements-test.txt")
sagemaker_api_require = find_requirements(
"requirements-extras-sagemaker-sdk.txt"
)
shell_require = find_requirements("requirements-extras-shell.txt")
setup_requires = find_requirements("requirements-setup.txt")
dev_require = (
docs_require
+ tests_require
+ shell_require
+ setup_requires
+ sagemaker_api_require
)
setup_kwargs: dict = dict(
name="gluonts",
version=version,
description=(
"GluonTS is a Python toolkit for probabilistic time series modeling, "
"built around MXNet."
),
long_description=read("README.md"),
long_description_content_type="text/markdown",
url="https://github.com/awslabs/gluon-ts",
author="Amazon",
author_email="[email protected]",
maintainer_email="[email protected]",
license="Apache License 2.0",
python_requires=">= 3.6",
package_dir={"": "src"},
packages=find_namespace_packages(include=["gluonts*"], where=str(SRC)),
include_package_data=True,
setup_requires=setup_requires,
install_requires=find_requirements("requirements.txt"),
tests_require=tests_require,
extras_require={
"dev": dev_require,
"docs": docs_require,
"R": find_requirements("requirements-extras-r.txt"),
"Prophet": find_requirements("requirements-extras-prophet.txt"),
"shell": shell_require,
},
entry_points=dict(
gluonts_forecasters=[
"deepar=gluonts.model.deepar:DeepAREstimator",
"DeepAR=gluonts.model.deepar:DeepAREstimator",
"DeepFactor=gluonts.model.deep_factor:DeepFactorEstimator",
"DeepState=gluonts.model.deepstate:DeepStateEstimator",
"DeepVAR=gluonts.model.deepvar:DeepVAREstimator",
"GaussianProcess=gluonts.model.gp_forecaster:GaussianProcessEstimator",
"GPVAR=gluonts.model.gpvar:GPVAREstimator",
"LSTNet=gluonts.model.lstnet:LSTNetEstimator",
"NBEATS=gluonts.model.n_beats:NBEATSEstimator",
"NBEATSEnsemble=gluonts.model.n_beats:NBEATSEnsembleEstimator",
"NPTS=gluonts.model.npts:NPTSPredictor",
"Rotbaum=gluonts.model.rotbaum:TreeEstimator",
"SelfAttention=gluonts.model.san:SelfAttentionEstimator",
"SeasonalNaive=gluonts.model.seasonal_naive:SeasonalNaivePredictor",
"MQCNN=gluonts.model.seq2seq:MQCNNEstimator",
"MQRNN=gluonts.model.seq2seq:MQRNNEstimator",
"Seq2Seq=gluonts.model.seq2seq:Seq2SeqEstimator",
"SimpleFeedForward=gluonts.model.simple_feedforward:SimpleFeedForwardEstimator",
"TFT=gluonts.model.tft:TemporalFusionTransformerEstimator",
"DeepTPP=gluonts.model.tpp:DeepTPPEstimator",
"Transformer=gluonts.model.transformer:TransformerEstimator",
"Constant=gluonts.model.trivial.constant:ConstantPredictor",
"ConstantValue=gluonts.model.trivial.constant:ConstantValuePredictor",
"Identity=gluonts.model.trivial.identity:IdentityPredictor",
"Mean=gluonts.model.trivial.mean:MeanEstimator",
"MeanPredictor=gluonts.model.trivial.mean:MeanPredictor",
"MovingAverage=gluonts.model.trivial.mean:MovingAveragePredictor",
"WaveNet=gluonts.model.wavenet:WaveNetEstimator",
# "r=gluonts.model.r_forecast:RForecastPredictor [R]",
# "prophet=gluonts.model.prophet:ProphetPredictor [Prophet]",
]
),
cmdclass={
"type_check": TypeCheckCommand,
"style_check": StyleCheckCommand,
**version_cmdclass,
},
)
if HAS_SPHINX:
class BuildApiDoc(setup_command.BuildDoc):
def run(self):
args = list(
itertools.chain(
["-f"], # force re-generation
["-P"], # include private modules
["--implicit-namespaces"], # respect PEP420
["-o", str(ROOT / "docs" / "api" / "gluonts")], # out path
[str(SRC / "gluonts")], # in path
["setup*", "test", "docs", "*pycache*"], # excluded paths
)
)
apidoc.main(args)
super(BuildApiDoc, self).run()
for command in ["build_sphinx", "doc", "docs"]:
setup_kwargs["cmdclass"][command] = BuildApiDoc
# -----------------------------------------------------------------------------
# start of AWS-internal section (DO NOT MODIFY THIS SECTION)!
#
# all AWS-internal configuration goes here
#
# end of AWS-internal section (DO NOT MODIFY THIS SECTION)!
# -----------------------------------------------------------------------------
# do the work
if __name__ == "__main__":
setup(**setup_kwargs)