forked from alkaline-ml/pmdarima
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
371 lines (321 loc) · 14.3 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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
# -*- coding: utf-8 -*-
#
# Author: Taylor Smith <[email protected]>
#
# Setup the pmdarima module. This is heavily adapted from the scikit-learn
# setup.py, since they have a similar package structure and build similar
# Cython + C modules.
import sys
import os
import platform
import shutil
from distutils.command.clean import clean as Clean
from packaging.version import Version
from setuptools import find_packages
import traceback
import importlib
import builtins
# Minimum allowed version
MIN_PYTHON = (3, 7)
IS_PYTHON_312 = sys.version_info[0] == 3 and sys.version_info[1] >= 12
# Hacky (!!), adopted from sklearn. This sets a global variable
# so pmdarima __init__ can detect if it's being loaded in the setup
# routine, so it won't load submodules that haven't yet been built.
# This is because of the numpy distutils extensions that are used by pmdarima
# to build the compiled extensions in sub-packages
builtins.__PMDARIMA_SETUP__ = True
# metadata
DISTNAME = 'pmdarima'
PYPIDIST = 'pmdarima'
GIT_REPO_NAME = 'pmdarima'
DESCRIPTION = "Python's forecast::auto.arima equivalent"
# Get the long desc
with open("README.md", "r") as fh:
LONG_DESCRIPTION = fh.read()
MAINTAINER = 'Taylor G. Smith'
MAINTAINER_GIT = 'tgsmith61591'
MAINTAINER_EMAIL = '[email protected]'
LICENSE = 'MIT'
URL = 'http://alkaline-ml.com/pmdarima'
DOWNLOAD_URL = 'https://pypi.org/project/pmdarima/#files'
PROJECT_URLS = {
'Bug Tracker': 'https://github.com/alkaline-ml/pmdarima/issues',
'Documentation': URL,
'Source Code': 'https://github.com/alkaline-ml/pmdarima'
}
# import restricted version of pmdarima that does not need the compiled code
import pmdarima
VERSION = pmdarima.__version__ # will be 0.0.0 unless tagging
# get the installation requirements:
with open('requirements.txt') as req:
REQUIREMENTS = [l for l in req.read().split(os.linesep) if l]
print(f"Requirements: {REQUIREMENTS}")
# Optional setuptools features
SETUPTOOLS_COMMANDS = { # this is a set literal, not a dict
'develop', 'release', 'bdist_egg', 'bdist_rpm',
'bdist_wininst', 'install_egg_info', 'build_sphinx',
'egg_info', 'easy_install', 'upload', 'bdist_wheel',
'--single-version-externally-managed',
# scikit does NOT do this:
'sdist,'
}
if SETUPTOOLS_COMMANDS.intersection(sys.argv):
# we don't use setuptools, but if we don't import it, the "develop"
# option for setup.py is invalid.
import setuptools # noqa
print('Adding extra setuptools args')
extra_setuptools_args = dict(
zip_safe=False, # the package can run out of an .egg file
include_package_data=True,
data_files=[
('pmdarima', ['pmdarima/VERSION']),
],
# scikit does this:
# extras_require={
# 'alldeps': REQUIREMENTS
# }
)
else:
extra_setuptools_args = dict()
# Custom clean command to remove build artifacts -- adopted from sklearn
class CleanCommand(Clean):
description = "Remove build artifacts from the source tree"
# this is mostly in case we ever add a Cython module to SMRT
def run(self):
Clean.run(self)
# Remove c files if we are not within a sdist package
cwd = os.path.abspath(os.path.dirname(__file__))
remove_c_files = not os.path.exists(os.path.join(cwd, 'PKG-INFO'))
if remove_c_files:
print('Will remove generated .c files')
if os.path.exists('build'):
shutil.rmtree('build')
for dirpath, dirnames, filenames in os.walk(DISTNAME):
for filename in filenames:
if any(filename.endswith(suffix) for suffix in
(".so", ".pyd", ".dll", ".pyc")):
print(f'Removing file: {filename}')
os.unlink(os.path.join(dirpath, filename))
continue
extension = os.path.splitext(filename)[1]
if remove_c_files and extension in ['.c', '.cpp']:
pyx_file = str.replace(filename, extension, '.pyx')
if os.path.exists(os.path.join(dirpath, pyx_file)):
os.unlink(os.path.join(dirpath, filename))
for dirname in dirnames:
if dirname == '__pycache__':
absdir = os.path.join(dirpath, dirname)
print(f'Removing directory: {absdir}')
shutil.rmtree(absdir)
cmdclass = {'clean': CleanCommand}
# build_ext has to be imported after setuptools
try:
import numpy as np
from numpy.distutils.command.build_ext import build_ext # noqa
# This is the preferred way to check numpy version: https://git.io/JtEIb
if sys.platform == 'darwin' and np.lib.NumpyVersion(np.__version__) >= '1.20.0':
# https://numpy.org/devdocs/user/building.html#disabling-atlas-and-other-accelerated-libraries
os.environ['NPY_BLAS_ORDER'] = ''
os.environ['NPY_LAPACK_ORDER'] = ''
class build_ext_subclass(build_ext):
def build_extensions(self):
build_ext.build_extensions(self)
cmdclass['build_ext'] = build_ext_subclass
except ImportError:
# Numpy should not be a dependency just to be able to introspect
# that python 3.X is required.
pass
# Here is where scikit configures the wheelhouse uploader, but we don't deal
# with that currently. Maybe in the future...
def configuration(parent_package='', top_path=None):
if os.path.exists('MANIFEST'):
os.remove('MANIFEST')
# we know numpy is a valid import now
from numpy.distutils.misc_util import Configuration
from pmdarima._build_utils import _check_cython_version
config = Configuration(None, parent_package, top_path)
# Avoid non-useful msg
# "Ignoring attempt to set 'name' (from ... "
config.set_options(ignore_setup_xxx_py=True,
assume_default_configuration=True,
delegate_options_to_subpackages=True,
quiet=True)
# Cython is required by config.add_subpackage, so check that we have the
# correct version of Cython
_check_cython_version()
config.add_subpackage(DISTNAME)
return config
def check_package_status(package, min_version):
"""
Returns a dictionary containing a boolean specifying whether given package
is up-to-date, along with the version string (empty string if
not installed).
"""
package_status = {}
try:
module = importlib.import_module(package)
package_version = module.__version__
package_status['up_to_date'] = Version(
package_version) >= Version(min_version)
package_status['version'] = package_version
except ImportError:
traceback.print_exc()
package_status['up_to_date'] = False
package_status['version'] = ""
req_str = "pmdarima requires {} >= {}.\n".format(
package, min_version)
if package_status['up_to_date'] is False:
if package_status['version']:
raise ImportError("Your installation of {} "
"{} is out-of-date.\n{}"
.format(package, package_status['version'],
req_str))
else:
raise ImportError("{} is not "
"installed.\n{}"
.format(package, req_str))
def do_setup():
# setup the config
metadata = dict(name=PYPIDIST,
# packages=[DISTNAME],
maintainer=MAINTAINER,
maintainer_email=MAINTAINER_EMAIL,
description=DESCRIPTION,
license=LICENSE,
url=URL,
download_url=DOWNLOAD_URL,
project_urls=PROJECT_URLS,
version=VERSION,
long_description=LONG_DESCRIPTION,
long_description_content_type="text/markdown",
classifiers=[
'Intended Audience :: Science/Research',
'Intended Audience :: Developers',
'Intended Audience :: Financial and Insurance Industry',
'Programming Language :: C',
'Programming Language :: Python',
'Topic :: Software Development',
'Topic :: Scientific/Engineering',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'Operating System :: Unix',
'Operating System :: MacOS',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
('Programming Language :: Python :: '
'Implementation :: CPython'),
],
cmdclass=cmdclass,
python_requires=f'>={MIN_PYTHON[0]}.{MIN_PYTHON[1]}',
install_requires=REQUIREMENTS,
# Adapted from: https://github.com/inmanta/inmanta/pull/83
# See also: https://github.com/pypa/setuptools/issues/3197
packages=find_packages(),
# We have a MANIFEST.in, so I'm not convinced this is fully
# necessary, but better to be safe since we've had sdist
# problems in the past...
package_data=dict(
DISTNAME=[
'*',
'pmdarima/*',
'pmdarima/VERSION',
'pmdarima/__check_build/*',
'pmdarima/_build_utils/*',
'pmdarima/arima/*',
'pmdarima/arima/tests/data/*',
'pmdarima/compat/*',
'pmdarima/datasets/*',
'pmdarima/datasets/data/*',
'pmdarima/model_selection/*',
'pmdarima/preprocessing/*',
'pmdarima/preprocessing/endog/*',
'pmdarima/preprocessing/exog/*',
'pmdarima/tests/*',
'pmdarima/utils/*',
]
),
keywords='arima timeseries forecasting pyramid pmdarima '
'pyramid-arima scikit-learn statsmodels',
**extra_setuptools_args)
if len(sys.argv) == 1 or (
len(sys.argv) >= 2 and ('--help' in sys.argv[1:] or
sys.argv[1] in ('--help-commands',
'egg_info',
'dist_info',
'--version',
'clean'))):
# For these actions, NumPy is not required, so we can import the
# setuptools module. However this is not preferable... the moment
# setuptools is imported, it monkey-patches distutils' setup and
# changes its behavior...
# (https://github.com/scikit-learn/scikit-learn/issues/1016)
#
# This is called when installing from pip and numpy might not
# be on the system yet
try:
from setuptools import setup
print("Setting up with setuptools")
except ImportError:
print("Setting up with distutils")
from distutils.core import setup
metadata['version'] = VERSION
else:
if sys.version_info < MIN_PYTHON:
raise RuntimeError(
# Don't make this an F-string so that the error can be rendered
# on older versions of python
"pmdarima requires Python {0}.{1} or later. The current "
"Python version is {2} installed in {3}.".format(
MIN_PYTHON[0], MIN_PYTHON[1],
platform.python_version(),
sys.executable
)
)
# for sdist, use setuptools so we get the long_description_content_type
if 'sdist' in sys.argv or IS_PYTHON_312:
from setuptools import setup
print("Setting up with setuptools")
# TODO: distutils is removed in Python 3.12+, so this should probably be the default
if IS_PYTHON_312:
from setuptools import Extension
import numpy
include_dirs = [numpy.get_include()]
metadata['ext_modules'] = [
Extension(
name='pmdarima.arima._arima',
sources=['pmdarima/arima/_arima.pyx'],
include_dirs=include_dirs
),
Extension(
name='pmdarima.preprocessing.exog._fourier',
sources=['pmdarima/preprocessing/exog/_fourier.pyx'],
include_dirs=include_dirs
),
Extension(
name='pmdarima.utils._array',
sources=['pmdarima/utils/_array.pyx'],
include_dirs=include_dirs
),
Extension(
name='pmdarima.__check_build._check_build',
sources=['pmdarima/__check_build/_check_build.pyx'],
include_dirs=include_dirs
)
]
else:
# we should only need numpy for building. Everything else can be
# collected via install_requires above
check_package_status('numpy', '1.16')
from numpy.distutils.core import setup
print("Setting up with numpy.distutils.core")
# add the config to the metadata
metadata['configuration'] = configuration
# call setup on the dict
setup(**metadata)
if __name__ == '__main__':
do_setup()