Skip to content

Commit

Permalink
V1.0b5预发布
Browse files Browse the repository at this point in the history
  • Loading branch information
GT-ZhangAcer committed Nov 25, 2023
1 parent 8d7b113 commit 2802071
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 65 deletions.
2 changes: 1 addition & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ QPT是一款致力于让**开源项目**更好通往互联网世界的Python项
save_path="./out") # [输出目录]打包后相关文件的输出目录
# requirements_file="auto" # [Python依赖]此处可填入依赖文件路径,也可设置为auto自动搜索依赖
# hidden_terminal=False # [终端窗口]设置为True后,运行时将不会展示黑色终端窗口
# interpreter_module=Python37() # [跨版本编译]需要预先from qpt.modules.python_env import Python37
# interpreter_version=38 # [跨版本编译]填写38、39、310数字格式的版本号即可生成指定的环境
# 好奇什么时候需要跨版本编译?可参考下方"进阶使用QPT"一节的《打包兼容性更强的Python解释器》
# icon="your_ico.ico" # [自定义图标文件]支持将exe文件设置为ico/JPG/PNG等格式的自定义图标
# 开始打包
Expand Down
25 changes: 11 additions & 14 deletions examples/advanced/打包兼容性更强的Python解释器.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
举例当前已知的Python版本在Windows版本上的兼容情况如下:

| Python版本 | WinXP | Win7 | Win8 | Win8.1 | Win10 | Win11 |
| ----- | ----- | ----- | ----- | ----- | ----- | ----- |
| 3.4 |||||| - |
| 3.5 | X ||||| - |
| 3.6 | X ||||| - |
| 3.7 | X ||||||
| 3.8 | X || X | - |||
| 3.9 | X | X | X | - |||
| 3.10 | X | X | X | - |||
| 3.11 | X | X | X | - |||
|----------|-------|------|------|--------|-------|-------|
| 3.4 | | | | | | - |
| 3.5 | X | | | | | - |
| 3.6 | X | | | | | - |
| 3.7 | X | | | | | |
| 3.8 | X | | X | - | | |
| 3.9 | X | X | X | - | | |
| 3.10 | X | X | X | - | | |
| 3.11 | X | X | X | - | | |

## QPT推荐的版本

Expand All @@ -39,15 +39,12 @@
```python
from qpt.executor import CreateExecutableModule as CEM

# 此处导入Python37镜像
from qpt.modules.python_env import Python37

if __name__ == '__main__':
module = CEM(work_dir="./sample_program",
launcher_py_path="./sample_program/run.py",
save_path="./out",
# 下方指定Python镜像
interpreter_module=Python37())
# 下方指定Python版本
interpreter_version=38)
module.make()
```

Expand Down
11 changes: 9 additions & 2 deletions qpt/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,18 @@
default=None,
type=str,
help="[自定义图标文件]传入自定义图标文件路径,为EXE设置属于你的图标样式,支持将exe文件设置为ico/JPG/PNG等格式的自定义图标。")
@click.option("-pv",
"--python_version",
default=None,
type=int,
help="[跨版本编译]填写38、39、310数字格式的版本号即可生成指定的环境。")
def cli(folder,
py,
save,
require,
hidden,
icon):
icon,
pv):
Logging.info("-----------------------------QPT--------------------------------")
Logging.info("当前执行模式为命令式执行,仅提供QPT基础功能,高阶操作可在GitHub参考最新文档")
Logging.info(" https://github.com/GT-ZhangAcer/QPT")
Expand All @@ -74,7 +80,8 @@ def cli(folder,
save_path=save,
requirements_file=require,
hidden_terminal=hidden,
icon=icon)
icon=icon,
interpreter_version=pv)
module.make()


Expand Down
15 changes: 9 additions & 6 deletions qpt/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self,
icon=None,
deploy_mode=DEFAULT_DEPLOY_MODE,
sub_modules: List[SubModule] = None,
interpreter_module: BasePythonEnv = None,
interpreter_version: int = None,
hidden_terminal: bool = False,
with_debug: bool = False):
"""
Expand All @@ -53,12 +53,13 @@ def __init__(self,
:param icon: 主程序图标
:param deploy_mode: 部署方式,默认为“本地下载后安装”,填写为“setup_install”将减少初始化时间,但会增加体积
:param sub_modules: 子模块列表
:param interpreter_module: 解释器Module
:param interpreter_version: 解释器Module,例如39、310、311,无子版本号
:param hidden_terminal: 是否隐藏界面
:param with_debug: QPT验证模式 - 请勿使用
"""

