-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_with_tests.py.example
More file actions
119 lines (107 loc) · 3.94 KB
/
setup_with_tests.py.example
File metadata and controls
119 lines (107 loc) · 3.94 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
"""
Example of how to run tests during installation (optional, not recommended for most use cases)
"""
from setuptools import setup, find_packages, Extension, Command
from setuptools.command.build_ext import build_ext
import numpy
import sys
import subprocess
import os
class TestCommand(Command):
"""Custom command to run tests during installation"""
description = 'run tests after installation'
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
"""Run the test suite"""
# Install test dependencies first
subprocess.check_call([
sys.executable, '-m', 'pip', 'install', 'pytest', 'pytest-cov'
])
# Run tests
test_dir = os.path.join(os.path.dirname(__file__), 'tests')
if os.path.exists(test_dir):
exit_code = subprocess.call([sys.executable, '-m', 'pytest', test_dir, '-v'])
if exit_code != 0:
print("⚠️ Some tests failed, but installation will continue")
else:
print("No tests directory found, skipping tests")
class CustomBuildExt(build_ext):
"""Custom build_ext command that provides user feedback"""
def build_extensions(self):
print("\n" + "="*60)
print("Building combinatorial_codes C extensions...")
print("="*60)
try:
super().build_extensions()
print("\n✓ SUCCESS: C extensions compiled successfully!")
print(" Performance-optimized functions are now available.")
print(" Expected speedup: 5-10x for computationally intensive operations.")
except Exception as e:
print(f"\n⚠ WARNING: C extension compilation failed: {e}")
print(" The package will still work using Python/Numba implementations.")
print(" Performance will be slower but functionality remains intact.")
print("\n To enable C extensions, ensure you have:")
print(" - A C compiler (gcc, clang, or MSVC)")
print(" - Python development headers")
print(" - NumPy development headers")
# Don't re-raise the exception - allow installation to continue
print("="*60 + "\n")
# Define the C extension with error handling
def get_ext_modules():
try:
translated_functions_ext = Extension(
'combinatorial_codes.translated_functions',
sources=['src/combinatorial_codes/translated_functions.c'],
include_dirs=[numpy.get_include()],
extra_compile_args=['-O3', '-ffast-math'], # Optimization flags
extra_link_args=[],
)
return [translated_functions_ext]
except Exception as e:
print(f"Warning: Could not set up C extension: {e}")
print("The package will still work using Python/Numba implementations.")
return []
setup(
name="combinatorial_codes",
version="0.2",
description="A Python package for manipulating combinatorial codes",
long_description="",
author="Vladimir Itskov",
author_email="vladimir.itskov@psu.edu",
url="https://github.com/nebneuron/combinatorial_codes",
packages=find_packages(where="src"),
package_dir={"": "src"},
ext_modules=get_ext_modules(),
cmdclass={
'build_ext': CustomBuildExt,
'test': TestCommand, # Add custom test command
},
python_requires=">=3.11",
install_requires=[
"numba>=0.57.0",
"numpy",
"gudhi>=3.11.0",
"networkx>=3.0",
],
extras_require={
"test": [
"pytest>=6.0",
"pytest-cov",
],
"dev": [
"pytest>=6.0",
"pytest-cov",
"black",
"flake8",
],
},
classifiers=[
"Programming Language :: Python :: 3.11",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
)