Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup.py
More file actions
Latest commit
216 lines (180 loc) · 7.08 KB
/
Copy pathsetup.py
File metadata and controls
216 lines (180 loc) · 7.08 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
#!/usr/bin/env python
"""
A setuptools based setup module generated from the xBrite Sample Package.
See:
* https://github.com/xBrite/sample-python-package
* https://packaging.python.org/en/latest/distributing.html
* https://github.com/pypa/sampleproject
"""
importos
importre
# To use a consistent encoding
fromcodecsimportopen
# Always prefer setuptools over distutils
fromsetuptoolsimportsetup, find_packages, Extension
# This is needed to build cython extensions.
fromsetuptools.command.build_extimportbuild_ext
# Package configuration should all be defined here for easy access.
# Update these values as best fits your particular package.
name="sample_package"
description="xBrite Sample Package."
author="xBrite contributors"
author_email="xbrite@example.com"
url="https://github.com/xBrite/sample-python-package"
license="MIT License"
keywords="xBrite"
classifiers= [
# CHANGEME: Update the classifiers as appropriate
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Topic :: Software Development :: Build Tools",
"License :: {}".format(license),
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
]
setup_requires= (
# CHANGEME: This module contains special handling for bootstrapping a
# project for cython and numpy. However, since these are
# specialty packages (especially during setup), we leave them
# commented out. Uncomment them here and in the tox section of
# pyproject.toml if wish to use them.
# "cython",
# "numpy",
)
install_requires=setup_requires+ (
# CHANGEME: Put your package"s requirements here. A requirements.txt file
# is not recommended.
# "sample_package",
# "other_sample_package",
)
tests_require=install_requires+ (
"pytest",
"pytest-runner",
"tox",
"mypy", # linting
"flake8", # linting
"flake8-annotations",
"flake8-bugbear",
"flake8-builtins",
"flake8-logging-format",
"flake8-pep3101",
"flake8-tidy-imports",
)
dev_require=tests_require+ (
"pip-tools", # for managing packages and building requirements.txt
"black", # autoformatting
"ptvsd", # vscode python debugging
"isort", # for auto-sorting imports
"autoflake", # for auto-remove unused imports
)
dependency_links= (
# CHANGEME: Install any private dependency links here.
)
entry_points= {
# CHANGEME: Set up any appropriate entry points here, e.g. console_scripts
# "console_scripts": [
# "sample_script = sample_package.example_script:main",
# ],
}
# Setting this to true will make sure any binaries in MANIFEST.in
# get included with the package when it is distributed.
# See: http://setuptools.readthedocs.io/en/latest/setuptools.html#including-data-files
include_package_data=True
################################################
# Please try not to touch things below this line
################################################
HERE=os.path.abspath(os.path.dirname(__file__))
MODULE_PATH=os.path.join(HERE, name.replace("-", "_"))
# Get the long description from the README file
withopen(os.path.join(HERE, "README.md"), encoding="utf-8") asf:
long_description=f.read()
# Load the version by reading the package directly, so we don"t run into
# dependency loops by importing it into setup.py
version=None
withopen(os.path.join(MODULE_PATH, "__init__.py")) asinit_file:
forlineininit_file:
m=re.search(r"\b(?:__version__|VERSION)\b\s*(?::\s*\w+\s*)=\s*(.+?)$", line)
ifm:
version=eval(m.group(1))
break
assertversionisnotNone, "Couldn't find version string."
classBuildExtWithNumpyWorkaround(build_ext):
"""
We need `numpy.get_include()` in order to build cython+numpy packages on some
environments (I"m looking at you, MacOS), but we don"t want setup.py to depend
on it and cause ImportErrors that would prevent things like pip from determining
the what packages setup actually requires.
This also includes a check so that it doesn"t even try to include import numpy
unless cython ext_modules are actually detected, and `numpy` is included in
the `setup_requires` list.
See: https://stackoverflow.com/questions/19919905/how-to-bootstrap-numpy-installation-in-setup-py
"""
NEED_NUMPY_INCLUDE=False
deffinalize_options(self):
build_ext.finalize_options(self) # old-style class can"t call super() properly
ifself.NEED_NUMPY_INCLUDE:
# Prevent numpy from thinking it"s still in its own setup process:
__builtins__.__NUMPY_SETUP__=False
importnumpy
self.include_dirs.append(numpy.get_include())
defmake_ext_modules():
"""
Walk the module tree looking for cython files and return a list of Extensions() from them.
See: http://cython.readthedocs.io/en/latest/src/userguide/source_files_and_compilation.html
"""
extensions= []
if"cython"insetup_requires:
cur_dir=os.getcwd()
(parent_dir, module_dir) =os.path.split(MODULE_PATH)
try:
ifparent_dir:
os.chdir(parent_dir)
forinfoinos.walk(module_dir):
dir_path=info[0]
# subdirs = info[1]
pyx_files= [fforfininfo[2] iff.endswith(".pyx")]
pxd_files= [fforfininfo[2] iff.endswith(".pxd")]
forpyxinpyx_files:
sources= [os.path.join(dir_path, pyx)]
module=pyx[:-4]
pxd=module+".pxd"
ifpxdinpxd_files:
sources.append(os.path.join(dir_path, pxd))
ifsources:
ext_name=".".join(dir_path.split(os.sep) + [module])
extensions.append(Extension(ext_name, sources=sources))
finally:
os.chdir(cur_dir)
ifextensionsand"numpy"insetup_requires:
BuildExtWithNumpyWorkaround.NEED_NUMPY_INCLUDE=True
returnextensions
setup(
name=name,
version=version,
description=description,
long_description=long_description,
author=author,
author_email=author_email,
url=url,
license=license,
classifiers=classifiers,
keywords=keywords,
cmdclass={"build_ext": BuildExtWithNumpyWorkaround},
setup_requires=setup_requires,
# Specify the specific modules (if any) that cython should compile
ext_modules=make_ext_modules(),
# This package only installs its base module, and a bunch of dependencies
packages=find_packages(exclude=["bin", "contrib", "docs", "tests"]),
include_package_data=include_package_data,
install_requires=install_requires,
dependency_links=dependency_links,
entry_points=entry_points,
# In order to keep tox *and* setup happy, we need to define the test requirements twice...
extras_require={
"test": tests_require,
"dev": dev_require,
},
tests_require=tests_require,
test_suite="py.test",
)