Skip to content

Commit c08577d

Browse files
committed
update
1 parent 3edeba0 commit c08577d

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

pyzpacker/pyzpacker.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import subprocess
88
import chardet
99
from pathlib import Path
10-
from typing import Optional, Callable, Any
10+
from typing import Optional, Callable, Any, Iterable
1111

1212

1313
def delete_source(root_path: Path, *,
@@ -51,10 +51,9 @@ def _delete_source(p: Path) -> None:
5151
print(f"rmtree {p} get error {str(e)}")
5252
else:
5353
# 文件夹-继续遍历
54+
iterdir: Iterable[Path] = p.iterdir()
5455
if dir_iter_filter:
5556
iterdir = filter(dir_iter_filter, p.iterdir())
56-
else:
57-
iterdir = p.iterdir()
5857
for child_path in iterdir:
5958
_delete_source(child_path)
6059
if any([callable(file_predication), callable(dir_predication)]):
@@ -126,11 +125,14 @@ def pyzpacker(source: str, main: str, *, output: Optional[str] = None, with_requ
126125
print(f"""命令: {command} 执行失败""")
127126
if ce.stderr:
128127
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)
130131
else:
131132
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)
134136
raise ce
135137
except Exception as e:
136138
print(f"""命令: {command} 执行失败""")
@@ -139,8 +141,9 @@ def pyzpacker(source: str, main: str, *, output: Optional[str] = None, with_requ
139141
content = ""
140142
if res.stdout:
141143
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)
144147
target = output_dir.joinpath(f"{pyz_name}.pyz")
145148
zipapp.create_archive(
146149
temp_path,

0 commit comments

Comments
 (0)