From 601f5becc851d886307ef72a247c4c384bfa7d06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Mon, 27 May 2024 21:37:01 +0200 Subject: [PATCH] [version] add __variant__ Specifies origin and OS of executable files. For example 'stable/windows'. --- .github/workflows/executables.yml | 10 ++++++++-- gallery_dl/__init__.py | 2 +- gallery_dl/version.py | 1 + scripts/pyinstaller.py | 27 +++++++++++++++++++++------ scripts/release.sh | 10 ++++++++-- 5 files changed, 39 insertions(+), 11 deletions(-) diff --git a/.github/workflows/executables.yml b/.github/workflows/executables.yml index b6d3c829..ac88e3e0 100644 --- a/.github/workflows/executables.yml +++ b/.github/workflows/executables.yml @@ -42,7 +42,9 @@ jobs: architecture: ${{ matrix.architecture }} - name: Date - run: echo "DATE=$(date '+${{ env.DATE_FORMAT }}')" >> "$GITHUB_ENV" + run: | + echo "DATE=$(date '+${{ env.DATE_FORMAT }}')" >> "$GITHUB_ENV" + echo "LABEL=$(python ./scripts/pyinstaller.py --print --os '${{ matrix.os }}' --arch '${{ matrix.architecture }}')" >> "$GITHUB_ENV" - name: Update Version # use Python since its behavior is consistent across operating systems @@ -56,13 +58,17 @@ jobs: r'\b(__version__ = "[^"]+)', r"\1:${{ env.DATE }}", content) + content = re.sub( + r'\b(__variant__ =).+', + r'\1 "dev/${{ env.LABEL }}"', + content) with open(path, "w") as fp: fp.write(content) - name: Build executable run: | pip install requests requests[socks] yt-dlp pyyaml ${{ matrix.python-packages }} pyinstaller - python ./scripts/pyinstaller.py --os '${{ matrix.os }}' --arch '${{ matrix.architecture }}' + python ./scripts/pyinstaller.py --label '${{ env.LABEL }}' - uses: actions/upload-artifact@v4 with: diff --git a/gallery_dl/__init__.py b/gallery_dl/__init__.py index 7ca405aa..bb4cafbe 100644 --- a/gallery_dl/__init__.py +++ b/gallery_dl/__init__.py @@ -127,7 +127,7 @@ def main(): extra = "" if util.EXECUTABLE: - extra = " - Executable" + extra = " - Executable ({})".format(version.__variant__) else: git_head = util.git_head() if git_head: diff --git a/gallery_dl/version.py b/gallery_dl/version.py index ab8df335..9c54d099 100644 --- a/gallery_dl/version.py +++ b/gallery_dl/version.py @@ -7,3 +7,4 @@ # published by the Free Software Foundation. __version__ = "1.27.0-dev" +__variant__ = None diff --git a/scripts/pyinstaller.py b/scripts/pyinstaller.py index ee22ecad..58303547 100755 --- a/scripts/pyinstaller.py +++ b/scripts/pyinstaller.py @@ -3,7 +3,6 @@ """Build a standalone executable using PyInstaller""" -import PyInstaller.__main__ import argparse import util import sys @@ -13,18 +12,34 @@ def main(): parser = argparse.ArgumentParser() parser.add_argument("-o", "--os") parser.add_argument("-a", "--arch") + parser.add_argument("-l", "--label") parser.add_argument("-e", "--extension") + parser.add_argument("-p", "--print", action="store_true") args = parser.parse_args() + if args.label: + label = args.label + else: + label = "" + if args.os: + os = args.os.partition("-")[0].lower() + if os == "ubuntu": + os = "linux" + label += os + if args.arch == "x86": + label += "_x86" + + if args.print: + return print(label) + name = "gallery-dl" - if args.os: - name = "{}_{}".format(name, args.os.partition("-")[0].lower()) - if args.arch == "x86": - name += "_x86" + if label: + name = "{}_{}".format(name, label) if args.extension: name = "{}.{}".format(name, args.extension.lower()) - PyInstaller.__main__.run([ + import PyInstaller.__main__ + return PyInstaller.__main__.run([ "--onefile", "--console", "--name", name, diff --git a/scripts/release.sh b/scripts/release.sh index 3685500b..13608e9c 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -53,19 +53,20 @@ build-linux() { cd "${ROOTDIR}" echo Building Linux executable - build-vm 'ubuntu22.04' 'gallery-dl.bin' + build-vm 'ubuntu22.04' 'gallery-dl.bin' 'linux' } build-windows() { cd "${ROOTDIR}" echo Building Windows executable - build-vm 'windows7_x86_sp1' 'gallery-dl.exe' + build-vm 'windows7_x86_sp1' 'gallery-dl.exe' 'windows' } build-vm() { VMNAME="$1" BINNAME="$2" + LABEL="$3" TMPPATH="/tmp/gallery-dl/dist/$BINNAME" # launch VM @@ -77,6 +78,11 @@ build-vm() { cp -a -t /tmp/gallery-dl -- \ ./gallery_dl ./scripts ./data ./setup.py ./README.rst + # update __variant__ + sed -i \ + -e "s#\(__variant__ *=\).*#\1 \"stable/${LABEL}\"#" \ + /tmp/gallery-dl/gallery_dl/version.py + # remove old executable rm -f "./dist/$BINNAME"