Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sage
Path: blob/develop/src/setup.py
4013 views
1
#!/usr/bin/env python
2
3
## This version of setup.py is used by the Sage distribution
4
## only when configure --enable-editable has been used.
5
##
6
## Distribution packaging should use build/pkgs/sagelib/src/setup.py
7
## instead.
8
9
import os
10
import platform
11
import sys
12
import time
13
from setuptools import setup, find_namespace_packages
14
from setuptools.dist import Distribution
15
from distutils import log
16
import multiprocessing.pool
17
18
# PEP 517 builds do not have . in sys.path
19
sys.path.insert(0, os.path.dirname(__file__))
20
21
from sage.misc.package import is_package_installed_and_updated
22
from sage_setup.command.sage_build_ext_minimal import sage_build_ext_minimal
23
from sage_setup.command.sage_install import sage_develop, sage_install
24
from sage_setup.find import filter_cython_sources
25
from sage_setup.cython_options import compiler_directives, compile_time_env_variables
26
from sage_setup.extensions import create_extension
27
from sage_setup.excepthook import excepthook
28
29
# Work around a Cython problem in Python 3.8.x on macOS
30
# https://github.com/cython/cython/issues/3262
31
if platform.system() == 'Darwin':
32
import multiprocessing
33
multiprocessing.set_start_method('fork', force=True)
34
35
# setuptools plugins considered harmful:
36
# If build isolation is not in use and setuptools_scm is installed,
37
# then its file_finders entry point is invoked, which we don't need.
38
# And with setuptools_scm 8, we get more trouble:
39
# LookupError: pyproject.toml does not contain a tool.setuptools_scm section
40
# LookupError: setuptools-scm was unable to detect version ...
41
# We just remove all handling of "setuptools.finalize_distribution_options" entry points.
42
Distribution._removed = staticmethod(lambda ep: True)
43
44
# ########################################################
45
# ## Set source directory
46
# ########################################################
47
48
import sage.env
49
sage.env.SAGE_SRC = os.getcwd()
50
from sage.env import *
51
52
sys.excepthook = excepthook
53
54
from sage_setup.setenv import setenv
55
setenv()
56
57
# ########################################################
58
# ## Configuration
59
# ########################################################
60
61
if len(sys.argv) > 1 and (sys.argv[1] in ["sdist", "egg_info", "dist_info"]):
62
sdist = True
63
else:
64
sdist = False
65
66
# ########################################################
67
# ## Discovering Sources
68
# ########################################################
69
if sdist:
70
extensions = []
71
python_packages = []
72
else:
73
log.info("Generating auto-generated sources")
74
from sage_setup.autogen import autogen_all
75
autogen_all()
76
77
log.info("Discovering Python/Cython source code...")
78
79
optional_packages = ['mcqd', 'bliss', 'tdlib',
80
'coxeter3', 'sirocco', 'meataxe']
81
distributions_to_exclude = [f"sagemath-{pkg}"
82
for pkg in optional_packages]
83
files_to_exclude = filter_cython_sources(SAGE_SRC, distributions_to_exclude)
84
85
log.debug(f"files_to_exclude = {files_to_exclude}")
86
87
python_packages = find_namespace_packages(where=SAGE_SRC, include=['sage', 'sage.*'])
88
log.debug(f"python_packages = {python_packages}")
89
90
log.info("Discovering Python/Cython source code... done")
91
92
# from sage_build_cython:
93
import Cython.Compiler.Options
94
Cython.Compiler.Options.embed_pos_in_docstring = True
95
gdb_debug = os.environ.get('SAGE_DEBUG', None) != 'no'
96
97
aliases = cython_aliases()
98
log.debug(f"aliases = {aliases}")
99
include_path = sage_include_directories(use_sources=True) + ['.']
100
log.debug(f"include_path = {include_path}")
101
nthreads = sage_build_ext_minimal.get_default_number_build_jobs()
102
log.info(f"Cythonizing with {nthreads} threads...")
103
try:
104
from Cython.Build import cythonize
105
from sage.env import cython_aliases, sage_include_directories
106
from sage.misc.package_dir import cython_namespace_package_support
107
with cython_namespace_package_support():
108
extensions = cythonize(
109
["sage/**/*.pyx"],
110
exclude=files_to_exclude,
111
include_path=include_path,
112
compile_time_env=compile_time_env_variables(),
113
compiler_directives=compiler_directives(False),
114
aliases=aliases,
115
create_extension=create_extension,
116
gdb_debug=gdb_debug,
117
nthreads=nthreads)
118
except Exception as exception:
119
log.warn(f"Exception while cythonizing source files: {repr(exception)}")
120
raise
121
log.info(f"Cythonizing with {nthreads} threads... done")
122
123
# ########################################################
124
# ## Distutils
125
# ########################################################
126
code = setup(
127
packages=python_packages,
128
cmdclass={
129
"build_ext": sage_build_ext_minimal,
130
"develop": sage_develop,
131
"install": sage_install,
132
},
133
ext_modules=extensions
134
)
135
136