-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
56 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,32 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Build cython extension modules. | ||
import os | ||
from setuptools import Extension | ||
|
||
The shared library can also be built manually using the command: | ||
$ cythonize -X language_level=3 -a -i ./iscc_core/cdc.py | ||
$ cythonize -X language_level=3 -a -i ./iscc_core/minhash.py | ||
$ cythonize -X language_level=3 -a -i ./iscc_core/simhash.py | ||
$ cythonize -X language_level=3 -a -i ./iscc_core/dct.py | ||
$ cythonize -X language_level=3 -a -i ./iscc_core/wtahash.py | ||
""" | ||
try: | ||
from Cython.Build import cythonize, build_ext | ||
except ImportError: | ||
# dummy build function for poetry | ||
def build(setup_kwargs): | ||
pass | ||
|
||
else: | ||
def build(setup_kwargs): | ||
try: | ||
from Cython.Build import cythonize | ||
|
||
class build_ext_gracefull(build_ext): | ||
def run(self): | ||
try: | ||
print("Trying to compile C accelerator modules") | ||
super().run() | ||
print("Successfully comiled C accelerator modules") | ||
except Exception as e: | ||
print(e) | ||
print("********************************************************************") | ||
print("Failed to compile C accelerator module, falling back to pure python.") | ||
print("********************************************************************") | ||
use_cython = True | ||
except ImportError: | ||
use_cython = False | ||
|
||
def build_extensions(self): | ||
try: | ||
print("Trying to compile C accelerator modules") | ||
super().build_extensions() | ||
print("Successfully comiled C accelerator modules") | ||
except Exception as e: | ||
print(e) | ||
print("********************************************************************") | ||
print("Failed to compile C accelerator module, falling back to pure python.") | ||
print("********************************************************************") | ||
|
||
def build(setup_kwargs): | ||
if use_cython: | ||
try: | ||
setup_kwargs.update( | ||
dict( | ||
ext_modules=cythonize( | ||
[ | ||
"iscc_core/cdc.py", | ||
"iscc_core/minhash.py", | ||
"iscc_core/simhash.py", | ||
"iscc_core/dct.py", | ||
"iscc_core/wtahash.py", | ||
] | ||
), | ||
cmdclass=dict(build_ext=build_ext_gracefull), | ||
) | ||
ext_modules = cythonize( | ||
[ | ||
Extension("iscc_core.cdc", ["iscc_core/cdc.py"]), | ||
Extension("iscc_core.minhash", ["iscc_core/minhash.py"]), | ||
Extension("iscc_core.simhash", ["iscc_core/simhash.py"]), | ||
Extension("iscc_core.dct", ["iscc_core/dct.py"]), | ||
Extension("iscc_core.wtahash", ["iscc_core/wtahash.py"]), | ||
], | ||
compiler_directives={"language_level": "3"}, | ||
) | ||
setup_kwargs.update({"ext_modules": ext_modules}) | ||
print("Cython modules prepared for compilation") | ||
except Exception as e: | ||
print(e) | ||
print("********************************************************************") | ||
print("Failed to compile C accelerator module, falling back to pure python.") | ||
print("********************************************************************") | ||
print(f"Failed to prepare Cython modules: {e}") | ||
print("Falling back to pure Python") | ||
else: | ||
print("Cython not available, using pure Python") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters