Skip to content

Commit a719780

Browse files
committed
Fix Packaging
修复Packaging类中未为子进程显式设置工作目录的问题;
1 parent c14000d commit a719780

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/py2exe_gui/Core/packaging.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from pathlib import Path
12
from typing import List, Optional
23

34
from PySide6 import QtCore
@@ -8,7 +9,8 @@
89

910
class Packaging(QtCore.QObject):
1011
"""
11-
执行打包的类 \n
12+
执行打包子进程的类
13+
不负责输入参数的检查 \n
1214
"""
1315

1416
# 自定义信号
@@ -23,6 +25,7 @@ def __init__(self, parent: Optional[QtCore.QObject] = None) -> None:
2325

2426
self.args_dict: dict = dict.fromkeys(pyinstaller_args_list, "")
2527
self._args: List[str] = []
28+
self._subprocess_working_dir: str = ""
2629
self.subprocess: SubProcessTool = SubProcessTool(self, program="pyinstaller")
2730

2831
@QtCore.Slot(tuple)
@@ -36,13 +39,15 @@ def set_pyinstaller_args(self, arg: tuple[str, str]) -> None:
3639
if arg_key in pyinstaller_args_list:
3740
self.args_dict[arg_key] = arg_value
3841
self._add_pyinstaller_args()
42+
self._set_subprocess_working_dir()
3943

4044
def _add_pyinstaller_args(self) -> None:
4145
"""
4246
将命令参数字典中的参数按顺序添加到命令参数列表中 \n
4347
"""
4448

4549
self._args = [] # 避免重复添加
50+
4651
self._args.extend([self.args_dict[PyinstallerArgs.script_path]])
4752
if self.args_dict[PyinstallerArgs.icon_path]:
4853
self._args.extend(["--icon", self.args_dict[PyinstallerArgs.icon_path]])
@@ -61,10 +66,19 @@ def _add_pyinstaller_args(self) -> None:
6166

6267
self.args_settled.emit(self._args)
6368

69+
def _set_subprocess_working_dir(self) -> None:
70+
"""
71+
设置子进程工作目录 \n
72+
"""
73+
74+
script_path = self.args_dict[PyinstallerArgs.script_path]
75+
self._subprocess_working_dir = str(Path(script_path).parent) # 工作目录设置为脚本所在目录
76+
6477
def run_packaging_process(self) -> None:
6578
"""
6679
使用给定的参数启动打包子进程 \n
6780
"""
6881

82+
self.subprocess.set_working_dir(self._subprocess_working_dir)
6983
self.subprocess.set_arguments(self._args)
7084
self.subprocess.start_process()

0 commit comments

Comments
 (0)