-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·95 lines (72 loc) · 3.16 KB
/
main.py
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
91
92
93
94
# NuitkaBuilder
# Author: Nick Roussis
# Github: https://github.com/neek8044/NuitkaBuilder
# License: Apache 2.0
import subprocess
import time
import sys
import os
try:
from colorama import Fore, Style
except ImportError:
while True:
answer = input("--> Module 'colorama' not found. Run 'pip3 install colorama' now? [Y/n] : ").lower()
if answer == "n":
print("Aborted.")
sys.exit()
elif answer == 'y':
os.system("pip3 install --upgrade colorama")
print("Module installation complete. Please re-run.")
sys.exit()
else:
print("Invalid input. Answer with 'y' (yes) or 'n' (no).")
# Parsing options with argv
extras = []
wine = False
debug = False
if "--onefile" in sys.argv or "--single" in sys.argv or "-o" in sys.argv:
extras.append("--onefile")
if "--cwd-runtime" in sys.argv or "--runtime" in sys.argv or "-r" in sys.argv:
extras.append("--file-reference-choice=runtime")
if "--windows" in sys.argv or "--wine" in sys.argv or "-w" in sys.argv:
wine = True
if "--debug" in sys.argv or "-d" in sys.argv:
debug = True
extras = " ".join(extras)
cwd = os.getcwd()
os.system("") # for an unknown reason colors do not work without an 'os.system' command in specific terminals
# Starting info
print(
Fore.BLUE, Style.BRIGHT,
"\n[i] Check usage and report issues on Github: https://github.com/neek8044/NuitkaBuilder",
Style.NORMAL, Fore.YELLOW,
"\n\nNOTE: Linux requires 'patchelf' to be installed. You should install it with your package manager to use this program.\nYou may want to install 'ordered-set' with 'pip3 install ordered-set' for best compilation performance.",
Fore.BLUE,
"\n--> Building standalone for main.py",
Fore.RESET
)
# Executing nuitka for compilation
start = time.time()
full_command = str("wine " if wine else "") + f"python{'' if wine else '3'} -m nuitka --standalone {extras} --follow-imports --output-dir=\"{cwd}/output/\" main.py"
print(Fore.MAGENTA + "Executing: " + full_command + Fore.RESET) if debug else ...
nuitka = subprocess.Popen(
full_command,
cwd=cwd, shell=True,
stdout=subprocess.DEVNULL if debug == False else None,
stderr=subprocess.STDOUT
)
# Terminal animation
anim_chars = ["\\", "|", "/", "-"]
while nuitka.poll() is None:
for i in anim_chars:
print("--> Please wait, compiling... " + i, " "*10 if wine else "", end="\r")
time.sleep(0.1)
end = time.time()
timeout = 3
# Code cannot be compiled as quickly as the timeout set, thus it must have failed. (might improve in the future)
if end - start < timeout:
print(Fore.RED + "ERROR: Unknown issue with building main.py.\nTroubleshooting:\n\t-> Make sure to have a 'main.py' file in this local folder.\n\t-> Make sure to have Nuitka installed in your Python3 installation.\n\t-> If you are using the Wine compatibility layer (Linux only), check if Wine is installed and that you have Python 3 with Nuitka installed inside of your default Wine config." + Fore.RESET)
else:
print(Fore.GREEN + "\nFinished building main.py (stored in: ./output/main.dist/)" + Fore.RESET)
input("\nPress ENTER to exit...")
sys.exit()