Skip to content

Commit e07fec8

Browse files
committed
1.1.3
Bug Fix in 1.1.5
1 parent 08fe33a commit e07fec8

File tree

3 files changed

+35
-25
lines changed

3 files changed

+35
-25
lines changed

dist/main.exe

6.43 MB
Binary file not shown.

lang/zh-cn.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
{
22
"time": "%Y-%m-%d %H:%M:%S",
3+
"nuitka_output": "Nuitka 输出",
34
"1": "成功加载配置文件:%s",
45
"2": "配置文件不存在:%s",
56
"3": "配置文件解析错误: %s - %s",
6-
"4": "加载配置文件时发生意外错误: %s"
7+
"4": "加载配置文件时发生意外错误: %s",
8+
"5": "配置信息已保存到:%s",
9+
"6": "保存配置文件失败:%s",
10+
"7": "自动设置并行编译工作数:%d",
11+
"8": "请输入版本号(格式:X.X.X.X)",
12+
"9": "自动添加并行编译参数: --jobs=%d",
13+
"10": "开始执行Nuitka编译",
14+
"11": "编译完整命令:%s"
715
}

main.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import argparse
22
import logging
3-
import multiprocessing
43
import platform
54
import subprocess
65
import sys
7-
import time
8-
from lang import *
6+
from functools import lru_cache
7+
from multiprocessing import cpu_count
98
from pathlib import Path
9+
from time import perf_counter
10+
11+
from lang import *
1012

1113
init_i18n(get_language_json(get_system_language()))
14+
_ = t
1215

1316
logging.basicConfig(
1417
level=logging.INFO,
@@ -38,17 +41,17 @@ def load_config(file_path: Path) -> dict:
3841
with open(file_path, "r", encoding="utf-8") as f:
3942
config_data: dict = json.load(f)
4043

41-
logger.info(t("1"), file_path)
44+
logger.info(_("1"), file_path)
4245
return config_data
4346

4447
except FileNotFoundError:
45-
logger.error(t("2"), file_path)
48+
logger.error(_("2"), file_path)
4649
sys.exit(1)
4750
except json.JSONDecodeError as e:
48-
logger.error(t("3"), file_path, e)
51+
logger.error(_("3"), file_path, e)
4952
sys.exit(1)
5053
except Exception as e:
51-
logger.exception(t("4"), e)
54+
logger.exception(_("4"), e)
5255
sys.exit(1)
5356

5457

@@ -57,10 +60,10 @@ def save_config(config: dict, file_path: Path):
5760
with open(file_path, "w", encoding="utf-8") as f:
5861
json.dump(config, f, indent=4, ensure_ascii=False)
5962

60-
logger.info("配置已保存到: %s", file_path)
63+
logger.info(_("5"), file_path)
6164

6265
except Exception as e:
63-
logger.error("保存配置文件失败: %s", e)
66+
logger.error(_("6"), e)
6467
sys.exit(1)
6568

6669

@@ -72,25 +75,24 @@ def validate_and_process_args(config: dict) -> list[str]:
7275
for arg in args:
7376

7477
if arg == "--jobs=$auto":
75-
cpu_count = multiprocessing.cpu_count()
76-
run_cpu_count: int = cpu_count * 2
78+
run_cpu_count: int = cpu_count() * 2
7779
processed_args.append(f"--jobs={run_cpu_count}")
7880
jobs_set = True
79-
logger.info("自动设置并行编译工作数: %d", run_cpu_count)
81+
logger.info(_("7"), run_cpu_count)
8082
elif arg.startswith("--jobs="):
8183
jobs_set = True
8284
processed_args.append(arg)
8385
else:
8486
if arg == "--file-version=$get":
85-
version: str = input("请输入版本号(格式:X.X.X.X):")
87+
version: str = input(_("8"))
8688
processed_args.append(f"--file-version={version}")
8789
else:
8890
processed_args.append(arg)
8991

9092
if not jobs_set:
91-
run_cpu_count = multiprocessing.cpu_count()
93+
run_cpu_count = cpu_count() * 2
9294
processed_args.append(f"--jobs={run_cpu_count}")
93-
logger.info(f"自动添加并行编译参数: --jobs={run_cpu_count}")
95+
logger.info(_("9"), run_cpu_count)
9496

9597
return processed_args
9698

@@ -102,11 +104,10 @@ def run_nuitka(config: dict) -> int | None:
102104

103105
cmd = [sys.executable, "-m", "nuitka"] + nuitka_args
104106

105-
logger.info("开始执行Nuitka编译...")
106-
logger.debug("完整命令: %s", " ".join(cmd))
107+
logger.info(_("10"))
108+
logger.debug(_("11"), " ".join(cmd))
107109

108-
start_time: float = time.perf_counter()
109-
print(cmd)
110+
start_time: float = perf_counter()
110111

111112
with subprocess.Popen(
112113
cmd,
@@ -119,27 +120,28 @@ def run_nuitka(config: dict) -> int | None:
119120
) as proc:
120121
if proc.stdout:
121122
for line in proc.stdout:
122-
print(f"[Nuitka输出] {line}", end="")
123+
print(f"[{_("nuitka_output")}] {line}", end="")
123124

124125
return_code: int = proc.wait()
125126

126-
duration = time.perf_counter() - start_time
127+
duration: float = perf_counter() - start_time
127128

128129
if return_code == 0:
129-
logger.info("编译成功完成! 耗时: %.3f秒", duration)
130+
logger.info("编译成功完成! 耗时: %.2f秒", duration)
130131
return 0
131132
else:
132133
logger.error("编译失败! 退出码: %d, 耗时: %.2f秒", return_code, duration)
133134
sys.exit(1)
134135

135136
except FileNotFoundError:
136-
logger.error("未找到Nuitka, 请先安装: pip install nuitka")
137+
logger.error("未找到Nuitka, 请先通过一下命令安装: \n\tpip install nuitka")
137138
sys.exit(1)
138139
except Exception as e:
139140
logger.exception("编译过程中发生意外错误: %s", e)
140141
sys.exit(1)
141142

142143

144+
@lru_cache(maxsize=5)
143145
def is_compiled() -> bool:
144146
try:
145147
if __compiled__ is not None:
@@ -206,7 +208,7 @@ def main() -> int:
206208
else:
207209
parser.print_help()
208210

209-
print("按下任意键以退出程序", end=" ")
211+
print("按下任意键以退出程序", end="")
210212
os.system("pause>nul")
211213
return 0
212214

0 commit comments

Comments
 (0)