Skip to content

Commit

Permalink
packaging: build CLI as portable binary too (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts authored Mar 20, 2024
2 parents 84fbb5f + ce1facd commit 5d77620
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 25 deletions.
66 changes: 46 additions & 20 deletions .github/workflows/builder_releaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,27 @@ jobs:
python -m pip install -e .[gdal]
python -m pip install -U -r requirements/packaging.txt
- name: Generates Executable
run: python -O ./builder/pyinstaller_build_ubuntu.py
- name: Generates executable for command-line version
run: |
python -O ./builder/pyinstaller_build_ubuntu_cli.py
- name: Save CLI binary as artifact
uses: actions/upload-artifact@v4
with:
name: DicoGIS_executable_ubuntu_CLI
path: dist/DicoGIS-cli_*
if-no-files-found: error

- name: Compress into ZIP
- name: Generates executable for graphical version
run: |
cd dist/
zip -r9 DicoGIS_Ubuntu . DicoGIS_*/*
python -O ./builder/pyinstaller_build_ubuntu_gui.py
- name: Save it as artifact
uses: actions/upload-artifact@v4
with:
name: DicoGIS_executable_Ubuntu
name: DicoGIS_executable_ubuntu_GUI
path: |
dist/DicoGIS_*.zip
dist/DicoGIS-gui_*
if-no-files-found: error

build-windows:
Expand Down Expand Up @@ -116,20 +123,27 @@ jobs:
- name: Generates MS Version Info
run: python .\builder\version_info_templater.py

- name: Generates MS Executable
run: python -O .\builder\pyinstaller_build_windows.py
- name: Generates executable for command-line version
run: |
python -O ./builder/pyinstaller_build_windows_cli.py
- name: Save CLI binary as artifact
uses: actions/upload-artifact@v4
with:
name: DicoGIS_executable_windows_CLI
path: dist/DicoGIS-cli_*
if-no-files-found: error

- name: Compress into ZIP
- name: Generates executable for graphical version
run: |
cd dist/
7z a DicoGIS_Windows.zip ./DicoGIS_*/*
python -O ./builder/pyinstaller_build_windows_gui.py
- name: Save it as artifact
uses: actions/upload-artifact@v4
with:
name: DicoGIS_executable_Windows
name: DicoGIS_executable_windows_GUI
path: |
dist/DicoGIS_*.zip
dist/DicoGIS-gui_*
if-no-files-found: error

release:
Expand All @@ -145,17 +159,29 @@ jobs:
if: startsWith(github.ref, 'refs/tags/')

steps:
- name: Download built package for Linux (Ubuntu)
- name: Download built package for Linux (Ubuntu) - GUI
uses: actions/download-artifact@v4
with:
name: DicoGIS_executable_ubuntu_GUI
path: builds/ubuntu/gui/

- name: Download built package for Linux (Ubuntu) - CLI
uses: actions/download-artifact@v4
with:
name: DicoGIS_executable_ubuntu_CLI
path: builds/ubuntu/cli/

- name: Download built package for Windows - GUI
uses: actions/download-artifact@v4
with:
name: DicoGIS_executable_Ubuntu
path: builds/ubuntu/
name: DicoGIS_executable_windows_GUI
path: builds/windows/gui

- name: Download built package for Windows
- name: Download built package for Windows - CLI
uses: actions/download-artifact@v4
with:
name: DicoGIS_executable_Windows
path: builds/windows/
name: DicoGIS_executable_windows_CLI
path: builds/windows/cli

- name: Release
uses: softprops/action-gh-release@v1
Expand Down
53 changes: 53 additions & 0 deletions builder/pyinstaller_build_ubuntu_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#! python3 # noqa: E265

"""
Launch PyInstaller using a Python script.
"""

# #############################################################################
# ########## Libraries #############
# ##################################

import platform
import sys

# Standard library
from os import getenv
from pathlib import Path

# 3rd party
import distro
import PyInstaller.__main__

# package
sys.path.insert(0, str(Path(".").resolve()))
from dicogis import __about__ # noqa: E402

# #############################################################################
# ########### MAIN #################
# ##################################
package_folder = Path("dicogis")

PyInstaller.__main__.run(
[
"--add-binary={}:bin/img/".format((package_folder / "bin/img/").resolve()),
"--add-data={}:locale/".format((package_folder / "locale/").resolve()),
"--add-data=options_TPL.ini:.",
"--add-data=LICENSE:.",
"--add-data=README.md:.",
"--collect-submodules=shellingham",
"--console",
"--log-level={}".format(getenv("PYINSTALLER_LOG_LEVEL", "WARN")),
"--name={}-cli_{}_{}{}_{}_Python{}".format(
__about__.__title_clean__,
__about__.__version__,
distro.id(),
distro.version(),
platform.architecture()[0],
platform.python_version(),
).replace(".", "-"),
"--noconfirm",
"--onefile",
str(package_folder.joinpath("cli/main.py")),
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"--add-data=LICENSE:.",
"--add-data=README.md:.",
"--log-level={}".format(getenv("PYINSTALLER_LOG_LEVEL", "WARN")),
"--name={}_{}_{}{}_{}_Python{}".format(
"--name={}-gui_{}_{}{}_{}_Python{}".format(
__about__.__title_clean__,
__about__.__version__,
distro.id(),
Expand Down
56 changes: 56 additions & 0 deletions builder/pyinstaller_build_windows_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#! python3 # noqa: E265

"""
Launch PyInstaller using a Python script.
"""

# #############################################################################
# ########## Libraries #############
# ##################################

import platform
import sys

# Standard library
from os import getenv
from pathlib import Path

# 3rd party
import PyInstaller.__main__

# package
sys.path.insert(0, str(Path(".").resolve()))
from dicogis import __about__ # noqa: E402

# #############################################################################
# ########### MAIN #################
# ##################################
package_folder = Path("dicogis")

PyInstaller.__main__.run(
[
"--add-binary={};bin/img/".format((package_folder / "bin/img/").resolve()),
"--add-data={};locale/".format((package_folder / "locale/").resolve()),
"--add-data=options_TPL.ini;.",
"--add-data=LICENSE;.",
"--add-data=README.md;.",
"--collect-submodules=shellingham",
"--console",
"--icon={}".format((package_folder / "bin/img/DicoGIS.ico").resolve()),
"--log-level={}".format(getenv("PYINSTALLER_LOG_LEVEL", "WARN")),
"--manifest={}".format((package_folder / "../builder/manifest.xml").resolve()),
"--name={}-cli_{}_{}{}_Python{}-{}".format(
__about__.__title_clean__,
__about__.__version__.replace(".", "-"),
platform.system(),
platform.architecture()[0],
platform.python_version_tuple()[0],
platform.python_version_tuple()[1],
),
"--noconfirm",
"--noupx",
"--onefile",
"--version-file={}".format("version_info.txt"),
str(package_folder.joinpath("cli/main.py")),
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@
"--add-data=options_TPL.ini;.",
"--add-data=LICENSE;.",
"--add-data=README.md;.",
"--clean",
# "--debug=all",
"--icon={}".format((package_folder / "bin/img/DicoGIS.ico").resolve()),
"--log-level={}".format(getenv("PYINSTALLER_LOG_LEVEL", "WARN")),
"--manifest={}".format((package_folder / "../builder/manifest.xml").resolve()),
"--name={}_{}_{}{}_Python{}-{}".format(
"--name={}-gui_{}_{}{}_Python{}-{}".format(
__about__.__title_clean__,
__about__.__version__.replace(".", "-"),
platform.system(),
Expand All @@ -49,7 +47,6 @@
),
"--noconfirm",
"--noupx",
# "--onedir",
"--onefile",
"--version-file={}".format("version_info.txt"),
"--windowed",
Expand Down

0 comments on commit 5d77620

Please sign in to comment.