22import subprocess
33from multiprocessing import cpu_count
44
5+ from Cython .Build import cythonize
56from setuptools import setup
67from setuptools .command import build_ext as dst_build_ext
78from setuptools .extension import Extension
1314MIN_VERSION = "0.0.5"
1415MAX_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
2218def 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