Logging.warning(msg="QPT 1.0b5版本中有较大更新,且仅对Win10 1809以上版本进行验证,低于该版本的操作系统可能存在无法运行问题。")
Logging.warning(
msg="QPT 1.0b5版本中有较大更新,且仅对Win10 1809以上版本进行验证,低于该版本的操作系统可能存在无法运行问题。")
self.with_debug = with_debug
self.work_dir = work_dir

Expand Down Expand Up @@ -157,10 +158,12 @@ def make_launcher_py_path(lp_path):

# Module相关
# 初始化解释器Module
if interpreter_module is None:
interpreter_module = AutoPythonEnv()
interpreter_version = AutoPythonEnv() if interpreter_version is None else BasePythonEnv(
name="interpreter",
version=interpreter_version)

# 获取SubModule列表 - 此处均无ExtModule
self.lazy_modules = [interpreter_module, QPTDependencyPackage()]
self.lazy_modules = [interpreter_version, QPTDependencyPackage()]

self.sub_modules = sub_modules if sub_modules is not None else list()

Expand Down
62 changes: 23 additions & 39 deletions qpt/modules/python_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,38 @@
PYTHON_ENV_MODE_ONLINE_INSTALLATION = "[暂不支持]不封装Python环境,用户使用时在线进行下载并部署"
DEFINE_PYTHON_ENV_MODE = PYTHON_ENV_MODE_SPEED_FIRST

SUPPORT_PYTHON_VERSION = ["3.8", "3.9", "3.10", "3.11", "3.12"]
DEFAULT_PYTHON_IMAGE_VERSION = "3.8"
SUPPORT_PYTHON_VERSION = [38, 39, 310, 311, 312]


class PackPythonEnvOpt(SubModuleOpt):
def __init__(self, version: str = None, mode=PYTHON_ENV_MODE_SPEED_FIRST):
def __init__(self, version: int, mode=PYTHON_ENV_MODE_SPEED_FIRST):
super().__init__()
self.version = ".".join(version.split('.')[:2])
self.version = version
self.mode = mode

def act(self) -> None:
# ToDo 增加版本控制
v = f"python{self.version.replace('.', '')}"
path = check_and_install_sdk_in_this_env("QEnvPython")
copytree(os.path.join(path, v), os.path.join(self.module_path, "Python"))
m = f"python{self.version}"
path = check_and_install_sdk_in_this_env(f"QEnvPython{self.version}")
copytree(os.path.join(path, m), os.path.join(self.module_path, "Python"))

# ToDo 未来对Tinkter和VC2019进行分离,先暂时放一起
v = f"tkinter{self.version.replace('.', '')}"
path = check_and_install_sdk_in_this_env("QEnvPython")
copytree(os.path.join(path, v), os.path.join(self.module_path, "Python"))
m = f"tkinter{self.version}"
path = check_and_install_sdk_in_this_env(f"QEnvPython{self.version}")
copytree(os.path.join(path, m), os.path.join(self.module_path, "Python"))

v = "vcredist"
m = "vcredist"
path = check_and_install_sdk_in_this_env("QVCRedist")
copytree(os.path.join(path, v), os.path.join(self.module_path, "Python"))
copytree(os.path.join(path, m), os.path.join(self.module_path, "Python"))


class BasePythonEnv(SubModule):
def __init__(self, name, version, mode=DEFINE_PYTHON_ENV_MODE):
def __init__(self, name, version: int, mode=DEFINE_PYTHON_ENV_MODE):
if version not in SUPPORT_PYTHON_VERSION:
if version < SUPPORT_PYTHON_VERSION[0]:
n_version = SUPPORT_PYTHON_VERSION[0]
else:
n_version = SUPPORT_PYTHON_VERSION[-1]
Logging.warning(f"----------------------------------------------------------------------\n"
f"未在QPT中找到Python{version}镜像,QPT目前提供的Python镜像版本有限,\n"
f"请尽可能使用Python3.7~Python3.10等主流Python版本进行打包,兼容性如下。\n"
Expand All @@ -51,41 +54,22 @@ def __init__(self, name, version, mode=DEFINE_PYTHON_ENV_MODE):
f"..."
f"完整说明详见:https://github.com/QPT-Family/QPT/blob/开发分支/examples/advanced/打包兼容性更强的Python解释器.md"
f"----------------------------------------------------------------------\n"
f"已强制设置目标版本号为{DEFAULT_PYTHON_IMAGE_VERSION},请检查存在以下兼容性问题:\n"
f"已强制设置目标版本号为{n_version},请检查存在以下兼容性问题:\n"
f"1. 需考虑待打包的代码是否兼容该Python版本\n"
f"2. 该Python版本是否可以在目标用户操作系统上执行\n"
f"----------------------------------------------------------------------\n")
version = n_version

