Skip to content

Commit

Permalink
Merge pull request #10 from muziing/dev
Browse files Browse the repository at this point in the history
Version `0.1.13`
  • Loading branch information
muziing authored Dec 18, 2023
2 parents 7f834e4 + 3e65dc1 commit 2be2bed
Show file tree
Hide file tree
Showing 33 changed files with 2,995 additions and 784 deletions.
34 changes: 29 additions & 5 deletions dev_scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
check_version_num,
)
from dev_scripts.clear_cache import clear_pycache, clear_pyinstaller_dist
from dev_scripts.path_constants import README_FILE_LIST, RESOURCES_PATH, SRC_PATH

# TODO 加入日志模块,保存构建日志
from dev_scripts.path_constants import (
PROJECT_ROOT,
README_FILE_LIST,
RESOURCES_PATH,
SRC_PATH,
)


def process_md_images(md_file_list: list[Path]) -> None:
Expand Down Expand Up @@ -49,7 +52,7 @@ def compile_resources() -> int:
:return: rcc 进程返回码
"""

compiled_file_path = RESOURCES_PATH / "compiled_resources.py"
compiled_file_path = RESOURCES_PATH / "COMPILED_RESOURCES.py"
qrc_file_path = RESOURCES_PATH / "resources.qrc"
cmd = [
"pyside6-rcc",
Expand All @@ -62,6 +65,25 @@ def compile_resources() -> int:
return result.returncode


def export_requirements() -> int:
"""
将项目依赖项导出至 requirements.txt 中
:return: poetry export 命令返回值
"""

poetry_export_cmd = [
"poetry",
"export",
"--without-hashes",
"-o",
PROJECT_ROOT / "requirements.txt",
"--format=requirements.txt",
]
result = subprocess.run(poetry_export_cmd)
print(f"已将当前项目依赖导出至 requirements.txt,poetry export 返回码:{result.returncode}")
return result.returncode


def build_py2exe_gui() -> None:
"""
构建项目的总函数 \n
Expand All @@ -73,6 +95,7 @@ def build_py2exe_gui() -> None:
clear_pycache(SRC_PATH)
process_md_images(README_FILE_LIST)
# compile_resources()
export_requirements()
print(f"pre-commit 检查完毕,返回码:{check_pre_commit()}。")
print(f"mypy 检查完毕,返回码:{check_mypy()}。")

Expand All @@ -86,6 +109,7 @@ def build_py2exe_gui() -> None:


if __name__ == "__main__":
# compile_resources()
# process_md_images()
# compile_resources()
# export_requirements()
build_py2exe_gui()
9 changes: 0 additions & 9 deletions dev_scripts/check_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,8 @@ def check_mypy() -> int:
return result.returncode


def check_requirements() -> int:
"""
检查 requirements.txt 中的依赖是否最新
"""

pass


