From 3cfe600ff3f7856baedf3c5e73b552862088394a Mon Sep 17 00:00:00 2001 From: Titusz Pan Date: Sat, 19 Oct 2024 21:19:41 +0200 Subject: [PATCH] More debug output --- build.py | 41 +++++++++++++++++------------------------ iscc_core/__init__.py | 7 ++++--- pyproject.toml | 2 +- 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/build.py b/build.py index 772e0cb..766bc3c 100644 --- a/build.py +++ b/build.py @@ -10,17 +10,14 @@ def build(setup_kwargs): print(f"Contents of current directory: {os.listdir('.')}") print(f"Contents of iscc_core directory: {os.listdir('iscc_core')}") - try: - from Cython.Build import cythonize - - use_cython = True - print("Cython is available") - except ImportError: - use_cython = False - print("Cython is not available") + # Check if we're building with Cython + use_cython = "cython" in setup_kwargs.get("extras_require", {}).get("cython", []) if use_cython: try: + from Cython.Build import cythonize + + print("Cython is available and will be used") ext_modules = cythonize( [ Extension("iscc_core.cdc", ["iscc_core/cdc.py"]), @@ -37,22 +34,18 @@ def build(setup_kwargs): for ext in ext_modules: print(f"Extension: {ext.name}") - # Force the build process - setup(**setup_kwargs) - print("Build process completed") - - # Check if the compiled modules exist - for ext in ext_modules: - module_name = ext.name.split(".")[-1] - compiled_file = f"{module_name}.cp{sys.version_info.major}{sys.version_info.minor}-win_amd64.pyd" - if os.path.exists(os.path.join("iscc_core", compiled_file)): - print(f"Compiled module found: {compiled_file}") - else: - print(f"Compiled module not found: {compiled_file}") - except Exception as e: - print(f"Failed to prepare or build Cython modules: {e}") - print("Falling back to pure Python") + # Add Cython to build requirements + setup_kwargs.setdefault("build_requires", []).extend( + ["Cython>=3", "setuptools", "wheel"] + ) + except ImportError: + print("Cython is not available, falling back to pure Python") + use_cython = False else: - print("Cython not available, using pure Python") + print("Not building with Cython, using pure Python") + + if not use_cython: + # Remove any Cython-related build options + setup_kwargs.pop("ext_modules", None) print(f"Setup kwargs: {setup_kwargs}") diff --git a/iscc_core/__init__.py b/iscc_core/__init__.py index 06fe58b..50abf6b 100644 --- a/iscc_core/__init__.py +++ b/iscc_core/__init__.py @@ -1,4 +1,3 @@ -import sys import os __version__ = "1.1.0" @@ -11,10 +10,12 @@ def _using_cython_modules(): # pragma: no cover try: module_obj = __import__(f"iscc_core.{module}", fromlist=[module]) module_path = getattr(module_obj, "__file__", "") + module_type = type(module_obj) if module_path.endswith((".so", ".pyd")): cython_modules.append(module) - print(f"Module {module} path: {module_path}") - print(f"Module {module} type: {type(module_obj)}") + print(f"Module {module}:") + print(f" Path: {module_path}") + print(f" Type: {module_type}") except ImportError as e: print(f"Error importing {module}: {e}") print(f"Cython modules: {cython_modules}") diff --git a/pyproject.toml b/pyproject.toml index f61df86..10fcfc8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -99,5 +99,5 @@ generate-setup-file = true script = "build.py" [build-system] -requires = ["poetry-core>=1.0.0", "Cython>=3", "setuptools", "wheel"] +requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api"