Skip to content

Commit

Permalink
fix #34 windows打包错误问题
Browse files Browse the repository at this point in the history
  • Loading branch information
zy7y committed Apr 28, 2024
1 parent 7e21b5c commit 622a03f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
34 changes: 29 additions & 5 deletions .github/workflows/build.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import os.path
import platform
import subprocess

import pymysql
import yapf_third_party
from PyInstaller import __main__ as pyi

CLIENT_PY = "dfs_generate/client.py"


def build_web():
subprocess.run("npm i", cwd="web", shell=True)
Expand All @@ -15,6 +19,14 @@ def gen_client_py():
import random
import socket
import threading
import sys
monkey_patch = type('MonkeyPatchSys', (object,), {'write': lambda self, *args, **kwargs: None})
if sys.stderr is None:
sys.stderr = monkey_patch()
if sys.stdout is None:
sys.stdout = monkey_patch()
from dfs_generate.server import app
Expand Down Expand Up @@ -46,24 +58,33 @@ def desktop_client():
if __name__ == '__main__':
desktop_client()
"""
with open("dfs_generate/client.py", "w", encoding="utf-8") as f:
with open(CLIENT_PY, "w", encoding="utf-8") as f:
f.write(code)


build_web()
# build_web()
gen_client_py()


def get_pyinstaller_add_data_by_package(name):
return f'{name.__file__.replace("__init__.py", "")}:{name.__name__}'


params = [
"--windowed",
"--onefile",
"--add-data",
"web/dist:web/dist",
"dfs_generate/*:.",
"--add-data",
get_pyinstaller_add_data_by_package(pymysql),
"--add-data",
get_pyinstaller_add_data_by_package(yapf_third_party),
"--add-data",
f'{yapf_third_party.__file__.replace("__init__.py", "")}:yapf_third_party',
"web/dist:web/dist",
"--clean",
"--noconfirm",
"--name=client",
"dfs_generate/client.py",
CLIENT_PY,
]

pyi.run(params)
Expand All @@ -77,3 +98,6 @@ def desktop_client():
# 删除空目录
rm_cmds = ["rm", "-rf", "dist/client"]
subprocess.call(rm_cmds)

if os.path.isfile(CLIENT_PY):
os.remove(CLIENT_PY)
2 changes: 1 addition & 1 deletion .github/workflows/build_client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ windows-latest, macos-latest ]
os: [ windows-latest, macos-latest, ubuntu-latest ]
steps:
- name: 拉代码
uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions dfs_generate/conversion.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from string import Template

from dfs_generate.templates import (
from templates import (
SQLMODEL_DAO,
TORTOISE_DAO,
RESPONSE_SCHEMA,
Expand All @@ -10,7 +10,7 @@
TORTOISE_ROUTER,
SQLMODEL_DB,
)
from dfs_generate.tools import to_pascal, tran, to_snake
from tools import to_pascal, tran, to_snake


def _pydantic_field(column, imports):
Expand Down
5 changes: 2 additions & 3 deletions dfs_generate/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import isort
from yapf.yapflib.yapf_api import FormatCode

from dfs_generate.conversion import SQLModelConversion, TortoiseConversion
from dfs_generate.tools import MySQLConf, MySQLHelper
from conversion import SQLModelConversion, TortoiseConversion
from tools import MySQLConf, MySQLHelper

app = bottle.Bottle()

Expand All @@ -16,7 +16,6 @@
static_file_abspath = os.path.join(
os.path.dirname(os.path.dirname(__file__)), "web", "dist"
)
print(static_file_abspath)


@app.hook("before_request")
Expand Down
2 changes: 1 addition & 1 deletion dfs_generate/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pymysql

from dfs_generate.types_map import TYPES
from types_map import TYPES


def tran(t, mode) -> dict:
Expand Down

0 comments on commit 622a03f

Please sign in to comment.