if __name__ == "__main__":
check_license_statement()
check_version_num()
check_pre_commit()
check_mypy()
check_requirements()
2 changes: 1 addition & 1 deletion dev_scripts/path_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
SRC_PATH = PROJECT_ROOT / "src" # 源码目录
SRC_PKG_PATH = SRC_PATH / "py2exe_gui"
RESOURCES_PATH = SRC_PKG_PATH / "Resources" # 静态资源文件目录
COMPILED_RESOURCES = RESOURCES_PATH / "compiled_resources.py" # 编译静态资源文件
COMPILED_RESOURCES = RESOURCES_PATH / "COMPILED_RESOURCES.py" # 编译静态资源文件
README_FILE_LIST = [
PROJECT_ROOT / "README.md",
PROJECT_ROOT / "README_zh.md",
Expand Down
11 changes: 6 additions & 5 deletions docs/ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
- [ ] Python 解释器选择器
- [ ] 文件浏览对话框选择解释器可执行文件
- [ ] 处理解释器验证器返回结果,异常时弹出对话框要求用户自行检查确认
- [ ] 创建「解释器环境类」,保存解释器路径等信息
- [ ] ComboBox 中列出各解释器,将解释器环境类保存在userData中
- [x] 创建「解释器环境类」,保存解释器路径等信息
- [x] ComboBox 中列出各解释器,将解释器路径保存在userData中
- [ ] 快捷显示已安装的 `PyInstaller` 版本,未安装则提供「一键安装」
- [ ] (?) 识别系统解释器/venv/Poetry/conda等
- [ ] 命令浏览器
- [x] 命令浏览器
- [x] 显示将传递给 PyInstaller 的选项列表
- [x] 高亮提示
- [x] 以终端命令格式显示完整命令,并添加续行符
- [ ] 导出为脚本功能,根据运行时平台导出 bash、powershell 等格式脚本
- [ ] "What is this" 提示
- [ ] 右键菜单,添加指向对应 PyInstaller 文档,提供完整帮助信息
- [ ] `PyInstaller` 选项参数详解表格
Expand All @@ -42,7 +43,7 @@
- [ ] 打包任务
- [x] 创建打包任务,保存所有选项
- [ ] 创建 [`.spec` 文件](https://pyinstaller.org/en/stable/spec-files.html)
- [ ] `spec` 编辑器
- [ ] ~~`spec` 编辑器~~

## 界面

Expand All @@ -53,7 +54,7 @@
- [x] 使用 `qrc` 管理静态资源
- [ ] 翻译与国际化
- [ ] Qt 提供的界面文本自动翻译
- [ ] 自实现的不同语言下功能差异,如“打开PyInstaller文档”指向不同的链接等
- [x] 自实现的不同语言下功能差异,如“打开PyInstaller文档”指向不同的链接等

## 应用程序级

Expand Down
49 changes: 26 additions & 23 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "py2exe-gui"
version = "0.1.12"
version = "0.1.13"
description = "GUI for PyInstaller, based on PySide6"
keywords = ["PyInstaller", "GUI", "PySide6"]
authors = ["muzing <muzi2001@foxmail.com>"]
Expand All @@ -21,7 +21,7 @@ py2exe-gui = 'py2exe_gui.__main__:main'
#priority = "default"

[tool.poetry.dependencies]
python = ">=3.8,<3.12"
python = ">=3.8,<3.13"
PySide6 = "^6.6.0"
pyyaml = "^6.0.1"

Expand All @@ -39,11 +39,12 @@ types-pyyaml = "^6.0.12.12"
[tool.black]
line-length = 88
target-version = ["py311"]
extend-exclude = "compiled_resources.py"
extend-exclude = "COMPILED_RESOURCES.py"

[tool.isort]
profile = "black"
line_length = 88
py_version=311

[tool.mypy]
python_version = "3.11"
Expand Down
9 changes: 5 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pyside6-addons==6.6.1 ; python_version >= "3.8" and python_version < "3.12"
pyside6-essentials==6.6.1 ; python_version >= "3.8" and python_version < "3.12"
pyside6==6.6.1 ; python_version >= "3.8" and python_version < "3.12"
shiboken6==6.6.1 ; python_version >= "3.8" and python_version < "3.12"
pyside6-addons==6.6.1 ; python_version >= "3.8" and python_version < "3.13"
pyside6-essentials==6.6.1 ; python_version >= "3.8" and python_version < "3.13"
pyside6==6.6.1 ; python_version >= "3.8" and python_version < "3.13"
pyyaml==6.0.1 ; python_version >= "3.8" and python_version < "3.13"
shiboken6==6.6.1 ; python_version >= "3.8" and python_version < "3.13"
11 changes: 11 additions & 0 deletions src/Py2exe-GUI.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# Licensed under the GPLv3 License: https://www.gnu.org/licenses/gpl-3.0.html
# For details: https://github.com/muziing/Py2exe-GUI/blob/main/README.md#license

"""
程序入口脚本
由于整个程序作为单一 Python 包发布,直接运行 py2exe_gui.__main__.py 会导致相对导入错误
需要在包外留有这个显式的入口模块来提供“通过运行某个 .py 文件启动程序”功能和 PyInstaller 打包入口脚本
Py2exe-GUI 启动方式:
python Py2exe-GUI.py
python -m py2exe_gui
"""

import sys

from PySide6.QtWidgets import QApplication
Expand Down
6 changes: 5 additions & 1 deletion src/py2exe_gui/Constants/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Licensed under the GPLv3 License: https://www.gnu.org/licenses/gpl-3.0.html
# For details: https://github.com/muziing/Py2exe-GUI/blob/main/README.md#license

"""
各类常量与全局变量
"""

from .app_constants import *
from .packaging_constants import *
from .platform_constants import *
from .type_constants import *
from .python_env_constants import *
14 changes: 13 additions & 1 deletion src/py2exe_gui/Constants/app_constants.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
# Licensed under the GPLv3 License: https://www.gnu.org/licenses/gpl-3.0.html
# For details: https://github.com/muziing/Py2exe-GUI/blob/main/README.md#license

from .runtime_info import RUNTIME_INFO

APP_URLs = {
"HOME_PAGE": "https://github.com/muziing/Py2exe-GUI",
"BugTracker": "https://github.com/muziing/Py2exe-GUI/issues",
"Pyinstaller_doc": "https://pyinstaller.org/",
}

if RUNTIME_INFO.language_code == "zh_CN":
APP_URLs["Pyinstaller_doc"] = "https://muzing.gitbook.io/pyinstaller-docs-zh-cn/"


class AppConstant:
"""
应用程序级的常量
"""

NAME = "Py2exe-GUI"
VERSION = "0.1.12"
VERSION = "0.1.13"
AUTHORS = ["muzing <muzi2001@foxmail.com>"]
LICENSE = "GPL-3.0-or-later"
HOME_PAGE = APP_URLs["HOME_PAGE"]
44 changes: 44 additions & 0 deletions src/py2exe_gui/Constants/python_env_constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Licensed under the GPLv3 License: https://www.gnu.org/licenses/gpl-3.0.html
# For details: https://github.com/muziing/Py2exe-GUI/blob/main/README.md#license

import enum
import subprocess
from typing import NamedTuple


@enum.unique
class PyEnvType(enum.IntFlag):
"""
Python 解释器(环境)类型,如系统解释器、venv 虚拟环境等 \n
"""

system = enum.auto() # 系统解释器
venv = enum.auto() # venv 虚拟环境 https://docs.python.org/3/library/venv.html
poetry = enum.auto() # Poetry 环境 https://python-poetry.org/
conda = enum.auto() # conda 环境 https://docs.conda.io/en/latest/


class PyEnv(NamedTuple):
"""
Python 解释器(环境)数据类
"""

type: PyEnvType
executable_path: str


def get_pyenv_version(pyenv: PyEnv) -> str:
"""
获取Python解释器的版本,以形如 "3.11.7" 的字符串形式返回 \n
:param pyenv: Python环境
:return: Version of the Python interpreter, such as "3.11.7".
"""

cmd = [
pyenv.executable_path,
"-c",
"import platform;print(platform.python_version(), end='')",
]
result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
version = str(result.stdout, encoding="utf-8")
return version
36 changes: 36 additions & 0 deletions src/py2exe_gui/Constants/runtime_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Licensed under the GPLv3 License: https://www.gnu.org/licenses/gpl-3.0.html
# For details: https://github.com/muziing/Py2exe-GUI/blob/main/README.md#license

"""
运行时信息
"""

import sys
from locale import getdefaultlocale
from typing import NamedTuple, Optional

from .platform_constants import PLATFORM, get_platform


class RuntimeInfo(NamedTuple):
"""
运行时信息数据结构类
"""

platform: PLATFORM # 运行平台,Windows、macOS、Linux或其他
language_code: Optional[str] # 语言环境,zh-CN、en-US 等
is_bundled: bool # 是否在已被 PyInstaller 捆绑的冻结环境中运行


# 虽然 locale.getdefaultlocale() 函数已被废弃[https://github.com/python/cpython/issues/90817],
# 但仍然是目前唯一能在 Windows 平台正确获取语言编码的方式[https://github.com/python/cpython/issues/82986]
# 当 Python 更新修复了这一问题后,将迁移至 locale.getlocale()
language_code = getdefaultlocale()[0]

# https://pyinstaller.org/en/stable/runtime-information.html#run-time-information
if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
is_bundled = True
else:
is_bundled = False

RUNTIME_INFO = RuntimeInfo(get_platform(), language_code, is_bundled)
6 changes: 0 additions & 6 deletions src/py2exe_gui/Constants/type_constants.py

This file was deleted.

Loading

0 comments on commit 2be2bed

Please sign in to comment.