From 7ffa0ba22b116ea4dbf66640337b909d97fa024f Mon Sep 17 00:00:00 2001 From: nyanpasu64 Date: Mon, 14 Jan 2019 19:19:15 -0800 Subject: [PATCH] [appveyor] Append version number to .zip artifacts --- appveyor.yml | 1 - corrscope.spec | 35 +++++++++++++++++++++++++++-------- corrscope/version.py | 11 ++++++++--- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index e64c6b4..f6eb7b4 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -56,4 +56,3 @@ after_test: artifacts: - path: 'dist\*' - - path: 'dist\corrscope' diff --git a/corrscope.spec b/corrscope.spec index 1002259..e882ab0 100644 --- a/corrscope.spec +++ b/corrscope.spec @@ -1,10 +1,12 @@ import glob +import zipfile +from pathlib import Path from PyInstaller.building.api import PYZ, EXE, COLLECT from PyInstaller.building.build_main import Analysis from PyInstaller.building.datastruct import TOC -from corrscope import version +from corrscope import version as v block_cipher = None @@ -18,8 +20,11 @@ def keep(dir, wildcard): datas = keep("corrscope/gui", "*.ui") + keep("corrscope/path", "*") -version.pyinstaller_write_version() -datas.append((version.version_txt, ".")) +version = v.pyinstaller_write_version() +datas.append((v.version_txt, ".")) + +app_name = "corrscope" +app_name_version = f"{app_name}-{version}" a = Analysis( ["corrscope/__main__.py"], @@ -38,7 +43,7 @@ a = Analysis( # Some dirs are included by PyInstaller hooks and must be removed after the fact. -path_excludes = ( +_path_excludes = ( # Matplotlib """ mpl-data/fonts @@ -59,7 +64,7 @@ path_excludes = ( libEGL.dll libGLESv2.dll d3dcompiler_ opengl32sw.dll """ ).split() -path_excludes = {s.lower() for s in path_excludes} +path_excludes = {s.lower() for s in _path_excludes} def path_contains(path: str) -> bool: @@ -89,13 +94,27 @@ exe = EXE( a.scripts, [], exclude_binaries=True, - name="corrscope", + name=app_name, debug=False, bootloader_ignore_signals=False, strip=False, upx=True, console=True, ) -coll = COLLECT( - exe, a.binaries, a.zipfiles, a.datas, strip=False, upx=True, name="corrscope" + +class ZipCollect(COLLECT): + name: str # absolute-ish path, != __init__(name=) + + def assemble(self): + ret = super().assemble() + + new_name = str(Path(self.name).with_name(app_name_version)) + with zipfile.ZipFile(new_name + '.zip', 'w', zipfile.ZIP_DEFLATED) as z: + z.write(self.name) + + return ret + + +coll = ZipCollect( + exe, a.binaries, a.zipfiles, a.datas, strip=False, upx=True, name=app_name ) diff --git a/corrscope/version.py b/corrscope/version.py index d4cfb2c..d070e00 100644 --- a/corrscope/version.py +++ b/corrscope/version.py @@ -40,19 +40,24 @@ def get_version() -> str: return base_version -def pyinstaller_write_version(): - """ Called only at pyinstaller time. +def pyinstaller_write_version() -> str: + """ Returns version. + + Called only at pyinstaller time. Writes to filesystem, does NOT call get_version(). Filesystem is ignored if version number isn't prerelease (x.y.z-pre). """ build_metadata = _calc_metadata() + version = _base_plus_metadata(build_metadata) with version_txt.open("w") as txt: - txt.write(_base_plus_metadata(build_metadata)) + txt.write(version) with version_py.open("w") as f: f.write(f"{metadata_key} = {repr(build_metadata)}") + return version + # Compute version suffix env = {}