forked from abhixdd/ghgrab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
90 lines (74 loc) · 2.65 KB
/
setup.py
File metadata and controls
90 lines (74 loc) · 2.65 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
from setuptools import setup, find_packages
from setuptools.command.build_py import build_py
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel
import os
import sys
import urllib.request
import platform
from pathlib import Path
VERSION = "1.0.1"
def get_platform_info():
system = platform.system().lower()
machine = platform.machine().lower()
if system == "windows":
return "win32", "ghgrab-win32.exe", "ghgrab.exe"
elif system == "darwin":
if machine in ("arm64", "aarch64"):
return "darwin-arm64", "ghgrab-darwin-arm64", "ghgrab"
return "darwin", "ghgrab-darwin", "ghgrab"
elif system == "linux":
if machine in ("arm64", "aarch64"):
return "linux-arm64", "ghgrab-linux-arm64", "ghgrab"
return "linux", "ghgrab-linux", "ghgrab"
return None, None, None
def download_binary():
platform_name, remote_name, local_name = get_platform_info()
if not platform_name:
return
bin_dir = Path(__file__).parent / "ghgrab"
bin_dir.mkdir(parents=True, exist_ok=True)
bin_path = bin_dir / local_name
if bin_path.exists() and bin_path.stat().st_size > 100_000:
print(f"Using existing binary at {bin_path}")
return
url = f"https://github.com/abhixdd/ghgrab/releases/download/v{VERSION}/{remote_name}"
print(f"Downloading ghgrab v{VERSION} binary for {platform_name} from {url}...")
try:
urllib.request.urlretrieve(url, bin_path)
size = bin_path.stat().st_size
if size < 100_000:
bin_path.unlink(missing_ok=True)
print(f"Downloaded file too small ({size} bytes). Skipping.")
return
if platform.system().lower() != "windows":
bin_path.chmod(0o755)
print(f"✓ Binary downloaded to {bin_path}")
except Exception as e:
print(f"Warning: Could not download binary: {e}")
class BuildPy(build_py):
def run(self):
download_binary()
super().run()
class bdist_wheel(_bdist_wheel):
def finalize_options(self):
super().finalize_options()
self.root_is_pure = False
def get_tag(self):
python, abi, plat = super().get_tag()
if plat.startswith("linux_x86_64"):
plat = "manylinux2014_x86_64"
elif plat.startswith("linux_aarch64"):
plat = "manylinux2014_aarch64"
return "py3", "none", plat
setup(
name="ghgrab",
version=VERSION,
packages=find_packages(),
package_data={"ghgrab": ["ghgrab", "ghgrab.exe"]},
include_package_data=True,
cmdclass={
"build_py": BuildPy,
"bdist_wheel": bdist_wheel,
},
zip_safe=False,
)