build: Upgrade buildsystem with new Makefile and make.bat

If a PyInstaller target is called from the Makefile, all libraries
installed in the virtual environment are captured with version and
license. The file 'bundled-libraries.md' contains a list of libraries
with version and license. The file 'open-source-licenses.txt'
includes the name, version, author, project URL, description and
complete license for each installed library. The files are included
in the output of the PyInstaller.
This commit is contained in:
2023-10-01 13:45:02 +02:00
parent d2be450d98
commit 24f4d688ba
3 changed files with 145 additions and 59 deletions

116
Makefile
View File

@@ -19,7 +19,7 @@ endif
SYSTEM_PYTHON = python3
PYTHON = $(or $(wildcard $(VENV_PATH)/bin/python), $(SYSTEM_PYTHON))
APP_VERSION = $(shell $(PYTHON) src/$(PACKAGE) --version)
APP_VERSION = $(shell "$(PYTHON)" src/$(PACKAGE) --version | cut -d ' ' -f 2)
all: build_ui build_rc test build
@@ -27,55 +27,105 @@ all: build_ui build_rc test build
## Environment
venv-info:
echo Using path: "$(VENV_PATH)"
@echo Environment for $(APP_NAME) $(APP_VERSION)
@echo Using path: "$(VENV_PATH)"
exit 0
venv:
$(SYSTEM_PYTHON) -m venv --system-site-packages "$(VENV_PATH)"
source $(VENV_PATH)/bin/activate && \
# Start with empty environment
"$(SYSTEM_PYTHON)" -m venv "$(VENV_PATH)"
source "$(VENV_PATH)/bin/activate" && \
python3 -m pip install --upgrade pip && \
python3 -m pip install -r requirements.txt
exit 0
.PHONY: venv-info venv
venv-ssp:
# Include system installed site-packages and add just missing modules
"$(SYSTEM_PYTHON)" -m venv --system-site-packages "$(VENV_PATH)"
source "$(VENV_PATH)/bin/activate" && \
python3 -m pip install --upgrade pip && \
python3 -m pip install -r requirements.txt
exit 0
.PHONY: venv-info venv venv-ssp
## Compile Qt UI files to python code
build_ui:
build-ui:
cd ui_dev && for ui_file in *.ui; do \
file_name=$${ui_file%.ui}; \
$(PYTHON) -m PyQt5.uic.pyuic $${ui_file} -o ../src/$(PACKAGE)/ui/$${file_name}_ui.py -x --from-imports; \
"$(PYTHON)" -m PyQt5.uic.pyuic $${ui_file} -o ../src/$(PACKAGE)/ui/$${file_name}_ui.py -x --from-imports; \
echo $${file_name}; \
done
build_rc:
build-rc:
cd ui_dev && for rc_file in *.qrc; do \
file_name=$${rc_file%.qrc}; \
$(PYTHON) -m PyQt5.pyrcc_main $${rc_file} -o ../src/$(PACKAGE)/ui/$${file_name}_rc.py; \
"$(PYTHON)" -m PyQt5.pyrcc_main $${rc_file} -o ../src/$(PACKAGE)/ui/$${file_name}_rc.py; \
echo $${file_name}; \
done
update_translation:
$(PYTHON) -m PyQt5.pylupdate_main translate.pro
update-translation:
"$(PYTHON)" -m PyQt5.pylupdate_main translate.pro
.PHONY: build_ui build_rc update_translation
.PHONY: build-ui build-rc update-translation
## Build steps
build: build_ui build_rc
$(PYTHON) -m setup sdist
$(PYTHON) -m setup bdist_wheel
build:
"$(PYTHON)" -m setup sdist
"$(PYTHON)" -m setup bdist_wheel
install: test build
$(PYTHON) -m pip install dist/$(PACKAGE)-*.whl
install: build
"$(PYTHON)" -m pip install dist/$(PACKAGE)-$(APP_VERSION)-*.whl
uninstall:
$(PYTHON) -m pip uninstall --yes $(PACKAGE)
"$(PYTHON)" -m pip uninstall --yes $(PACKAGE)
.PHONY: test build install uninstall
## PyInstaller
installer_mac: build_ui build_rc
$(PYTHON) -m PyInstaller -n $(APP_NAME) \
app-licenses:
mkdir -p dist
# Create a list of all installed libraries, their versions and licenses
"$(PYTHON)" -m piplicenses \
--format=markdown \
--output-file dist/bundled-libraries.md
# Create a list of installed libraries with complete project information
"$(PYTHON)" -m piplicenses \
--with-authors \
--with-urls \
--with-description \
--with-license-file \
--no-license-path \
--format=json \
--output-file dist/open-source-licenses.json
"$(PYTHON)" -m piplicenses \
--with-authors \
--with-urls \
--with-description \
--with-license-file \
--no-license-path \
--format=plain-vertical \
--output-file dist/open-source-licenses.txt
app: build-ui build-rc app-licenses
"$(PYTHON)" -m PyInstaller -n $(APP_NAME) \
--add-data="src/$(PACKAGE)/locale:./$(PACKAGE)/locale" \
--add-data="dist/bundled-libraries.md:$(PACKAGE)/open-source-licenses" \
--add-data="dist/open-source-licenses.*:$(PACKAGE)/open-source-licenses" \
--add-data="data/$(PACKAGE).ico:." \
--add-data="data/$(PACKAGE).png:." \
--icon=data/$(PACKAGE).ico \
--noconfirm \
--clean \
--onedir \
--windowed \
src/$(PACKAGE)/__main__.py
app-mac: build-ui build-rc app-licenses
"$(PYTHON)" -m PyInstaller -n $(APP_NAME) \
--add-data="src/$(PACKAGE)/locale:./$(PACKAGE)/locale" \
--add-data="dist/bundled-libraries.md:$(PACKAGE)/open-source-licenses" \
--add-data="dist/open-source-licenses.*:$(PACKAGE)/open-source-licenses" \
--add-data="data/$(PACKAGE).icns:." \
--icon=data/$(PACKAGE).icns \
--noconfirm \
@@ -86,7 +136,7 @@ installer_mac: build_ui build_rc
--codesign-identity $(APPLE_SIG) \
src/$(PACKAGE)/__main__.py
installer_mac_dmg: installer_mac
app-mac-dmg: app-mac
mkdir dist/dmg
mv dist/$(APP_NAME).app dist/dmg
create-dmg \
@@ -104,25 +154,19 @@ installer_mac_dmg: installer_mac
dist/$(APP_NAME)\ $(APP_VERSION).dmg \
dist/dmg
installer_linux: build_ui build_rc
$(PYTHON) -m PyInstaller -n $(APP_NAME) \
--add-data="src/$(PACKAGE)/locale:./$(PACKAGE)/locale" \
--add-data="data/$(PACKAGE).ico:." \
--add-data="data/$(PACKAGE).png:." \
--icon=data/$(PACKAGE).ico \
--noconfirm \
--clean \
--onedir \
--windowed \
src/$(PACKAGE)/__main__.py
.PHONY: installer_mac installer_mac_dmg installer_linux
.PHONY: app-licenses app app-mac app-mac-dmg
## Clean
clean:
rm -rf build dist src/*.egg-info *.spec
# PyTest caches
rm -rf .pytest_cache
# Build artifacts
rm -rf build dist src/*.egg-info
# PyInstaller created files
rm -rf *.spec
distclean: clean
rm -rf $(VENV_PATH)
# Virtual environment
rm -rf "$(VENV_PATH)"
.PHONY: clean distclean