7
7
import subprocess
8
8
import chardet
9
9
from pathlib import Path
10
- from typing import Optional , Callable , Any
10
+ from typing import Optional , Callable , Any , Iterable
11
11
12
12
13
13
def delete_source (root_path : Path , * ,
@@ -51,10 +51,9 @@ def _delete_source(p: Path) -> None:
51
51
print (f"rmtree { p } get error { str (e )} " )
52
52
else :
53
53
# 文件夹-继续遍历
54
+ iterdir : Iterable [Path ] = p .iterdir ()
54
55
if dir_iter_filter :
55
56
iterdir = filter (dir_iter_filter , p .iterdir ())
56
- else :
57
- iterdir = p .iterdir ()
58
57
for child_path in iterdir :
59
58
_delete_source (child_path )
60
59
if any ([callable (file_predication ), callable (dir_predication )]):
@@ -126,11 +125,14 @@ def pyzpacker(source: str, main: str, *, output: Optional[str] = None, with_requ
126
125
print (f"""命令: { command } 执行失败""" )
127
126
if ce .stderr :
128
127
encoding = chardet .detect (ce .stderr ).get ("encoding" )
129
- content = ce .stderr .decode (encoding ).strip ()
128
+ if encoding :
129
+ content = ce .stderr .decode (encoding ).strip ()
130
+ print (content )
130
131
else :
131
132
encoding = chardet .detect (ce .stdout ).get ("encoding" )
132
- content = ce .stdout .decode (encoding ).strip ()
133
- print (content )
133
+ if encoding :
134
+ content = ce .stdout .decode (encoding ).strip ()
135
+ print (content )
134
136
raise ce
135
137
except Exception as e :
136
138
print (f"""命令: { command } 执行失败""" )
@@ -139,8 +141,9 @@ def pyzpacker(source: str, main: str, *, output: Optional[str] = None, with_requ
139
141
content = ""
140
142
if res .stdout :
141
143
encoding = chardet .detect (res .stdout ).get ("encoding" )
142
- content = res .stdout .decode (encoding ).strip ()
143
- print (content )
144
+ if encoding :
145
+ content = res .stdout .decode (encoding ).strip ()
146
+ print (content )
144
147
target = output_dir .joinpath (f"{ pyz_name } .pyz" )
145
148
zipapp .create_archive (
146
149
temp_path ,
0 commit comments