|
1
|
|
|
#!/usr/bin/env python |
|
2
|
|
|
# ruff: noqa: E501 |
|
3
|
|
|
import os |
|
4
|
|
|
import re |
|
5
|
|
|
from pathlib import Path |
|
6
|
|
|
|
|
7
|
|
|
from setuptools import Extension, find_packages, setup |
|
8
|
|
|
from setuptools.command.build_ext import build_ext |
|
9
|
|
|
from setuptools.dist import Distribution |
|
10
|
|
|
|
|
11
|
|
|
try: |
|
12
|
|
|
# Allow installing package without any Cython available. This |
|
13
|
|
|
# assumes you are going to include the .c files in your sdist. |
|
14
|
|
|
import Cython |
|
15
|
|
|
except ImportError: |
|
16
|
|
|
Cython = None |
|
17
|
|
|
|
|
18
|
|
|
# Enable code coverage for C code: we cannot use CFLAGS=-coverage in tox.ini, since that may mess with compiling |
|
19
|
|
|
# dependencies (e.g. numpy). Therefore we set SETUPPY_CFLAGS=-coverage in tox.ini and copy it to CFLAGS here (after |
|
20
|
|
|
# deps have been safely installed). |
|
21
|
|
|
if "TOX_ENV_NAME" in os.environ and os.environ.get("SETUPPY_EXT_COVERAGE") == "yes": |
|
22
|
|
|
CFLAGS = os.environ["CFLAGS"] = "-DCYTHON_TRACE=1" |
|
23
|
|
|
LFLAGS = os.environ["LFLAGS"] = "" |
|
24
|
|
|
else: |
|
25
|
|
|
CFLAGS = "" |
|
26
|
|
|
LFLAGS = "" |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
class OptionalBuildExt(build_ext): |
|
30
|
|
|
""" |
|
31
|
|
|
Allow the building of C extensions to fail. |
|
32
|
|
|
""" |
|
33
|
|
|
|
|
34
|
|
|
def run(self): |
|
35
|
|
|
try: |
|
36
|
|
|
if os.environ.get("SETUPPY_FORCE_PURE"): |
|
37
|
|
|
raise Exception("C extensions disabled (SETUPPY_FORCE_PURE)!") |
|
38
|
|
|
super().run() |
|
39
|
|
|
except Exception as e: |
|
40
|
|
|
self._unavailable(e) |
|
41
|
|
|
self.extensions = [] # avoid copying missing files (it would fail). |
|
42
|
|
|
|
|
43
|
|
|
def _unavailable(self, e): |
|
44
|
|
|
print("*" * 80) |
|
45
|
|
|
print("""WARNING: |
|
46
|
|
|
|
|
47
|
|
|
An optional code optimization (C extension) could not be compiled. |
|
48
|
|
|
|
|
49
|
|
|
Optimizations for this package will not be available! |
|
50
|
|
|
""") |
|
51
|
|
|
|
|
52
|
|
|
print("CAUSE:") |
|
53
|
|
|
print("") |
|
54
|
|
|
print(" " + repr(e)) |
|
55
|
|
|
print("*" * 80) |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
class BinaryDistribution(Distribution): |
|
59
|
|
|
""" |
|
60
|
|
|
Distribution which almost always forces a binary package with platform name |
|
61
|
|
|
""" |
|
62
|
|
|
|
|
63
|
|
|
def has_ext_modules(self): |
|
64
|
|
|
return super().has_ext_modules() or not os.environ.get("SETUPPY_ALLOW_PURE") |
|
65
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
def read(*names, **kwargs): |
|
68
|
|
|
with ( |
|
69
|
|
|
Path(__file__) |
|
70
|
|
|
.parent.joinpath(*names) |
|
71
|
|
|
.open(encoding=kwargs.get("encoding", "utf8")) as fh |
|
72
|
|
|
): |
|
73
|
|
|
return fh.read() |
|
74
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
setup( |
|
77
|
|
|
name="precision-recall-gain", |
|
78
|
|
|
license="MIT", |
|
79
|
|
|
description="Precision-recall-gain curves for Python", |
|
80
|
|
|
version="0.1.3", |
|
81
|
|
|
long_description="{}\n{}".format( |
|
82
|
|
|
re.compile("^.. start-badges.*^.. end-badges", re.M | re.S).sub( |
|
83
|
|
|
"", read("README.rst") |
|
84
|
|
|
), |
|
85
|
|
|
re.sub(":[a-z]+:`~?(.*?)`", r"``\1``", read("CHANGELOG.rst")), |
|
86
|
|
|
), |
|
87
|
|
|
author="Richard Decal", |
|
88
|
|
|
author_email="[email protected]", |
|
89
|
|
|
url="https://github.com/crypdick/precision-recall-gain", |
|
90
|
|
|
packages=find_packages("src"), |
|
91
|
|
|
package_dir={"": "src"}, |
|
92
|
|
|
py_modules=[path.stem for path in Path("src").glob("*.py")], |
|
93
|
|
|
include_package_data=True, |
|
94
|
|
|
zip_safe=False, |
|
95
|
|
|
classifiers=[ |
|
96
|
|
|
# complete classifier list: http://pypi.python.org/pypi?%3Aaction=list_classifiers |
|
97
|
|
|
"Development Status :: 5 - Production/Stable", |
|
98
|
|
|
"Intended Audience :: Developers", |
|
99
|
|
|
"License :: OSI Approved :: BSD License", |
|
100
|
|
|
"Operating System :: Unix", |
|
101
|
|
|
"Operating System :: POSIX", |
|
102
|
|
|
"Operating System :: Microsoft :: Windows", |
|
103
|
|
|
"Programming Language :: Python", |
|
104
|
|
|
"Programming Language :: Python :: 3", |
|
105
|
|
|
"Programming Language :: Python :: 3 :: Only", |
|
106
|
|
|
"Programming Language :: Python :: 3.9", |
|
107
|
|
|
"Programming Language :: Python :: 3.10", |
|
108
|
|
|
"Programming Language :: Python :: 3.11", |
|
109
|
|
|
"Programming Language :: Python :: Implementation :: CPython", |
|
110
|
|
|
"Programming Language :: Python :: Implementation :: PyPy", |
|
111
|
|
|
"Topic :: Utilities", |
|
112
|
|
|
], |
|
113
|
|
|
project_urls={ |
|
114
|
|
|
"Documentation": "https://precision-recall-gain.readthedocs.io/", |
|
115
|
|
|
"Changelog": ( |
|
116
|
|
|
"https://precision-recall-gain.readthedocs.io/en/latest/changelog.html" |
|
117
|
|
|
), |
|
118
|
|
|
"Issue Tracker": "https://github.com/crypdick/precision-recall-gain/issues", |
|
119
|
|
|
}, |
|
120
|
|
|
keywords=[ |
|
121
|
|
|
# eg: "keyword1", "keyword2", "keyword3", |
|
122
|
|
|
], |
|
123
|
|
|
python_requires=">=3.9", |
|
124
|
|
|
install_requires=["scikit-learn>=1.1"], |
|
125
|
|
|
extras_require={ |
|
126
|
|
|
# eg: |
|
127
|
|
|
# "rst": ["docutils>=0.11"], |
|
128
|
|
|
# ":python_version=="2.6"": ["argparse"], |
|
129
|
|
|
}, |
|
130
|
|
|
setup_requires=( |
|
131
|
|
|
[ |
|
132
|
|
|
"setuptools_scm>=3.3.1", |
|
133
|
|
|
"cython", |
|
134
|
|
|
] |
|
135
|
|
|
if Cython |
|
136
|
|
|
else [ |
|
137
|
|
|
"setuptools_scm>=3.3.1", |
|
138
|
|
|
] |
|
139
|
|
|
), |
|
140
|
|
|
entry_points={}, |
|
141
|
|
|
cmdclass={"build_ext": OptionalBuildExt}, |
|
142
|
|
|
ext_modules=[ |
|
143
|
|
|
Extension( |
|
144
|
|
|
str(path.relative_to("src").with_suffix("")).replace(os.sep, "."), |
|
145
|
|
|
sources=[str(path)], |
|
146
|
|
|
extra_compile_args=CFLAGS.split(), |
|
147
|
|
|
extra_link_args=LFLAGS.split(), |
|
148
|
|
|
include_dirs=[str(path.parent)], |
|
149
|
|
|
) |
|
150
|
|
|
for path in Path("src").glob("**/*.pyx" if Cython else "**/*.c") |
|
151
|
|
|
], |
|
152
|
|
|
distclass=BinaryDistribution, |
|
153
|
|
|
) |
|
154
|
|
|
|