Skip to content

Commit 99c437a

Browse files
committed
stop bundling cython-generated C files in sdist
It's better to require regeneration of the C modules at build time for releases since newer cython versions often change the underlying C code that is generated to support new CPython versions and other API changes.
1 parent 3033edc commit 99c437a

2 files changed

Lines changed: 25 additions & 35 deletions

File tree

MANIFEST.in

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

setup.py

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import subprocess
33
from multiprocessing import cpu_count
44

5+
from Cython.Build import cythonize
56
from setuptools import setup
67
from setuptools.command import build_ext as dst_build_ext
78
from setuptools.extension import Extension
@@ -13,11 +14,6 @@
1314
MIN_VERSION = "0.0.5"
1415
MAX_VERSION = "0.0.5"
1516

16-
# running against git repo
17-
GIT = os.path.exists(os.path.join(os.path.dirname(__file__), ".git"))
18-
19-
compiler_directives = {"language_level": 3}
20-
2117

2218
def pkg_config(*packages, **kw):
2319
"""Translate pkg-config data to compatible Extension parameters.
@@ -73,18 +69,11 @@ def extensions(**build_opts):
7369
exts = []
7470

7571
for ext in cython_pyx(MODULEDIR):
76-
cythonized = os.path.splitext(ext)[0] + ".c"
77-
# use pre-generated modules for releases
78-
if not GIT and os.path.exists(cythonized):
79-
ext_path = cythonized
80-
else:
81-
ext_path = ext
82-
8372
# strip package dir
84-
module = ext_path.rpartition(PACKAGEDIR)[-1].lstrip(os.path.sep)
73+
module = ext.rpartition(PACKAGEDIR)[-1].lstrip(os.path.sep)
8574
# strip file extension and translate to module namespace
8675
module = os.path.splitext(module)[0].replace(os.path.sep, ".")
87-
exts.append(Extension(name=module, sources=[ext_path], **build_opts))
76+
exts.append(Extension(name=module, sources=[ext], **build_opts))
8877

8978
return exts
9079

@@ -103,30 +92,31 @@ def initialize_options(self):
10392
def finalize_options(self):
10493
self.cython_coverage = bool(self.cython_coverage)
10594

106-
if GIT:
107-
ext_modules = self.distribution.ext_modules[:]
108-
109-
# optionally enable coverage support for cython modules
110-
if self.cython_coverage:
111-
compiler_directives["linetrace"] = True
112-
trace_macros = [("CYTHON_TRACE", "1"), ("CYTHON_TRACE_NOGIL", "1")]
113-
for ext in ext_modules:
114-
ext.define_macros.extend(trace_macros)
115-
116-
from Cython.Build import cythonize
117-
118-
self.distribution.ext_modules[:] = cythonize(
119-
ext_modules,
120-
compiler_directives=compiler_directives,
121-
annotate=False,
122-
)
123-
124-
super().finalize_options()
95+
ext_modules = self.distribution.ext_modules[:]
96+
# default cython compiler directives
97+
compiler_directives = {"language_level": 3}
98+
99+
# optionally enable coverage support for cython modules
100+
if self.cython_coverage:
101+
compiler_directives["linetrace"] = True
102+
trace_macros = [("CYTHON_TRACE", "1"), ("CYTHON_TRACE_NOGIL", "1")]
103+
for ext in ext_modules:
104+
ext.define_macros.extend(trace_macros)
105+
106+
# generate C modules
107+
self.distribution.ext_modules[:] = cythonize(
108+
ext_modules,
109+
force=True,
110+
compiler_directives=compiler_directives,
111+
annotate=False,
112+
)
125113

126114
# default to parallelizing build across all cores
127115
if self.parallel is None:
128116
self.parallel = cpu_count()
129117

118+
super().finalize_options()
119+
130120
def run(self):
131121
# delay pkg-config to avoid requiring library during sdist
132122
pkgcraft_opts = pkg_config("pkgcraft")

0 commit comments

Comments
 (0)