mirror of
https://github.com/muziing/Py2exe-GUI.git
synced 2025-01-27 17:02:55 +08:00
Update dev scripts
更新开发脚本: - 增加对 poetry build 构建的异常处理; - 修复路径常量中获取项目根路径的方法,排除运行脚本的工作目录不同带来的干扰; - 添加两个关于构建 PySide 翻译工作流的函数 `gen_ts()` 与 `gen_qm()`; - 将 RCC 资源编译函数 `compile_resources()` 重构至新的模块中;
This commit is contained in:
parent
5f3bc8b46f
commit
b7e36c9960
@ -11,12 +11,7 @@ from dev_scripts.check_funcs import (
|
|||||||
check_version_num,
|
check_version_num,
|
||||||
)
|
)
|
||||||
from dev_scripts.clear_cache import clear_pycache, clear_pyinstaller_dist
|
from dev_scripts.clear_cache import clear_pycache, clear_pyinstaller_dist
|
||||||
from dev_scripts.path_constants import (
|
from dev_scripts.path_constants import PROJECT_ROOT, README_FILE_LIST, SRC_PATH
|
||||||
PROJECT_ROOT,
|
|
||||||
README_FILE_LIST,
|
|
||||||
RESOURCES_PATH,
|
|
||||||
SRC_PATH,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def process_md_images(md_file_list: list[Path]) -> None:
|
def process_md_images(md_file_list: list[Path]) -> None:
|
||||||
@ -46,30 +41,6 @@ def process_md_images(md_file_list: list[Path]) -> None:
|
|||||||
# FIXME 会在文件尾部多出来莫名其妙的行
|
# FIXME 会在文件尾部多出来莫名其妙的行
|
||||||
|
|
||||||
|
|
||||||
def compile_resources() -> int:
|
|
||||||
"""调用 RCC 工具编译静态资源
|
|
||||||
|
|
||||||
:return: rcc 进程返回码
|
|
||||||
"""
|
|
||||||
|
|
||||||
compiled_file_path = RESOURCES_PATH / "COMPILED_RESOURCES.py"
|
|
||||||
qrc_file_path = RESOURCES_PATH / "resources.qrc"
|
|
||||||
cmd = [
|
|
||||||
"pyside6-rcc",
|
|
||||||
"-o",
|
|
||||||
str(compiled_file_path.absolute()),
|
|
||||||
str(qrc_file_path.absolute()),
|
|
||||||
]
|
|
||||||
try:
|
|
||||||
result = subprocess.run(cmd)
|
|
||||||
except subprocess.SubprocessError as e:
|
|
||||||
print(f"RCC编译进程错误:{e}")
|
|
||||||
raise e
|
|
||||||
else:
|
|
||||||
print(f"已完成静态资源文件编译,RCC返回码:{result.returncode}。")
|
|
||||||
return result.returncode
|
|
||||||
|
|
||||||
|
|
||||||
def export_requirements() -> int:
|
def export_requirements() -> int:
|
||||||
"""将项目依赖项导出至 requirements.txt 中
|
"""将项目依赖项导出至 requirements.txt 中
|
||||||
|
|
||||||
@ -109,12 +80,18 @@ def build_py2exe_gui() -> None:
|
|||||||
print(f"mypy 检查完毕,返回码:{check_mypy()}。")
|
print(f"mypy 检查完毕,返回码:{check_mypy()}。")
|
||||||
|
|
||||||
# 正式构建
|
# 正式构建
|
||||||
subprocess.run(["poetry", "build"]) # TODO 处理异常与返回值
|
try:
|
||||||
|
result = subprocess.run(["poetry", "build"], check=True)
|
||||||
# 清理
|
except subprocess.SubprocessError as e:
|
||||||
process_md_images(README_FILE_LIST)
|
print(f"Poetry build 失败:{e}")
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
print(f"Poetry build 完毕,返回码:{result.returncode}。")
|
||||||
|
finally:
|
||||||
|
# 清理
|
||||||
|
process_md_images(README_FILE_LIST)
|
||||||
else:
|
else:
|
||||||
print("构建失败,有未通过的检查项")
|
print("有未通过的检查项,不进行构建")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
"""
|
"""开发脚本中使用的相对路径常量
|
||||||
开发脚本中使用的相对路径常量
|
|
||||||
所有脚本应以项目根目录为工作目录运行
|
所有脚本应以项目根目录为工作目录运行
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
PROJECT_ROOT = Path("../") # 项目根目录
|
PROJECT_ROOT = Path(__file__).parent.parent # 项目根目录
|
||||||
SRC_PATH = PROJECT_ROOT / "src" # 源码目录
|
SRC_PATH = PROJECT_ROOT / "src" # 源码目录
|
||||||
SRC_PKG_PATH = SRC_PATH / "py2exe_gui"
|
SRC_PKG_PATH = SRC_PATH / "py2exe_gui" # 包目录
|
||||||
RESOURCES_PATH = SRC_PKG_PATH / "Resources" # 静态资源文件目录
|
RESOURCES_PATH = SRC_PKG_PATH / "Resources" # 静态资源文件目录
|
||||||
COMPILED_RESOURCES = RESOURCES_PATH / "COMPILED_RESOURCES.py" # 编译静态资源文件
|
COMPILED_RESOURCES = RESOURCES_PATH / "COMPILED_RESOURCES.py" # 编译静态资源文件
|
||||||
|
WIDGETS_PATH = SRC_PKG_PATH / "Widgets" # 控件目录
|
||||||
README_FILE_LIST = [
|
README_FILE_LIST = [
|
||||||
PROJECT_ROOT / "README.md",
|
PROJECT_ROOT / "README.md",
|
||||||
PROJECT_ROOT / "README_zh.md",
|
PROJECT_ROOT / "README_zh.md",
|
||||||
|
85
dev_scripts/pyside6_tools_script.py
Normal file
85
dev_scripts/pyside6_tools_script.py
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
"""开发脚本,便于调用 PySide6 提供的各种工具程序
|
||||||
|
"""
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
from dev_scripts.path_constants import (
|
||||||
|
COMPILED_RESOURCES,
|
||||||
|
PROJECT_ROOT,
|
||||||
|
RESOURCES_PATH,
|
||||||
|
SRC_PKG_PATH,
|
||||||
|
WIDGETS_PATH,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def compile_resources() -> int:
|
||||||
|
"""调用 RCC 工具编译静态资源
|
||||||
|
|
||||||
|
:return: rcc 进程返回码
|
||||||
|
"""
|
||||||
|
|
||||||
|
compiled_file_path = COMPILED_RESOURCES
|
||||||
|
qrc_file_path = RESOURCES_PATH / "resources.qrc"
|
||||||
|
cmd = [
|
||||||
|
"pyside6-rcc",
|
||||||
|
"-o",
|
||||||
|
compiled_file_path,
|
||||||
|
qrc_file_path,
|
||||||
|
]
|
||||||
|
|
||||||
|
try:
|
||||||
|
result = subprocess.run(cmd, cwd=PROJECT_ROOT, check=True)
|
||||||
|
except subprocess.SubprocessError as e:
|
||||||
|
print(f"RCC 编译进程错误:{e}")
|
||||||
|
raise e
|
||||||
|
else:
|
||||||
|
print(f"已完成静态资源文件编译,RCC 返回码:{result.returncode}。")
|
||||||
|
return result.returncode
|
||||||
|
|
||||||
|
|
||||||
|
def gen_ts(lang: str = "zh_CN") -> int:
|
||||||
|
"""调用 lupdate 工具分析源码,生成 .ts 文本翻译文件
|
||||||
|
|
||||||
|
:param lang: 目标翻译语言代码
|
||||||
|
:return: lupdate 返回码
|
||||||
|
"""
|
||||||
|
|
||||||
|
source = [*list(WIDGETS_PATH.glob("**/*.py")), SRC_PKG_PATH / "__main__.py"]
|
||||||
|
target = RESOURCES_PATH / "i18n" / f"{lang.replace('-', '_')}.ts"
|
||||||
|
cmd = ["pyside6-lupdate", *source, "-ts", target]
|
||||||
|
|
||||||
|
try:
|
||||||
|
result = subprocess.run(cmd, cwd=PROJECT_ROOT, check=True)
|
||||||
|
except subprocess.SubprocessError as e:
|
||||||
|
print(f"lupdate 进程错误:{e}")
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
print(f"已完成文本翻译文件生成,lupdate 返回码:{result.returncode}。")
|
||||||
|
return result.returncode
|
||||||
|
|
||||||
|
|
||||||
|
def gen_qm(lang: str = "zh_CN") -> int:
|
||||||
|
"""调用 lrelease 工具编译.ts 文本翻译文件
|
||||||
|
|
||||||
|
:param lang: 目标翻译语言代码
|
||||||
|
:return: lrelease 返回码
|
||||||
|
"""
|
||||||
|
|
||||||
|
source = RESOURCES_PATH / "i18n" / f"{lang.replace('-', '_')}.ts"
|
||||||
|
target = RESOURCES_PATH / "i18n" / f"{lang.replace('-', '_')}.qm"
|
||||||
|
cmd = ["pyside6-lrelease", source, "-qm", target]
|
||||||
|
|
||||||
|
try:
|
||||||
|
result = subprocess.run(cmd, cwd=PROJECT_ROOT, check=True)
|
||||||
|
except subprocess.SubprocessError as e:
|
||||||
|
print(f"lrelease 进程错误:{e}")
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
print(f"已完成文本翻译文件编译,lrelease 返回码:{result.returncode}。")
|
||||||
|
return result.returncode
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# compile_resources()
|
||||||
|
gen_ts("zh_CN")
|
||||||
|
# gen_qm("zh_CN")
|
Loading…
x
Reference in New Issue
Block a user