|
| 1 | +import os |
| 2 | +import sys |
| 3 | +import platform |
1 | 4 | from setuptools import setup, find_packages |
| 5 | +from wheel.bdist_wheel import bdist_wheel as _bdist_wheel |
2 | 6 |
|
3 | 7 | with open("README.md", "r") as fh: |
4 | 8 | long_description = fh.read() |
5 | 9 |
|
| 10 | +# Map Python's platform names to our binary folder names |
| 11 | +PLATFORM_MAPPING = { |
| 12 | + 'linux': 'linux', |
| 13 | + 'darwin': 'darwin', |
| 14 | + 'win32': 'windows', |
| 15 | + 'freebsd': 'freebsd', |
| 16 | + 'openbsd': 'openbsd', |
| 17 | +} |
| 18 | + |
| 19 | +ARCH_MAPPING = { |
| 20 | + 'x86_64': 'x86_64', |
| 21 | + 'AMD64': 'x86_64', |
| 22 | + 'amd64': 'x86_64', |
| 23 | + 'aarch64': 'arm64', |
| 24 | + 'arm64': 'arm64', |
| 25 | +} |
| 26 | + |
| 27 | +def get_platform_info(): |
| 28 | + """Determine the platform and architecture from environment or system.""" |
| 29 | + target_platform, target_architecture = os.environ.get('LEFTHOOK_TARGET_PLATFORM'), os.environ.get('LEFTHOOK_TARGET_ARCH') |
| 30 | + |
| 31 | + if target_platform and target_architecture: |
| 32 | + return target_platform, target_architecture |
| 33 | + |
| 34 | + system, machine = platform.system().lower(), platform.machine().lower() |
| 35 | + return PLATFORM_MAPPING.get(sys.platform, system), ARCH_MAPPING.get(machine, machine) |
| 36 | + |
| 37 | +class CustomBdistWheel(_bdist_wheel): |
| 38 | + """Custom bdist_wheel that generates platform-specific wheels.""" |
| 39 | + |
| 40 | + def finalize_options(self): |
| 41 | + """Initialize platform-specific options.""" |
| 42 | + super().finalize_options() |
| 43 | + platform, architecture = get_platform_info() |
| 44 | + self.plat_name = f"{platform}_{architecture}" |
| 45 | + |
| 46 | + def get_tag(self): |
| 47 | + """Override to return platform-specific tag.""" |
| 48 | + platform, architecture = get_platform_info() |
| 49 | + return ('py3', 'none', f'{platform}_{architecture}') |
| 50 | + |
| 51 | +def get_package_data(): |
| 52 | + """Get only the binary for the current/target platform.""" |
| 53 | + platform, architecture = get_platform_info() |
| 54 | + binary_name = 'lefthook' |
| 55 | + if platform == 'windows': |
| 56 | + binary_name = 'lefthook.exe' |
| 57 | + return { |
| 58 | + 'lefthook': [f'bin/lefthook-{platform}-{architecture}/{binary_name}'] |
| 59 | + } |
| 60 | + |
6 | 61 | setup( |
7 | 62 | name='lefthook', |
8 | 63 | version='2.0.2', |
|
18 | 73 | 'lefthook=lefthook.main:main' |
19 | 74 | ], |
20 | 75 | }, |
21 | | - package_data={ |
22 | | - 'lefthook':[ |
23 | | - 'bin/lefthook-linux-x86_64/lefthook', |
24 | | - 'bin/lefthook-linux-arm64/lefthook', |
25 | | - 'bin/lefthook-freebsd-x86_64/lefthook', |
26 | | - 'bin/lefthook-freebsd-arm64/lefthook', |
27 | | - 'bin/lefthook-openbsd-x86_64/lefthook', |
28 | | - 'bin/lefthook-openbsd-arm64/lefthook', |
29 | | - 'bin/lefthook-windows-x86_64/lefthook.exe', |
30 | | - 'bin/lefthook-windows-arm64/lefthook.exe', |
31 | | - 'bin/lefthook-darwin-x86_64/lefthook', |
32 | | - 'bin/lefthook-darwin-arm64/lefthook', |
33 | | - ] |
| 76 | + package_data=get_package_data(), |
| 77 | + license_files=['LICENSE'], |
| 78 | + cmdclass={ |
| 79 | + 'bdist_wheel': CustomBdistWheel, |
34 | 80 | }, |
35 | 81 | classifiers=[ |
36 | | - 'License :: OSI Approved :: MIT License', |
37 | 82 | 'Operating System :: OS Independent', |
38 | 83 | 'Topic :: Software Development :: Version Control :: Git' |
39 | 84 | ], |
|
0 commit comments