-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbuild.py
More file actions
72 lines (56 loc) · 2.07 KB
/
build.py
File metadata and controls
72 lines (56 loc) · 2.07 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
#!/usr/bin/env python3
"""This script builds the dfetch executable using Nuitka."""
import subprocess # nosec
import sys
import tomllib as toml
from typing import Union
from dfetch import __version__
def parse_option(
option_name: str, option_value: Union[bool, str, list, dict]
) -> list[str]:
"""
Convert a config value to Nuitka CLI arguments.
Handles booleans (--flag), strings (--flag=value), lists (multiple --flag=value),
and nested dicts (--flag=key1=val1=key2=val2).
Returns:
list[str]: Nuitka CLI arguments in the format ['--flag', '--key=value']
"""
args = []
cli_key = f"--{option_name.replace('_','-')}"
if isinstance(option_value, bool):
if option_value:
args.append(cli_key)
elif isinstance(option_value, str):
args.append(f"{cli_key}={option_value}".replace("{VERSION}", __version__))
elif isinstance(option_value, list):
for v in option_value:
if isinstance(v, dict):
parts = [f"{v[k]}" for k in v]
args.append(f"{cli_key}={'='.join(parts)}")
else:
args.append(f"{cli_key}={v}")
else:
args.append(f"{cli_key}={option_value}")
return args
# Load pyproject.toml
with open("pyproject.toml", "rb") as pyproject_file:
pyproject = toml.load(pyproject_file)
nuitka_opts = pyproject.get("tool", {}).get("nuitka", {})
if sys.platform.startswith("win"):
nuitka_opts["output-filename"] = nuitka_opts["output-filename-win"]
elif sys.platform.startswith("linux"):
nuitka_opts["output-filename"] = nuitka_opts["output-filename-linux"]
elif sys.platform.startswith("darwin"):
nuitka_opts["output-filename"] = nuitka_opts["output-filename-macos"]
nuitka_opts = {
k: v
for k, v in nuitka_opts.items()
if k
not in {"output-filename-win", "output-filename-linux", "output-filename-macos"}
}
command = [sys.executable, "-m", "nuitka"]
for key, value in nuitka_opts.items():
command.extend(parse_option(key, value))
command.append("dfetch")
print(command)
subprocess.check_call(command) # nosec