Skip to content

Commit

Permalink
Packaging: improve output name and PyInstaller options (#321)
Browse files Browse the repository at this point in the history
- change executable name from `
QGISDeploymentToolbelt_0-26-0_Windows64bit_Python3-11.exe ` to
`QGISDeploymentToolbelt_0-26-0.exe` cc @jmkerloch
- let PyInstaller deciding use UPX or not
- generate a build report to keep a trace accross CI/CD
- minor improvments in builder scripts (f-strings...)
- update packaging documentation consequently
  • Loading branch information
Guts authored Nov 8, 2023
2 parents 16c8150 + 56087a7 commit 974f0e0
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 51 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/build_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ jobs:
- uses: actions/upload-artifact@v3
with:
name: macos_executable
path: dist/*
path: |
dist/*
build_environment_report.txt
if-no-files-found: error

build-ubuntu:
Expand Down Expand Up @@ -131,7 +133,9 @@ jobs:
- uses: actions/upload-artifact@v3
with:
name: ubuntu_executable
path: dist/*
path: |
dist/*
build_environment_report.txt
if-no-files-found: error

build-windows:
Expand Down Expand Up @@ -168,7 +172,9 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: windows_executable
path: dist/*
path: |
dist/*
build_environment_report.txt
if-no-files-found: error

release:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,4 @@ docs/misc/licenses.md
docs/misc/dependencies.md
QGISDeploymentToolbelt_*Ubuntu*
tests/fixtures/tmp/*
build_environment_report.txt
34 changes: 22 additions & 12 deletions builder/pyinstaller_build_macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# Standard library
import platform
import sys
from datetime import datetime
from os import getenv
from pathlib import Path

Expand All @@ -24,28 +25,37 @@
# #############################################################################
# ########### MAIN #################
# ##################################
# write build report
build_report = (
f"datetime: {datetime.now().astimezone().isoformat()}"
f"\nprog_name: {__about__.__title__}"
f"\nprog_version: {__about__.__version__}"
f"\noperating_system: {platform.system()}"
f"\noperating_system_version: {platform.release()}_{platform.version()}"
f"\narchitecture: {platform.architecture()[0]}"
f"\npython_version: {platform.python_version()}"
)
Path("build_environment_report.txt").write_text(data=build_report, encoding="UTF-8")

# variables
output_filename = (
f"{__about__.__title_clean__}_{__about__.__version__.replace('.', '-')}"
)
package_folder = Path("qgis_deployment_toolbelt")


mac_os_version, _, _ = platform.mac_ver()
mac_os_version = "-".join(mac_os_version.split(".")[:2])

PyInstaller.__main__.run(
[
"--add-data=LICENSE:.",
"--add-data=README.md:.",
"--add-data={}:profiles/".format(
(package_folder / "profiles/shortcut_freedesktop.template/").resolve()
),
"--log-level={}".format(getenv("PYINSTALLER_LOG_LEVEL", "WARN")),
"--name={}_{}_MacOS{}_Python{}-{}".format(
__about__.__title_clean__,
__about__.__version__.replace(".", "-"),
mac_os_version,
platform.python_version_tuple()[0],
platform.python_version_tuple()[1],
),
f"--add-data={package_folder.joinpath('profiles/shortcut_freedesktop.template/').resolve()}:profiles/",
f"--log-level={getenv('PYINSTALLER_LOG_LEVEL', 'WARN')}",
f"--name={output_filename}",
"--noconfirm",
"--noupx",
# "--noupx",
"--onefile",
"--console",
str(package_folder / "cli.py"),
Expand Down
35 changes: 22 additions & 13 deletions builder/pyinstaller_build_ubuntu.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# Standard library
import platform
import sys
from datetime import datetime
from os import getenv
from pathlib import Path

Expand All @@ -25,26 +26,34 @@
# #############################################################################
# ########### MAIN #################
# ##################################

# write build report
build_report = (
f"datetime: {datetime.now().astimezone().isoformat()}"
f"\nprog_name: {__about__.__title__}"
f"\nprog_version: {__about__.__version__}"
f"\ndistribution: {distro.name()}"
f"\ndistribution_version: {distro.version()}"
f"\narchitecture: {platform.architecture()[0]}"
f"\npython_version: {platform.python_version()}"
)
Path("build_environment_report.txt").write_text(data=build_report, encoding="UTF-8")


# variables
output_filename = (
f"{__about__.__title_clean__}_{__about__.__version__.replace('.', '-')}"
)
package_folder = Path("qgis_deployment_toolbelt")

PyInstaller.__main__.run(
[
"--add-data=LICENSE:.",
"--add-data=README.md:.",
"--add-data={}:profiles/".format(
(package_folder / "profiles/shortcut_freedesktop.template/").resolve()
),
"--log-level={}".format(getenv("PYINSTALLER_LOG_LEVEL", "WARN")),
"--name={}_{}_{}{}_{}_Python{}".format(
__about__.__title_clean__,
__about__.__version__,
distro.name(),
distro.version(),
platform.architecture()[0],
platform.python_version(),
).replace(".", "-"),
f"--add-data={package_folder.joinpath('profiles/shortcut_freedesktop.template/').resolve()}:profiles/",
f"--log-level={getenv('PYINSTALLER_LOG_LEVEL', 'WARN')}",
f"--name={output_filename}",
"--noconfirm",
"--noupx",
"--onefile",
"--console",
str(package_folder / "cli.py"),
Expand Down
38 changes: 23 additions & 15 deletions builder/pyinstaller_build_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# Standard library
import platform
import sys
from datetime import datetime
from os import getenv
from pathlib import Path

Expand All @@ -24,31 +25,38 @@
# #############################################################################
# ########### MAIN #################
# ##################################

# write build report
build_report = (
f"datetime: {datetime.now().astimezone().isoformat()}"
f"\nprog_name: {__about__.__title__}"
f"\nprog_version: {__about__.__version__}"
f"\noperating_system: {platform.system()}"
f"\noperating_system_version: {platform.release()}_{platform.version()}"
f"\narchitecture: {platform.architecture()[0]}"
f"\npython_version: {platform.python_version()}"
)
Path("build_environment_report.txt").write_text(data=build_report, encoding="UTF-8")

# variables
output_filename = (
f"{__about__.__title_clean__}_{__about__.__version__.replace('.', '-')}"
)
package_folder = Path("qgis_deployment_toolbelt")

PyInstaller.__main__.run(
[
"--add-data=LICENSE:.",
"--add-data=README.md:.",
"--add-data={}:profiles/".format(
(package_folder / "profiles/shortcut_freedesktop.template/").resolve()
),
# "--clean",
f"--icon={package_folder.parent.resolve()}/docs/static/logo_qdt.ico",
"--log-level={}".format(getenv("PYINSTALLER_LOG_LEVEL", "WARN")),
"--manifest={}".format((package_folder / "../builder/manifest.xml").resolve()),
"--name={}_{}_{}{}_Python{}-{}".format(
__about__.__title_clean__,
__about__.__version__.replace(".", "-"),
platform.system(),
platform.architecture()[0],
platform.python_version_tuple()[0],
platform.python_version_tuple()[1],
),
f"--log-level={getenv('PYINSTALLER_LOG_LEVEL', 'WARN')}",
f"--manifest={Path(__file__).parent.joinpath('manifest.xml')}",
f"--name={output_filename}",
"--noconfirm",
"--noupx",
# "--noupx",
"--onefile",
"--version-file={}".format("version_info.txt"),
"--version-file=version_info.txt",
"--console",
str(package_folder / "cli.py"),
]
Expand Down
17 changes: 9 additions & 8 deletions docs/development/packaging.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

The project takes advantage of [PyInstaller](https://pyinstaller.readthedocs.io/) to package the application into an executable.

The output binary and all embedded dependencies is located into a subfolder named: `dist/qgis_deployment_toolbelt_{version}_{operating-system}_Python{python-version}`.
The output binary and all embedded dependencies is located into a subfolder named: `dist/QGISDeploymentToolbelt_{version}`. A file named `build_environment_report.txt` containing build environment information is generated at the project's root.

### Windows

> Comply with [Windows development requirements](windows) before to run.
> Comply with [Windows development requirements](../development/windows.md) before to run.
```powershell
# Generates MS Version Info
Expand All @@ -18,24 +18,25 @@ python .\builder\version_info_templater.py
python -O .\builder\pyinstaller_build_windows.py
```

![QGIS Deployment Toolbelt - Executable properties](/static/executable_windows_properties_details.png)
![QGIS Deployment Toolbelt - Executable properties](../static/executable_windows_properties_details.png)

To run it, double-click on the executable file (*.exe).

### Ubuntu

> Comply with [Ubuntu development requirements](ubuntu) before to run.
> Comply with [Ubuntu development requirements](../development/ubuntu.md) before to run.
```bash
```sh
# Generates binary executable
python -O ./builder/pyinstaller_build_ubuntu.py
# make it runnable
chmod +x dist/QGISDeploymentToolbelt_*
```

To run it, for example:

```bash
cd dist/qgis_deployment_toolbelt_3-0-0_Ubuntu20-04_64bit_Python3-8-5/
./qgis_deployment_toolbelt_3-0-0_Ubuntu20-04_64bit_Python3-8-5
```sh
./dist/QGISDeploymentToolbelt_0-26-0
```

----
Expand Down

0 comments on commit 974f0e0

Please sign in to comment.