Skip to content

Commit

Permalink
Use new pyinstaller pathing and remove onefile flags
Browse files Browse the repository at this point in the history
+ macfix
  • Loading branch information
Dpeta committed May 29, 2024
1 parent 67a2dd4 commit cdf68cb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 89 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Install PyInstaller
run: python -m pip install --upgrade PyInstaller
- name: Run pyinst.py
run: python3 pyinst.py --no-prompts --onefile --no-upx --no-crt --no-clean --windowed
run: python3 pyinst.py --no-prompts --no-upx --no-crt --no-clean --windowed
- name: Create archive (.tar.xz)
run: tar -cavf Pesterchum_linux64.tar.xz -C dist Pesterchum
- uses: actions/upload-artifact@v3
Expand All @@ -47,7 +47,7 @@ jobs:
- name: Install PyInstaller
run: python -m pip install --upgrade PyInstaller
- name: Run PyInstaller
run: python3 pyinst.py --no-prompts --onefile --no-upx --crt --no-clean --windowed
run: python3 pyinst.py --no-prompts --no-upx --crt --no-clean --windowed
- name: Create archive (.zip)
run: tar.exe -a -c -f Pesterchum_win64_py311.zip -C dist Pesterchum
- uses: actions/upload-artifact@v3
Expand All @@ -73,7 +73,7 @@ jobs:
- name: Install PyInstaller
run: python -m pip install --upgrade PyInstaller
- name: Run PyInstaller
run: python3 pyinst.py --prompts False --onefile True --upx False --crt True --clean False --windowed True
run: python3 pyinst.py --prompts False True --upx False --crt True --clean False --windowed True
- name: Create archive (.zip)
run: tar.exe -a -c -f Pesterchum_win32_py38.zip -C dist Pesterchum
- uses: actions/upload-artifact@v3
Expand All @@ -99,7 +99,7 @@ jobs:
- name: Install PyInstaller
run: python -m pip install --upgrade PyInstaller
- name: Run pyinst.py
run: python3 pyinst.py --no-prompts --onefile --no-upx --no-crt --no-clean --windowed
run: python3 pyinst.py --no-prompts --no-upx --no-crt --no-clean --windowed
- name: Create archive (.tar.xz)
run: tar -cavf Pesterchum_macOS64.tar.xz -C dist Pesterchum.app
- uses: actions/upload-artifact@v3
Expand Down
110 changes: 25 additions & 85 deletions pyinst.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
is_64bit = sys.maxsize > 2**32
# is_linux = sys.platform.startswith("linux")
exclude_modules = []

add_data = [
"quirks;quirks",
"smilies;smilies",
Expand Down Expand Up @@ -36,6 +37,7 @@
"LICENSE": "LICENSE.txt",
"CHANGELOG.md": "CHANGELOG.md",
}

# Some of these might not be required anymore,
# newer versions of PyInstaller claim to exclude certain problematic DDLs automatically.
upx_exclude = [
Expand Down Expand Up @@ -95,7 +97,6 @@
delete_builddist = ""
upx_enabled = ""
package_universal_crt = ""
onefile = ""
windowed = ""
upx_dir = ""
crt_path = ""
Expand All @@ -114,11 +115,6 @@
help="Prompt for the options below on run",
action=argparse.BooleanOptionalAction,
)
parser.add_argument(
"--onefile",
help="Create a one-file bundled executable.",
action=argparse.BooleanOptionalAction,
)
parser.add_argument(
"--upx",
help="Try to compress binaries with UPX.",
Expand Down Expand Up @@ -155,11 +151,6 @@
elif _ARGUMENTS.crt is False:
package_universal_crt = "n"

if _ARGUMENTS.onefile:
onefile = "y"
elif _ARGUMENTS.onefile is False:
onefile = "n"

if _ARGUMENTS.windowed:
windowed = "y"
elif _ARGUMENTS.windowed is False:
Expand All @@ -172,12 +163,6 @@
action="store",
choices=["True", "False"],
)
parser.add_argument(
"--onefile",
help="Create a one-file bundled executable.",
action="store",
choices=["True", "False"],
)
parser.add_argument(
"--upx",
help="Try to compress binaries with UPX.",
Expand Down Expand Up @@ -215,10 +200,6 @@
package_universal_crt = "y"
elif _ARGUMENTS.crt == "False":
package_universal_crt = "n"
if _ARGUMENTS.onefile == "True":
onefile = "y"
elif _ARGUMENTS.onefile == "False":
onefile = "n"
if _ARGUMENTS.windowed == "True":
windowed = "y"
elif _ARGUMENTS.windowed == "False":
Expand Down Expand Up @@ -296,10 +277,6 @@
)
print("crt_path = " + crt_path)

