publish test

This commit is contained in:
xaoyo 2023-11-28 18:15:59 +08:00
parent 9fb59d08f8
commit 142dd30bc2
2 changed files with 68 additions and 4 deletions

View File

@ -39,7 +39,7 @@ jobs:
- name: Build Executable
run: |
pyinstaller --onefile --clean --add-data "${{ github.workspace }}/pywxdump/version_list.json;pywxdump" --add-data "${{ github.workspace }}/pywxdump/show_chat/templates/chat.html;pywxdump/show_chat/templates" --add-data "${{ github.workspace }}/pywxdump/show_chat/templates/index.html;pywxdump/show_chat/templates" --distpath=dist --name=pywxdump dist/tmp.py
pyinstaller --clean --distpath=dist tests/dist/pywxdump.spec
- name: test
run: |

View File

@ -9,7 +9,58 @@ import site
import os
code = """from pywxdump.command import console_run;console_run()"""
spec_content = '''
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['tmp.py'],
pathex=[],
binaries=[],
datas=[(r'{root_path}\\version_list.json', 'pywxdump'),
(r'{root_path}/show_chat/templates/chat.html', 'pywxdump/show_chat/templates'),
(r'{root_path}/show_chat/templates/index.html', 'pywxdump/show_chat/templates')],
hiddenimports={hidden_imports},
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='pywxdump',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True, # 启用压缩
console=True, # 使用控制台
disable_windowed_traceback=True, # 不禁用堆栈跟踪
argv_emulation=False, # 不模拟命令行参数
target_arch=None, # 自动检测目标 CPU 架构
codesign_identity=None, # 不签名应用程序
entitlements_file=None, # 不使用 entitlements 文件
onefile=True, # 生成单个可执行文件
)
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='pywxdump')
'''
# 创建文件夹
os.makedirs("dist", exist_ok=True)
# 将代码写入文件
@ -20,12 +71,25 @@ with open("dist/tmp.py", "w", encoding="utf-8") as f:
package_path = site.getsitepackages()
if package_path:
package_path = package_path[1] # 假设取第一个安装包的路径
version_list_path = os.path.join(package_path,'pywxdump', 'version_list.json')
root_path = os.path.join(package_path, 'pywxdump')
require_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "requirements.txt")
print(require_path)
# 读取依赖
with open(require_path, "r", encoding="utf-8") as f:
hidden_imports = f.read().splitlines()
# 去掉setuptools、wheel
hidden_imports = [i for i in hidden_imports if i not in ["setuptools", "wheel"]]
# 生成 spec 文件
spec_content = spec_content.format(root_path=root_path, hidden_imports=hidden_imports)
spec_file = os.path.join("dist", "pywxdump.spec")
with open(spec_file, 'w') as f:
f.write(spec_content.strip())
# 执行打包命令
cmd = f'pyinstaller --onefile --clean --add-data "{version_list_path};pywxdump" --distpath=dist --workpath=build --specpath=build --name=pywxdump dist/tmp.py'
cmd = f'pyinstaller --clean --distpath=dist {spec_file}'
print(cmd)
os.system(cmd)
# os.system(cmd)
else:
print("未找到安装包路径")