Update dev scripts

添加 `__all__`,模块级提供的函数列表呈现更清晰;
更新 docstrings;
其他微小改动优化;
This commit is contained in:
muzing 2024-01-06 12:00:00 +08:00
parent a6b7e323e4
commit 0edbed1fa5
4 changed files with 53 additions and 24 deletions

View File

@ -1,6 +1,11 @@
"""用于构建项目的脚本
"""
__all__ = [
"export_requirements",
"build_py2exe_gui",
]
import subprocess
from dev_scripts.check_funcs import (
@ -46,7 +51,7 @@ def build_py2exe_gui() -> None:
clear_pyinstaller_dist(SRC_PATH)
clear_pycache(SRC_PATH)
# compile_resources()
export_requirements()
# export_requirements()
print(f"pre-commit 检查完毕,返回码:{check_pre_commit()}")
print(f"mypy 检查完毕,返回码:{check_mypy()}")

View File

@ -1,6 +1,12 @@
"""各类检查函数
"""
各类检查函数
"""
__all__ = [
"check_license_statement",
"check_version_num",
"check_pre_commit",
"check_mypy",
]
import subprocess
import tomllib
@ -17,8 +23,8 @@ from py2exe_gui import __version__ as py2exe_gui__version__
def check_license_statement() -> int:
"""
检查源代码文件中是否都包含了许可声明
"""检查源代码文件中是否都包含了许可声明
:return: 0-所有源文件都包含许可声明1-存在缺失许可声明的源文件
"""
@ -46,8 +52,8 @@ def check_license_statement() -> int:
def check_version_num() -> int:
"""
检查各部分声明的版本号是否一致 \n
"""检查各部分声明的版本号是否一致
:return: 0-各处版本一致1-存在版本不一致情况
"""
@ -74,8 +80,10 @@ def check_version_num() -> int:
def check_pre_commit() -> int:
"""
调用已有的 pre-commit 检查工具进行检查 \n
"""调用已有的 pre-commit 检查工具进行检查
如果首次调用返回值不为0可能已经进行了一定的自动修复需要再运行第二次检查返回值
:return: pre-commit 进程返回码
"""
@ -86,7 +94,7 @@ def check_pre_commit() -> int:
print("开始进行第二次 pre-commit 检查...")
result_2 = subprocess.run(pre_commit_run_cmd)
if result_2.returncode != 0:
warnings.warn("pre-commit进程返回码非0建议检查", stacklevel=1)
warnings.warn("pre-commit 进程返回码非 0建议检查", stacklevel=1)
return result_2.returncode
else:
print("pre-commit 检查完成,所有项目通过。")
@ -94,16 +102,18 @@ def check_pre_commit() -> int:
def check_mypy() -> int:
"""
调用mypy进行静态代码分析
"""
"""调用mypy进行静态代码分析"""
mypy_cmd = ["mypy", SRC_PKG_PATH, "--config-file", PROJECT_ROOT / "pyproject.toml"]
print("开始运行 mypy 检查...")
result = subprocess.run(mypy_cmd)
print("mypy 检查运行完毕。")
return result.returncode
try:
result = subprocess.run(mypy_cmd)
except subprocess.CalledProcessError as e:
warnings.warn(f"mypy 检查失败,错误信息:{e}", stacklevel=1)
return e.returncode
else:
print("mypy 检查运行完毕。")
return result.returncode
if __name__ == "__main__":

View File

@ -1,6 +1,11 @@
"""各种清理函数,如清理 Python 编译缓存、PyInstaller 打包中间文件与输出文件等
"""
__all__ = [
"clear_pyinstaller_dist",
"clear_pycache",
]
import os
from pathlib import Path
from shutil import rmtree
@ -9,14 +14,15 @@ from dev_scripts.path_constants import SRC_PATH
def clear_pyinstaller_dist(src_path: Path) -> None:
"""
清理开发过程中测试运行时的打包中间文件及结果文件 \n
"""清理开发过程中测试运行时的打包中间文件及结果文件
:param src_path: Py2exe-GUI.py 运行目录
"""
dist_path = src_path / Path("dist")
build_path = src_path / Path("build")
dist_path = src_path / "dist"
build_path = src_path / "build"
spec_path_list = list(src_path.glob("*.spec"))
if dist_path.exists():
rmtree(dist_path)
if build_path.exists():
@ -24,13 +30,15 @@ def clear_pyinstaller_dist(src_path: Path) -> None:
if spec_path_list:
for spec_file in spec_path_list:
os.remove(spec_file)
print("Pyinstaller dist all cleaned.")
print("Pyinstaller dist and cache all cleaned.")
def clear_pycache(src_path: Path) -> None:
"""
清理给定路径下的所有 .pyc .pyo 文件与 __pycache__ 目录 \n
"""清理给定路径下的所有 `.pyc` `.pyo` 文件与 `__pycache__` 目录
ref: https://stackoverflow.com/a/41386937
:param src_path: 源码 src 目录路径
"""

View File

@ -1,6 +1,12 @@
"""开发脚本,便于调用 PySide6 提供的各种工具程序
"""
__all__ = [
"compile_resources",
"gen_ts",
"gen_qm",
]
import subprocess
from dev_scripts.path_constants import (