-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
71 lines (56 loc) · 1.93 KB
/
build.py
File metadata and controls
71 lines (56 loc) · 1.93 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
import os
import tempfile
import subprocess
from src.gitmit import __VERSION__
from src.gitmit.utils.terminal import display_info, display_success, display_warning
def main():
version = __VERSION__
dist_dir = os.path.join(tempfile.gettempdir(), "gitmit")
if not os.path.exists(dist_dir):
os.makedirs(dist_dir)
display_info(f"Directory '{dist_dir}' created.")
output_file = os.path.join(dist_dir, f"gitmit-{version}.pex")
requirements_file = os.path.join(dist_dir, "requirements.txt")
# Export dependencies using uv
display_info("Exporting dependencies...")
export_result = subprocess.run(
["uv", "export", "--no-hashes", "--no-dev", "--no-emit-project"],
capture_output=True,
text=True,
)
if export_result.returncode != 0:
raise RuntimeError(f"Failed to export dependencies: {export_result.stderr}")
# Filter out the "Resolved X packages" line from stderr
requirements = export_result.stdout
with open(requirements_file, "w") as f:
f.write(requirements)
# Build PEX using uvx
display_info("Building PEX executable...")
cmd = [
"uvx",
"pex",
"-r",
requirements_file,
"-o",
output_file,
"-e",
"gitmit:main",
"--python-shebang",
"/usr/bin/env python3",
"--no-transitive",
"--sources-dir=src",
]
result = subprocess.run(cmd)
if result.returncode != 0:
raise RuntimeError("Failed to build PEX executable")
# Cleanup temporary requirements file
os.remove(requirements_file)
display_success(f"Build completed successfully: {output_file}")
display_warning(
f"a) Move file: [bold purple]mv {output_file} /usr/local/bin/gitmit[/bold purple]"
)
display_warning(
f"b) Make file executable: [bold purple]chmod +x /usr/local/bin/gitmit[/bold purple]"
)
if __name__ == "__main__":
main()