-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
64 lines (58 loc) · 1.83 KB
/
setup.py
File metadata and controls
64 lines (58 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from setuptools import setup, Extension
from setuptools.dist import Distribution
from Cython.Build import cythonize
import sys
# Define the extension module
extensions = [
Extension(
"src.security.hardware_id_cy", # Name of the extension
["src/security/hardware_id.pyx"], # Cython source file
# Include directories if needed
# include_dirs=[...],
# Extra compile args if needed
# extra_compile_args=[...],
)
]
# Setup configuration
setup(
name="BAR",
ext_modules=cythonize(
extensions,
compiler_directives={
"language_level": 3,
# Add annotations for better type checking
"annotation_typing": True,
# Optimize
"boundscheck": False,
"wraparound": False,
"initializedcheck": False,
},
),
# Ensure .pyx files are included in the package
package_data={
"src.security": ["*.pyx", "*.pxd"],
},
# Don't zip the package
zip_safe=False,
)
# Function to build the extension in place
def build_ext_inplace():
"""Build the extension modules in-place for development."""
from setuptools.command.build_ext import build_ext as _build_ext
# Create a custom build_ext command
class InplaceBuildExt(_build_ext):
def finalize_options(self):
_build_ext.finalize_options(self)
self.inplace = 1
# Run the build_ext command
cmd = InplaceBuildExt(Distribution({"ext_modules": extensions}))
cmd.ensure_finalized()
cmd.run()
# If this script is run directly, build the extension in-place
if __name__ == "__main__":
try:
build_ext_inplace()
print("Successfully built Cython extension in-place.")
except Exception as e:
print(f"Error building Cython extension: {e}")
sys.exit(1)