Skip to content
This repository was archived by the owner on Feb 1, 2023. It is now read-only.

Commit 1aef376

Browse files
committed
Extract cython options to new module
1 parent 1da6df4 commit 1aef376

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

src/sage_setup/command/sage_build_cython.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from sage_setup.util import stable_uniq
1818
from sage_setup.find import find_extra_files
1919
from sage_setup.library_order import library_order
20+
from sage_setup.cython_options import compiler_directives, compile_time_env_variables
2021

2122
from sage.env import (cython_aliases, sage_include_directories)
2223

@@ -149,23 +150,8 @@ def finalize_options(self):
149150
"Cython must be installed and importable in order to run "
150151
"the cythonize command")
151152

152-
# Cython compiler directives
153-
self.cython_directives = dict(
154-
auto_pickle=False,
155-
autotestdict=False,
156-
cdivision=True,
157-
embedsignature=True,
158-
fast_getattr=True,
159-
language_level="3str",
160-
preliminary_late_includes_cy28=True,
161-
profile=self.profile,
162-
)
163-
self.compile_time_env = dict(
164-
PY_PLATFORM=sys.platform,
165-
# The following two constants are here only for backwards compatibility of user packages
166-
PY_VERSION_HEX=sys.hexversion,
167-
PY_MAJOR_VERSION=sys.version_info[0]
168-
)
153+
self.cython_directives = compiler_directives(self.profile)
154+
self.compile_time_env = compile_time_env_variables()
169155

170156
# We check the Cython version and some relevant configuration
171157
# options from the earlier build to see if we need to force a

src/sage_setup/cython_options.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import sys
2+
3+
def compiler_directives(profile: bool):
4+
"""
5+
Returns a list of Cython directives used for compilation.
6+
"""
7+
return dict(
8+
# Do not create __test__ dictionary automatically from docstrings
9+
autotestdict=False,
10+
# Do not check for division by 0 (this is about 35% quicker than with check)
11+
cdivision=True,
12+
# Embed a textual copy of the call signature in the docstring (to support tools like IPython)
13+
embedsignature=True,
14+
fast_getattr=True,
15+
# Use Python 3 (including source code semantics) for module compilation
16+
language_level="3str",
17+
# Enable support for late includes (make declarations in Cython code available to C include files)
18+
preliminary_late_includes_cy28=True,
19+
# Add hooks for Python profilers into the compiled C code
20+
profile=profile,
21+
)
22+
23+
def compile_time_env_variables():
24+
"""
25+
Returns a list of environmental variables used for compilation.
26+
"""
27+
return dict(
28+
PY_PLATFORM=sys.platform,
29+
# The following two constants are here only for backwards compatibility of user packages
30+
PY_VERSION_HEX=sys.hexversion,
31+
PY_MAJOR_VERSION=sys.version_info[0]
32+
)

0 commit comments

Comments
 (0)