if sys.platform in ("win32", "linux"):
while onefile not in ("y", "n"):
onefile = input("Build with '--onefile'? (Y/N): ").lower()

except KeyboardInterrupt:
sys.exit("KeyboardInterrupt")
else:
Expand Down Expand Up @@ -333,8 +310,6 @@
)
print("crt_path = " + crt_path)
package_universal_crt = "y"
if _ARGUMENTS.onefile is None:
onefile = "y"
if _ARGUMENTS.windowed is None:
windowed = "y"

Expand Down Expand Up @@ -374,11 +349,6 @@
run_win32.append("--exclude-module=%s" % x)
if windowed == "y":
run_win32.append("--windowed")
if onefile == "y":
run_win32.append("--onefile")
elif onefile == "n":
for x in add_data:
run_win32.append("--add-data=%s" % x)

if package_universal_crt == "y":
run_win32.append("--paths=%s" % crt_path)
Expand Down Expand Up @@ -657,28 +627,17 @@
print(run_win32)
PyInstaller.__main__.run(run_win32)

if onefile == "y":
# There's more proper ways to do this, but this doesn't require changing our paths
for x in data_folders:
print(x)
shutil.copytree(
x,
os.path.join("dist", data_folders[x]),
ignore=shutil.ignore_patterns(
"*.psd", "*.xcf*", "ebg2.png", "ebg1.png"
),
)
for x in data_files:
print(x)
shutil.copy(x, os.path.join("dist", data_files[x]))

files = os.listdir("dist")
try:
os.mkdir(os.path.join("dist", "Pesterchum"))
except FileExistsError:
pass
for x in files:
shutil.move(os.path.join("dist", x), os.path.join("dist", "Pesterchum"))
# There's more proper ways to do this, but this doesn't require changing our paths
for x in data_folders:
print(x)
shutil.copytree(
x,
os.path.join("dist", "Pesterchum", data_folders[x]),
ignore=shutil.ignore_patterns("*.psd", "*.xcf*", "ebg2.png", "ebg1.png"),
)
for x in data_files:
print(x)
shutil.copy(x, os.path.join("dist", "Pesterchum", data_files[x]))

# shutil.copy(os.path.join('build', 'Pesterchum', 'xref-Pesterchum.html'),
# os.path.join('dist', 'Pesterchum', 'xref-Pesterchum.html'))
Expand Down Expand Up @@ -740,43 +699,24 @@
run_linux.append("--noupx")
for x in exclude_modules:
run_linux.append("--exclude-module=%s" % x)
if onefile == "y":
run_linux.append("--onefile")
elif onefile == "n":
for x in add_data:
run_linux.append("--add-data=%s" % x.replace(";", ":"))
if windowed == "y":
run_linux.append("--windowed")

print(run_linux)
PyInstaller.__main__.run(run_linux)

if onefile == "y":
# There's more proper ways to do this, but this doesn't require changing our paths
for x in data_folders:
print(x)
shutil.copytree(
x,
os.path.join("dist", data_folders[x]),
ignore=shutil.ignore_patterns(
"*.psd", "*.xcf*", "ebg2.png", "ebg1.png"
),
)
for x in data_files_linux:
print(x)
shutil.copy(x, os.path.join("dist", data_files_linux[x]))

files = os.listdir("dist")
try:
os.mkdir(os.path.join("dist", ".cache"))
except FileExistsError as e:
print(e)
for x in files:
try:
shutil.move(os.path.join("dist", x), os.path.join("dist", ".cache", x))
except FileExistsError as e:
print(e)
shutil.move(os.path.join("dist", ".cache"), os.path.join("dist", "Pesterchum"))
# There's more proper ways to do this, but this doesn't require changing our paths
for x in data_folders:
print(x)
shutil.copytree(
x,
os.path.join("dist", "Pesterchum", data_folders[x]),
ignore=shutil.ignore_patterns("*.psd", "*.xcf*", "ebg2.png", "ebg1.png"),
)
for x in data_files_linux:
print(x)
shutil.copy(x, os.path.join("dist", "Pesterchum", data_files_linux[x]))

# shutil.copy(os.path.join('build', 'Pesterchum', 'xref-Pesterchum.html'),
# os.path.join('dist', 'Pesterchum', 'xref-Pesterchum.html'))
# shutil.copy(os.path.join('build', 'Pesterchum', 'Analysis-00.toc'),
Expand Down

0 comments on commit cdf68cb

Please sign in to comment.