super().__init__(name, level=TOP_LEVEL)
self.add_pack_opt(PackPythonEnvOpt(version=version, mode=mode))
self.python_version = "非标准的PythonSubModule,需指定版本号"


class AutoPythonEnv(BasePythonEnv):
def __init__(self, mode=DEFINE_PYTHON_ENV_MODE):
import platform
version = platform.python_version()
Logging.info(f"当前解释器版本为{version},正在向QPT查询是否存在合适的Python镜像...")
version = platform.python_version_tuple()
version = "".join(version[0:2])
Logging.info(f"当前解释器版本为Python{version},正在向QPT查询是否存在合适的Python镜像...")
# 截断版本号,只保留两位
version = "".join([v if version_index == 1 else v + "."
for version_index, v in enumerate(version.split(".")[:2])])
super().__init__(name=None, mode=mode, version=version)


class Python38(BasePythonEnv):
def __init__(self, mode=DEFINE_PYTHON_ENV_MODE):
super().__init__(name=None, version="3.8", mode=mode)


class Python39(BasePythonEnv):
def __init__(self, mode=DEFINE_PYTHON_ENV_MODE):
super().__init__(name=None, version="3.9", mode=mode)


class Python310(BasePythonEnv):
def __init__(self, mode=DEFINE_PYTHON_ENV_MODE):
super().__init__(name=None, version="3.10", mode=mode)


class Python311(BasePythonEnv):
def __init__(self, mode=DEFINE_PYTHON_ENV_MODE):
super().__init__(name=None, version="3.11", mode=mode)
super().__init__(name="interpreter", mode=mode, version=int(version))
28 changes: 25 additions & 3 deletions unit_test/run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_module_m_gui_python38(self):
launcher_py_path="./sandbox_m/run.py",
save_path=os.path.join(OUT_DIR_ROOT, sys._getframe().f_code.co_name),
requirements_file="sandbox_m/requirements_with_opt.txt",
interpreter_module=Python38(),
interpreter_version=38,
with_debug=True,
hidden_terminal=True)
module.make()
Expand All @@ -41,7 +41,7 @@ def test_module_m_gui_python39(self):
launcher_py_path="./sandbox_m/run.py",
save_path=os.path.join(OUT_DIR_ROOT, sys._getframe().f_code.co_name),
requirements_file="sandbox_m/requirements_with_opt.txt",
interpreter_module=Python39(),
interpreter_version=39,
with_debug=True,
hidden_terminal=True)
module.make()
Expand All @@ -52,7 +52,29 @@ def test_module_m_gui_python310(self):
launcher_py_path="./sandbox_m/run.py",
save_path=os.path.join(OUT_DIR_ROOT, sys._getframe().f_code.co_name),
requirements_file="sandbox_m/requirements_with_opt.txt",
interpreter_module=Python310(),
interpreter_version=310,
with_debug=True,
hidden_terminal=True)
module.make()

def test_module_m_gui_python311(self):
# 验证Python兼容性
module = CreateExecutableModule(work_dir="./sandbox_m",
launcher_py_path="./sandbox_m/run.py",
save_path=os.path.join(OUT_DIR_ROOT, sys._getframe().f_code.co_name),
requirements_file="sandbox_m/requirements_with_opt.txt",
interpreter_version=311,
with_debug=True,
hidden_terminal=True)
module.make()

def test_module_m_gui_python312(self):
# 验证Python兼容性
module = CreateExecutableModule(work_dir="./sandbox_m",
launcher_py_path="./sandbox_m/run.py",
save_path=os.path.join(OUT_DIR_ROOT, sys._getframe().f_code.co_name),
requirements_file="sandbox_m/requirements_with_opt.txt",
interpreter_version=312,
with_debug=True,
hidden_terminal=True)
module.make()
Expand Down

0 comments on commit 2802071

Please sign in to comment.