Switch to tar.gz and dmg archives to reduce space

This commit is contained in:
Timmy Welch 2023-12-25 22:16:18 -08:00
parent db00736f58
commit 231b600a0e
5 changed files with 96 additions and 27 deletions

View File

@ -88,6 +88,8 @@ jobs:
name: "${{ format('ComicTagger-{0}', runner.os) }}"
path: |
dist/*.zip
dist/*.tar.gz
dist/*.dmg
dist/*.AppImage
- name: PyTest

View File

@ -70,5 +70,7 @@ jobs:
# upload the single application zip file for each OS and include the wheel built on linux
files: |
dist/*.zip
dist/*.tar.gz
dist/*.dmg
dist/*${{ fromJSON('["never", ""]')[runner.os == 'Linux'] }}.whl
dist/*.AppImage

24
build-tools/dmgbuild.conf Normal file
View File

@ -0,0 +1,24 @@
import pathlib
import platform
from comictaggerlib.ctversion import __version__
app = "ComicTagger"
exe = app.casefold()
ver = platform.mac_ver()
os_version = f"osx-{ver[0]}-{ver[2]}"
app_name = f"{app}.app"
final_name = f"{app}-{__version__}-{os_version}"
path = pathlib.Path(f"dist/{app_name}")
zip_file = pathlib.Path(f"dist/{final_name}.zip")
format = 'ULMO'
files = (str(path),)
symlinks = {'Applications': '/Applications'}
icon = pathlib.Path().cwd() / 'build-tools' / 'mac' / 'volume.icns'
icon_locations = {
app_name: (100, 100),
'Applications': (300, 100)
}

View File

@ -3,28 +3,13 @@ from __future__ import annotations
import os
import pathlib
import platform
import runpy
import sys
import tarfile
import zipfile
from comictaggerlib.ctversion import __version__
app = "ComicTagger"
exe = app.casefold()
if platform.system() == "Windows":
os_version = f"win-{platform.machine()}"
app_name = f"{exe}.exe"
final_name = f"{app}-{__version__}-{os_version}.exe"
elif platform.system() == "Darwin":
ver = platform.mac_ver()
os_version = f"osx-{ver[0]}-{ver[2]}"
app_name = f"{app}.app"
final_name = f"{app}-{__version__}-{os_version}.app"
else:
app_name = exe
final_name = f"ComicTagger-{__version__}-{platform.system()}"
path = f"dist/{app_name}"
zip_file = pathlib.Path(f"dist/{final_name}.zip")
def addToZip(zf: zipfile.ZipFile, path: str, zippath: str) -> None:
if os.path.isfile(path):
@ -34,14 +19,69 @@ def addToZip(zf: zipfile.ZipFile, path: str, zippath: str) -> None:
zf.write(path, zippath)
for nm in sorted(os.listdir(path)):
addToZip(zf, os.path.join(path, nm), os.path.join(zippath, nm))
# else: ignore
zip_file.unlink(missing_ok=True)
with zipfile.ZipFile(zip_file, "w", compression=zipfile.ZIP_DEFLATED, compresslevel=8) as zf:
zippath = os.path.basename(path)
if not zippath:
zippath = os.path.basename(os.path.dirname(path))
if zippath in ("", os.curdir, os.pardir):
zippath = ""
addToZip(zf, path, zippath)
def Zip(zip_file: pathlib.Path, path: pathlib.Path) -> None:
zip_file.unlink(missing_ok=True)
with zipfile.ZipFile(f"{zip_file}.zip", "w", compression=zipfile.ZIP_DEFLATED, compresslevel=8) as zf:
zippath = os.path.basename(path)
if not zippath:
zippath = os.path.basename(os.path.dirname(path))
if zippath in ("", os.curdir, os.pardir):
zippath = ""
addToZip(zf, str(path), zippath)
def addToTar(tf: tarfile.TarFile, path: str, zippath: str) -> None:
if os.path.isfile(path):
tf.add(path, zippath)
elif os.path.isdir(path):
if zippath:
tf.add(path, zippath, recursive=False)
for nm in sorted(os.listdir(path)):
addToTar(tf, os.path.join(path, nm), os.path.join(zippath, nm))
def Tar(tar_file: pathlib.Path, path: pathlib.Path) -> None:
tar_file.unlink(missing_ok=True)
with tarfile.TarFile(f"{tar_file}.tar.gz", "w:gz") as tf: # type: ignore[arg-type]
zippath = os.path.basename(path)
if not zippath:
zippath = os.path.basename(os.path.dirname(path))
if zippath in ("", os.curdir, os.pardir):
zippath = ""
addToTar(tf, str(path), zippath)
if __name__ == "__main__":
app = "ComicTagger"
exe = app.casefold()
if platform.system() == "Windows":
os_version = f"win-{platform.machine()}"
app_name = f"{exe}.exe"
final_name = f"{app}-{__version__}-{os_version}.exe"
elif platform.system() == "Darwin":
ver = platform.mac_ver()
os_version = f"osx-{ver[0]}-{ver[2]}"
app_name = f"{app}.app"
final_name = f"{app}-{__version__}-{os_version}"
else:
app_name = exe
final_name = f"ComicTagger-{__version__}-{platform.system()}"
path = pathlib.Path(f"dist/{app_name}")
zip_file = pathlib.Path(f"dist/{final_name}")
if platform.system() == "Darwin":
sys.argv = [
"zip_artifacts",
"-s",
str(pathlib.Path(__file__).parent / "dmgbuild.conf"),
f"{app} {__version__}",
f"{final_name}.dmg",
]
runpy.run_module("dmgbuild", alter_sys=True)
elif platform.system() == "Windows":
Zip(zip_file, path)
else:
Tar(zip_file, path)

View File

@ -234,6 +234,7 @@ depends =
pypi-upload
deps =
pyinstaller>=5.6.2,!=6.0.0
dmgbuild
extras =
all
commands =