Skip to content

Commit 9d2a941

Browse files
committed
setup.py: avoid generating cython modules during sdist build
Since the build process now always generates new C modules instead of using bundled versions, skip creating them during the sdist process.
1 parent 5649799 commit 9d2a941

2 files changed

Lines changed: 16 additions & 13 deletions

File tree

MANIFEST.in

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# all vcs-tracked files are auto-included by setuptools_scm
22
# include bundled test data
33
recursive-include testdata *
4-
# exclude cython-generated files
5-
recursive-exclude src/pkgcraft *.c
64
# drop git-related files
75
global-exclude .git*
86
prune .github

setup.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,32 +92,37 @@ def initialize_options(self):
9292
def finalize_options(self):
9393
self.cython_coverage = bool(self.cython_coverage)
9494

95-
ext_modules = self.distribution.ext_modules[:]
95+
# default to parallelizing build across all cores
96+
if self.parallel is None:
97+
self.parallel = cpu_count()
98+
99+
super().finalize_options()
100+
101+
def run(self):
96102
# default cython compiler directives
97103
compiler_directives = {"language_level": 3}
98104

99105
# optionally enable coverage support for cython modules
100106
if self.cython_coverage:
101107
compiler_directives["linetrace"] = True
102108
trace_macros = [("CYTHON_TRACE", "1"), ("CYTHON_TRACE_NOGIL", "1")]
103-
for ext in ext_modules:
109+
for ext in self.extensions:
104110
ext.define_macros.extend(trace_macros)
105111

106-
# generate C modules
107-
self.distribution.ext_modules[:] = cythonize(
108-
ext_modules,
112+
# generate C modules with cython
113+
self.extensions[:] = cythonize(
114+
self.extensions,
109115
force=True,
110116
compiler_directives=compiler_directives,
111117
annotate=False,
112118
)
113119

114-
# default to parallelizing build across all cores
115-
if self.parallel is None:
116-
self.parallel = cpu_count()
120+
# HACK: Force setuptools to reinject its private attributes to
121+
# extension objects that were overridden by `cythonize`, otherwise the
122+
# build fails when it tries to access them.
123+
build_ext = self.reinitialize_command("build_ext")
124+
build_ext.ensure_finalized()
117125

118-
super().finalize_options()
119-
120-
def run(self):
121126
# delay pkg-config to avoid requiring library during sdist
122127
pkgcraft_opts = pkg_config("pkgcraft")
123128

0 commit comments

Comments
 (0)