-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup.py
More file actions
104 lines (96 loc) · 3.16 KB
/
setup.py
File metadata and controls
104 lines (96 loc) · 3.16 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
import os
import shutil
import subprocess
import sysconfig
from contextlib import contextmanager
import setuptools
from Cython.Build import cythonize
from setuptools.extension import Extension
# Find correct value for SAGE_LIB which is needed to compile the Cython extensions.
try:
from sage.env import SAGE_LIB
except ModuleNotFoundError:
SAGE_LIB = os.getenv("SAGE_LIB") or sysconfig.get_path("purelib")
# Check if sage is installed in SAGE_LIB
if not os.path.isdir(SAGE_LIB + "/sage"):
raise ModuleNotFoundError("Sagemath or passagemath needs to be installed.")
INCLUDE_DIRS = []
LIBRARY_DIRS = []
if shutil.which("brew") is not None:
proc = subprocess.Popen(
"brew --prefix",
shell=True,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.STDOUT,
close_fds=True,
)
HOMEBREW_PREFIX = proc.stdout.readline().decode("utf-8").strip()
HOMEBREW_LIB = HOMEBREW_PREFIX + "/lib"
LIBRARY_DIRS.append(HOMEBREW_LIB)
HOMEBREW_INC = HOMEBREW_PREFIX + "/include"
INCLUDE_DIRS.append(HOMEBREW_INC)
# Extension modules using Cython
extra_compile_args = [
"-Wno-unused-function",
"-Wno-implicit-function-declaration",
"-Wno-unused-variable",
"-Wno-deprecated-declarations",
"-Wno-deprecated-register",
]
ext_modules = [
Extension(
"hilbert_modgroup.hilbert_modular_group_element",
sources=[os.path.join("src/hilbert_modgroup/hilbert_modular_group_element.pyx")],
extra_compile_args=extra_compile_args,
include_dirs=INCLUDE_DIRS,
library_dirs=LIBRARY_DIRS,
),
Extension(
"hilbert_modgroup.upper_half_plane",
sources=[os.path.join("src/hilbert_modgroup/upper_half_plane.pyx")],
extra_compile_args=extra_compile_args,
include_dirs=INCLUDE_DIRS,
library_dirs=LIBRARY_DIRS,
),
Extension(
"hilbert_modgroup.pullback_cython",
sources=[os.path.join("src/hilbert_modgroup/pullback_cython.pyx")],
language="c++",
extra_compile_args=extra_compile_args + ["-std=c++11"],
include_dirs=INCLUDE_DIRS,
library_dirs=LIBRARY_DIRS,
),
Extension(
"hilbert_modgroup.extended.group_element",
sources=["src/hilbert_modgroup/extended/group_element.pyx"],
extra_compile_args=extra_compile_args,
include_dirs=INCLUDE_DIRS,
library_dirs=LIBRARY_DIRS,
),
Extension(
"hilbert_modgroup.extended.pullback_cython",
sources=["src/hilbert_modgroup/extended/pullback_cython.pyx"],
language="c++",
extra_compile_args=extra_compile_args + ["-std=c++11"],
include_dirs=INCLUDE_DIRS,
library_dirs=LIBRARY_DIRS,
),
]
try:
from sage.misc.package_dir import cython_namespace_package_support
except ImportError:
@contextmanager
def cython_namespace_package_support():
yield
with cython_namespace_package_support():
setuptools.setup(
ext_modules=cythonize(
ext_modules,
include_path=["src", SAGE_LIB],
compiler_directives={
"embedsignature": True,
"language_level": "3",
},
),
)