-
Notifications
You must be signed in to change notification settings - Fork 36
/
setup.py
226 lines (190 loc) · 7.47 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
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Setup file for ``bezier``."""
import os
import sys
try:
import numpy as np
except ImportError:
np = None
import setuptools
import setuptools.dist
VERSION = "2024.6.21.dev1" # Also in ``codemeta.json`` and ``__init__.py``.
AUTHOR = "Danny Hermes" # Also in ``__init__.py``.
README_FILENAME = os.path.join(os.path.dirname(__file__), "README.rst")
NUMPY_MESSAGE = """\
Error: NumPy needs to be installed first. It can be installed via:
$ python -m pip install numpy
$ python3.12 -m pip install numpy
$ # OR
$ conda install numpy
"""
NO_EXTENSION_ENV = "BEZIER_NO_EXTENSION"
NO_SPEEDUPS_MESSAGE = """\
The `{}` environment variable has been used to explicitly disable the
building of the binary extension module.
""".format(
NO_EXTENSION_ENV
)
IGNORE_VERSION_CHECK_ENV = "BEZIER_IGNORE_VERSION_CHECK"
INVALID_VERSION_MESSAGE = """\
The current Python version ({major}.{minor}) is not supported.
The supported versions are: {versions}
Using `bezier` on an unsupported version of Python is not known to work. You
may be seeing this message as part of a source distribution (`sdist`) install
because no wheels exist on PyPI for your current Python environment. The
Python environment is uniquely identified by Python version, operating
system (ABI) and architecture (platform). You are likely seeing this message
because a new version of Python has been released. To disable this check, set
the `BEZIER_IGNORE_VERSION_CHECK` environment variable.
"""
INSTALL_PREFIX_ENV = "BEZIER_INSTALL_PREFIX"
NO_INSTALL_PREFIX_MESSAGE = """\
The `{install_prefix}` environment variable must be set when installing
`bezier` from source with the binary extension module. If you are not
intending to install from source, check on PyPI to see if a prebuilt wheel
exists for your current Python environment. If no wheel exists, installing
from source is the only option (even via `pip`, which will use the `sdist`
source distribution).
For a pure Python install (i.e. without the binary extension module), set
the `{no_extension}` environment variable.
For a source install using the binary extension module, see installation
instructions for the C ABI (`libbezier`).
""".format(
install_prefix=INSTALL_PREFIX_ENV, no_extension=NO_EXTENSION_ENV
)
REQUIREMENTS = ("numpy >= 2.0.0",)
# See: https://www.python.org/dev/peps/pep-0508/
# Dependency specification for Python Software Packages
EXTRAS_REQUIRE = {
"full": ["matplotlib >= 3.9.0", "scipy >= 1.13.1", "sympy >= 1.12.1"],
}
DESCRIPTION = (
"Helper for B\u00e9zier Curves, Triangles, and Higher Order Objects"
)
_IS_WINDOWS = os.name == "nt"
_IS_PYPY = sys.implementation.name == "pypy"
def numpy_include_dir():
if np is None:
print(NUMPY_MESSAGE, file=sys.stderr, end="")
sys.exit(1)
return np.get_include()
def extension_modules():
if NO_EXTENSION_ENV in os.environ:
print(NO_SPEEDUPS_MESSAGE, file=sys.stderr, end="")
return []
install_prefix = os.environ.get(INSTALL_PREFIX_ENV)
if install_prefix is None:
print(NO_INSTALL_PREFIX_MESSAGE, file=sys.stderr, end="")
sys.exit(1)
rpath = os.path.join(install_prefix, "lib")
if not os.path.isdir(rpath):
rpath = os.path.join(install_prefix, "lib64")
extra_link_args = []
if not _IS_WINDOWS:
extra_link_args.append("-Wl,-rpath,{}".format(rpath))
extension = setuptools.Extension(
name="bezier._speedup",
sources=[os.path.join("src", "python", "bezier", "_speedup.c")],
include_dirs=[
numpy_include_dir(),
os.path.join(install_prefix, "include"),
],
libraries=["bezier"],
library_dirs=[rpath],
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],
extra_compile_args=[],
extra_link_args=extra_link_args,
)
return [extension]
def make_readme():
with open(README_FILENAME, "r") as file_obj:
return file_obj.read()
def setup():
setuptools.setup(
name="bezier",
version=VERSION,
description=DESCRIPTION,
author=AUTHOR,
author_email="daniel.j.hermes@gmail.com",
long_description=make_readme(),
scripts=(),
url="https://github.com/dhermes/bezier",
project_urls={
"Documentation": "https://bezier.readthedocs.io/",
"Changelog": (
"https://bezier.readthedocs.io/en/latest/releases/index.html"
),
"Issue Tracker": "https://github.com/dhermes/bezier/issues",
},
keywords=["Geometry", "Curve", "Bezier", "Intersection", "Python"],
packages=["bezier", "bezier.hazmat"],
package_dir={"": os.path.join("src", "python")},
license="Apache 2.0",
platforms="Posix; macOS; Windows",
package_data={"bezier": ["*.pxd"]},
zip_safe=True,
install_requires=REQUIREMENTS,
extras_require=EXTRAS_REQUIRE,
ext_modules=extension_modules(),
python_requires=">=3.10",
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering :: Mathematics",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
],
)
def _check_python_version():
"""Check that this is being installed in a valid version of Python.
If the current version of Python is unsupported, this will exit with an
error.
The ``BEZIER_IGNORE_VERSION_CHECK`` environment variable can be set to
opt out of this check.
"""
if IGNORE_VERSION_CHECK_ENV in os.environ:
return
major = sys.version_info.major
minor = sys.version_info.minor
if (major, minor) in ((3, 10), (3, 11), (3, 12)):
return
message = INVALID_VERSION_MESSAGE.format(
major=major, minor=minor, versions="3.10, 3.11 and 3.12"
)
print(message, file=sys.stderr, end="")
sys.exit(1)
def _patch_setuptools():
"""Patch ``setuptools`` to address known issues.
Known issues:
* In some PyPy installs, the ``setuptools.build_py.build_package_data()``
method depends on the ``convert_2to3_doctests`` being set on an instance
of ``setuptools.dist.Distribution``, but it is unset. We handle this
by setting it as a **class attribute** (vs. monkey-patching ``__init__``
to set it on instances).
"""
if not _IS_PYPY:
return
setuptools.dist.Distribution.convert_2to3_doctests = []
def main():
_check_python_version()
_patch_setuptools()
setup()
if __name__ == "__main__":
main()