-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
136 lines (114 loc) · 3.42 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
import ctypes
import ctypes.util
import os
import platform
import re
import sys
from contextlib import suppress
import subprocess
from setuptools import Extension, find_packages, setup
WINDOWS = platform.system() == "Windows"
def from_env(var):
ENVSEP = ";" if WINDOWS else ":"
with suppress(KeyError):
return list(filter(None, os.environ[var].split(ENVSEP)))
return ()
if not os.environ.get("FROM_MAKE_DIST", False):
subprocess.run(["make", "dist"])
SETUP_MODULE_NAME = "voucher"
SETUP_EXTENSION_LIBS = ["voucher_if"]
os.environ["C_INCLUDE_PATH"] = "local/include"
os.environ["LIBRARY_PATH"] = "local/lib"
os.environ["LD_LIBRARY_PATH"] = "local/lib"
os.environ["DYLD_LIBRARY_PATH"] = "local/lib"
def _get_version():
pattern = re.compile(r'^__version__ = ["]([.\w]+?)["]')
with open(
os.path.join(
"src", SETUP_MODULE_NAME, "__init__.py"
)
) as f:
for line in f:
match = pattern.match(line)
if match:
return match.group(1)
raise RuntimeError()
VERSION = _get_version()
if "--with-coverage" in sys.argv:
sys.argv.remove("--with-coverage")
COVERAGE = True
else:
COVERAGE = False
setup_requires = [
# Setuptools 18.0 properly handles Cython extensions.
"setuptools >= 18.0",
# Cython 0.28 handles const memoryviews.
"cython >= 0.28.0",
]
install_requires = [
"certifi",
'contextlib2; python_version < "3.0"',
'enum34 != 1.1.8; python_version < "3.0"',
'pathlib2; python_version < "3.0"',
]
tests_require = [
"readme_renderer",
'contextlib2; python_version < "3.0"',
]
def extensions(coverage=False):
libraries = (
[
"AdvAPI32", # `Crypt*` calls from `library/entropy_poll.c`
"mbedTLS",
]
if WINDOWS
else SETUP_EXTENSION_LIBS
)
library_dirs = from_env("LIBPATH" if WINDOWS else "LIBRARY_PATH")
for dirpath, _, filenames in os.walk("src"):
for fn in filenames:
root, ext = os.path.splitext(fn)
if ext != ".pyx":
continue
mod = ".".join(dirpath.split(os.sep)[1:] + [root])
extension = Extension(
mod,
sources=[os.path.join(dirpath, fn)],
library_dirs=library_dirs,
libraries=libraries,
define_macros=[
("CYTHON_TRACE", "1"),
("CYTHON_TRACE_NOGIL", "1"),
]
if coverage
else [],
)
extension.cython_directives = {"language_level": "3str"}
if coverage:
extension.cython_directives["linetrace"] = True
yield extension
def options(coverage=False):
if coverage:
return {}
return {
"build": {
"build_base": os.sep.join(
("build", "%i.%i.%i" % sys.version_info[:3])
)
},
"build_ext": {"cython_c_in_temp": True},
}
print('@@ COVERAGE:', COVERAGE)
print('@@ ext_modules:', list(extensions(COVERAGE)))
print('@@ packages:', find_packages("src"))
setup(
name=f"python-{SETUP_MODULE_NAME}",
version=VERSION,
ext_modules=list(extensions(COVERAGE)),
#options=options(COVERAGE),
package_dir={"": "src"},
packages=find_packages("src"),
setup_requires=setup_requires,
install_requires=install_requires,
tests_require=tests_require,
)