Skip to content

Commit

Permalink
setup.py: avoid generating cython modules during sdist build
Browse files Browse the repository at this point in the history
Since the build process now always generates new C modules instead of
using bundled versions, skip creating them during the sdist process.
  • Loading branch information
radhermit committed Feb 5, 2023
1 parent 5649799 commit 9d2a941
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
2 changes: 0 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# all vcs-tracked files are auto-included by setuptools_scm
# include bundled test data
recursive-include testdata *
# exclude cython-generated files
recursive-exclude src/pkgcraft *.c
# drop git-related files
global-exclude .git*
prune .github
27 changes: 16 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,32 +92,37 @@ def initialize_options(self):
def finalize_options(self):
self.cython_coverage = bool(self.cython_coverage)

ext_modules = self.distribution.ext_modules[:]
# default to parallelizing build across all cores
if self.parallel is None:
self.parallel = cpu_count()

super().finalize_options()

def run(self):
# default cython compiler directives
compiler_directives = {"language_level": 3}

# optionally enable coverage support for cython modules
if self.cython_coverage:
compiler_directives["linetrace"] = True
trace_macros = [("CYTHON_TRACE", "1"), ("CYTHON_TRACE_NOGIL", "1")]
for ext in ext_modules:
for ext in self.extensions:
ext.define_macros.extend(trace_macros)

# generate C modules
self.distribution.ext_modules[:] = cythonize(
ext_modules,
# generate C modules with cython
self.extensions[:] = cythonize(
self.extensions,
force=True,
compiler_directives=compiler_directives,
annotate=False,
)

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

super().finalize_options()

def run(self):
# delay pkg-config to avoid requiring library during sdist
pkgcraft_opts = pkg_config("pkgcraft")

Expand Down

0 comments on commit 9d2a941

Please sign in to comment.