forked from cobyqa/cobyqa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
202 lines (172 loc) · 6.82 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
#!/usr/bin/env python3
import importlib
import os
import shutil
import sys
from pkg_resources import parse_version
if sys.version_info < (3, 7):
raise RuntimeError('Python version >= 3.7 required.')
import builtins
from pathlib import Path
# Remove MANIFEST before importing setuptools to prevent improper updates.
if os.path.exists('MANIFEST'):
os.remove('MANIFEST')
import setuptools # noqa
from distutils.command.clean import clean # noqa
from distutils.command.sdist import sdist # noqa
# This is a bit hackish: to prevent loading components that are not yet built,
# we set the following global variable to endow the main __init__ with the
# ability to detect whether it is loaded by the setup routine.
builtins.__COBYQA_SETUP__ = True
import cobyqa # noqa
import cobyqa.utils._min_dependencies as min_deps # noqa
SETUPTOOLS_COMMANDS = {
'bdist_dumb',
'bdist_egg',
'bdist_rpm',
'bdist_msi',
'bdist_wheel',
'bdist_wininst',
'develop',
'easy_install',
'egg_info',
'install',
'install_egg_info',
'upload',
}
if SETUPTOOLS_COMMANDS.intersection(sys.argv[1:]):
extra_setuptools_args = dict(
zip_safe=False,
include_package_data=True,
extras_require={k: min_deps.tag_to_pkgs[k] for k in ['docs', 'tests']},
)
else:
extra_setuptools_args = {}
class CleanCommand(clean):
description = 'Remove build artifacts from the source tree'
def run(self):
super().run()
# Remove setuptools artifact directories and files.
cwd = Path(__file__).resolve(strict=True).parent
shutil.rmtree(cwd / 'build', ignore_errors=True)
shutil.rmtree(cwd / 'dist', ignore_errors=True)
for dirname in cwd.glob('*.egg-info'):
shutil.rmtree(dirname)
# Remove test cache directories.
shutil.rmtree(cwd / '.pytest_cache', ignore_errors=True)
shutil.rmtree(cwd / '.tox', ignore_errors=True)
# Remove the 'MANIFEST' file.
if Path(cwd, 'MANIFEST').is_file():
os.unlink(cwd / 'MANIFEST')
# Remove C/C++ files generated outside of a source distribution.
rm_c_files = not Path(cwd, 'PKG-INFO').is_file()
for dirpath, dirnames, filenames in os.walk(cwd / 'cobyqa'):
dirpath = Path(dirpath).resolve(strict=True)
for dirname in dirnames:
if dirname == '__pycache__':
shutil.rmtree(dirpath / dirname)
for filename in filenames:
basename, extension = os.path.splitext(filename)
if extension in ('.dll', '.pyc', '.pyd', '.so'):
os.unlink(dirpath / filename)
if rm_c_files and extension in ('.c', '.cpp'):
pyx_file = basename + '.pyx'
if Path(dirpath, pyx_file).is_file():
os.unlink(dirpath / filename)
cmdclass = {'clean': CleanCommand, 'sdist': sdist}
def configuration(parent_package='', top_path=None):
from numpy.distutils.misc_util import Configuration
from cobyqa._build_utils import _check_cython_version # noqa
config = Configuration(None, parent_package, top_path)
config.set_options(
ignore_setup_xxx_py=True,
assume_default_configuration=True,
delegate_options_to_subpackages=True,
quiet=True,
)
_check_cython_version()
config.add_subpackage('cobyqa')
return config
def check_pkg_status(pkg, min_version):
message = '{} version >= {} required.'.format(pkg, min_version)
try:
module = importlib.import_module(pkg)
pkg_version = module.__version__ # noqa
if parse_version(pkg_version) < parse_version(min_version):
message += ' The current version is {}.'.format(pkg_version)
raise ValueError(message)
except ModuleNotFoundError:
raise ModuleNotFoundError(message)
def setup_package():
metadata = dict(
name='cobyqa',
author='Tom M. Ragonneau, Zaikun Zhang',
author_email='[email protected]',
maintainer='Tom M. Ragonneau',
maintainer_email='[email protected]',
packages=setuptools.find_packages(),
version=cobyqa.__version__,
description='Constrained Optimization BY Quadratic Approximation',
long_description=open('README.rst').read().rstrip(),
long_description_content_type='text/x-rst',
keywords='',
license='BSD-3-Clause',
url='https://cobyqa.readthedocs.io',
download_url='https://pypi.org/project/cobyqa/#files',
project_urls={
'Bug Tracker': 'https://github.com/ragonneau/cobyqa/issues',
'Documentation': 'https://cobyqa.readthedocs.io',
'Source Code': 'https://github.com/ragonneau/cobyqa',
},
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'Intended Audience :: Education',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: BSD License',
'Operating System :: MacOS',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'Operating System :: POSIX :: Linux',
'Operating System :: Unix',
'Programming Language :: Cython',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Topic :: Scientific/Engineering',
'Topic :: Scientific/Engineering :: Mathematics',
'Topic :: Software Development',
'Topic :: Software Development :: Libraries',
'Topic :: Software Development :: Libraries :: Python Modules',
],
platforms=['Linux', 'macOS', 'Unix', 'Windows'],
cmdclass=cmdclass,
python_requires='>=3.7',
install_requires=min_deps.tag_to_pkgs['install'],
package_data={'': ['*.pxd']},
**extra_setuptools_args
)
distutils_commands = {
'check',
'clean',
'egg_info',
'dist_info',
'install_egg_info',
'rotate',
}
commands = [arg for arg in sys.argv[1:] if not arg.startswith('-')]
if all(command in distutils_commands for command in commands):
from setuptools import setup
else:
check_pkg_status('numpy', min_deps.NUMPY_MIN_VERSION)
check_pkg_status('scipy', min_deps.SCIPY_MIN_VERSION)
from numpy.distutils.core import setup
metadata['configuration'] = configuration
setup(**metadata)
if __name__ == '__main__':
setup_package()
del builtins.__COBYQA_SETUP__ # noqa