@@ -10,17 +10,14 @@ def build(setup_kwargs):
10
10
print (f"Contents of current directory: { os .listdir ('.' )} " )
11
11
print (f"Contents of iscc_core directory: { os .listdir ('iscc_core' )} " )
12
12
13
- try :
14
- from Cython .Build import cythonize
15
-
16
- use_cython = True
17
- print ("Cython is available" )
18
- except ImportError :
19
- use_cython = False
20
- print ("Cython is not available" )
13
+ # Check if we're building with Cython
14
+ use_cython = "cython" in setup_kwargs .get ("extras_require" , {}).get ("cython" , [])
21
15
22
16
if use_cython :
23
17
try :
18
+ from Cython .Build import cythonize
19
+
20
+ print ("Cython is available and will be used" )
24
21
ext_modules = cythonize (
25
22
[
26
23
Extension ("iscc_core.cdc" , ["iscc_core/cdc.py" ]),
@@ -37,22 +34,18 @@ def build(setup_kwargs):
37
34
for ext in ext_modules :
38
35
print (f"Extension: { ext .name } " )
39
36
40
- # Force the build process
41
- setup (** setup_kwargs )
42
- print ("Build process completed" )
43
-
44
- # Check if the compiled modules exist
45
- for ext in ext_modules :
46
- module_name = ext .name .split ("." )[- 1 ]
47
- compiled_file = f"{ module_name } .cp{ sys .version_info .major } { sys .version_info .minor } -win_amd64.pyd"
48
- if os .path .exists (os .path .join ("iscc_core" , compiled_file )):
49
- print (f"Compiled module found: { compiled_file } " )
50
- else :
51
- print (f"Compiled module not found: { compiled_file } " )
52
- except Exception as e :
53
- print (f"Failed to prepare or build Cython modules: { e } " )
54
- print ("Falling back to pure Python" )
37
+ # Add Cython to build requirements
38
+ setup_kwargs .setdefault ("build_requires" , []).extend (
39
+ ["Cython>=3" , "setuptools" , "wheel" ]
40
+ )
41
+ except ImportError :
42
+ print ("Cython is not available, falling back to pure Python" )
43
+ use_cython = False
55
44
else :
56
- print ("Cython not available, using pure Python" )
45
+ print ("Not building with Cython, using pure Python" )
46
+
47
+ if not use_cython :
48
+ # Remove any Cython-related build options
49
+ setup_kwargs .pop ("ext_modules" , None )
57
50
58
51
print (f"Setup kwargs: { setup_kwargs } " )
0 commit comments