-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup.py
executable file
·119 lines (102 loc) · 3.44 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
#!/usr/bin/env python3
import os
import platform
import subprocess
import sysconfig
from pathlib import Path
import numpy
from Cython.Build import cythonize
from setuptools import Extension, setup
from setuptools.command.build_py import build_py
PROFILE = os.environ.get("PROFILE", False)
if PROFILE:
from Cython.Compiler.Options import get_directive_defaults
directive_defaults = get_directive_defaults()
directive_defaults["linetrace"] = True
directive_defaults["binding"] = True
# make the wheel platform specific
# https://stackoverflow.com/a/45150383
try:
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel
class bdist_wheel(_bdist_wheel):
def finalize_options(self):
_bdist_wheel.finalize_options(self)
self.root_is_pure = False
except ImportError:
bdist_wheel = None
class CustomBuildPy(build_py):
def run(self):
if platform.system() == "Windows":
script = Path(__file__).parent / "build.sh"
path = script.absolute().as_posix()
try:
subprocess.check_call(f"bash {path}", shell=True)
except subprocess.CalledProcessError as e:
print(f"Error running build script: {e}")
raise
# witness = Path(__file__).parent / "pydivsufsort/divsufsort.dll"
# assert witness.exists(), "Launch ./build.sh first"
elif platform.system() == "Darwin":
script = Path(__file__).parent / "build.sh"
path = script.absolute().as_posix()
mach = sysconfig.get_platform()
print("Building for", mach, platform.machine())
if mach.endswith("x86_64"):
arch = "x86_64"
elif mach.endswith("arm64"):
arch = "arm64"
else:
# support universal2
arch = platform.machine()
subprocess.check_call(
[path],
shell=False,
env={
**os.environ,
"PLATFORM_OPTION": "-DCMAKE_OSX_ARCHITECTURES=" + arch,
},
)
else:
script = Path(__file__).parent / "build.sh"
path = script.absolute().as_posix()
subprocess.check_call([path], shell=True, executable="/bin/bash")
super().run()
def read(fname):
return (Path(__file__).parent / fname).open().read()
extensions = [
Extension(
"pydivsufsort.stringalg",
["pydivsufsort/stringalg.pyx"],
include_dirs=[numpy.get_include()],
language="c++",
define_macros=[("CYTHON_TRACE", "1")] if PROFILE else None,
)
]
setup(
name="pydivsufsort",
version="0.0.18",
author="Louis Abraham",
license="MIT",
author_email="[email protected]",
description="String algorithms",
long_description=read("README.md"),
long_description_content_type="text/markdown",
url="https://github.com/louisabraham/pydivsufsort",
packages=["pydivsufsort"],
package_data={
"pydivsufsort": [
# unix
"libdivsufsort.*",
"libdivsufsort64.*",
# windows
"divsufsort.dll",
"divsufsort64.dll",
]
},
ext_modules=cythonize(extensions),
python_requires=">=3.9",
install_requires=["wheel", "numpy"],
tests_require=["pytest"],
classifiers=[],
cmdclass={"build_py": CustomBuildPy, "bdist_wheel": bdist_wheel},
)