|
3 | 3 | import os |
4 | 4 | import sys |
5 | 5 | import subprocess |
6 | | -import shutil |
7 | 6 | from pathlib import Path |
8 | 7 | from setuptools import setup, find_packages |
9 | 8 | from setuptools.command.build_py import build_py |
@@ -36,61 +35,40 @@ def check_system_dependencies(): |
36 | 35 |
|
37 | 36 | def build_compiled_components(): |
38 | 37 | """Build the required C++ components using the build script.""" |
39 | | - |
| 38 | + |
40 | 39 | print("Building partis compiled components (ig-sw and ham)...") |
41 | | - |
| 40 | + |
42 | 41 | # Check system dependencies first |
43 | 42 | check_system_dependencies() |
44 | | - |
| 43 | + |
45 | 44 | base_dir = Path(__file__).parent.absolute() |
46 | 45 | build_script = base_dir / "bin" / "build.sh" |
47 | | - |
| 46 | + |
48 | 47 | if not build_script.exists(): |
49 | 48 | raise Exception(f"Build script not found at {build_script}") |
50 | | - |
| 49 | + |
51 | 50 | print("Compiling C++ components...") |
52 | 51 | result = subprocess.run([str(build_script)], cwd=str(base_dir)) |
53 | | - |
| 52 | + |
54 | 53 | if result.returncode != 0: |
55 | 54 | raise Exception(f"Build script failed with exit code {result.returncode}") |
56 | | - |
57 | | - print("✓ Successfully built ig-sw and ham binaries") |
58 | 55 |
|
59 | | - |
60 | | -class CustomBuildPy(build_py): |
61 | | - """Custom build command that compiles C++ components.""" |
62 | | - def run(self): |
63 | | - # First run the standard build |
64 | | - build_py.run(self) |
65 | | - # Then build our C++ components |
66 | | - build_compiled_components() |
67 | | - |
68 | | - |
69 | | -class CustomDevelop(develop): |
70 | | - """Custom develop command that compiles C++ components.""" |
71 | | - def run(self): |
72 | | - # Build C++ components first |
73 | | - build_compiled_components() |
74 | | - # Then run the standard develop |
75 | | - develop.run(self) |
| 56 | + print("✓ Successfully built ig-sw and ham binaries") |
76 | 57 |
|
77 | 58 |
|
78 | | -class CustomInstall(install): |
79 | | - """Custom install command that ensures C++ components are built.""" |
80 | | - def run(self): |
81 | | - # Build C++ components first |
82 | | - build_compiled_components() |
83 | | - # Then run the standard install |
84 | | - install.run(self) |
| 59 | +def make_custom_command(base_class): |
| 60 | + """Factory function to create custom command classes that build C++ components.""" |
| 61 | + class CustomCommand(base_class): |
| 62 | + def run(self): |
| 63 | + build_compiled_components() |
| 64 | + base_class.run(self) |
| 65 | + return CustomCommand |
85 | 66 |
|
86 | 67 |
|
87 | | -class CustomEggInfo(egg_info): |
88 | | - """Custom egg_info command that builds C++ components early.""" |
89 | | - def run(self): |
90 | | - # Build C++ components before creating egg info |
91 | | - build_compiled_components() |
92 | | - # Then run the standard egg_info |
93 | | - egg_info.run(self) |
| 68 | +CustomBuildPy = make_custom_command(build_py) |
| 69 | +CustomDevelop = make_custom_command(develop) |
| 70 | +CustomInstall = make_custom_command(install) |
| 71 | +CustomEggInfo = make_custom_command(egg_info) |
94 | 72 |
|
95 | 73 |
|
96 | 74 | class BinaryDistribution(Distribution): |
@@ -162,14 +140,12 @@ def has_ext_modules(self): |
162 | 140 | 'circlify', |
163 | 141 | 'ete3', |
164 | 142 | 'joypy', |
165 | | - 'matplotlib', |
166 | 143 | ], |
167 | 144 | 'full': [ |
168 | 145 | 'circlify', |
169 | 146 | 'ete3', |
170 | 147 | 'joypy', |
171 | 148 | 'levenshtein', |
172 | | - 'matplotlib', |
173 | 149 | ], |
174 | 150 | }, |
175 | 151 |
|
@@ -197,6 +173,8 @@ def has_ext_modules(self): |
197 | 173 | include_package_data=True, |
198 | 174 | package_data={ |
199 | 175 | 'partis': [ |
| 176 | + # Note: Using ../ to include files from outside the package directory |
| 177 | + # These are runtime dependencies that need to be bundled with the package |
200 | 178 | '../bin/*', |
201 | 179 | '../data/**/*', |
202 | 180 | '../test/**/*', |
|
0 commit comments