@@ -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