Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make rule to generate standalone python zippapp application #149

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
make rule to generate standalone python zippapp application
This bundles umu-run and its dependencies in a standalone executable
(a python zipapp), ideal for clients like heroic or lutris.

This can also be used from python code by adding the file to PYTHONPATH
(or sys.path) as in:

PYTHONPATH=~/.local/bin/umu-run python -m umu
db47h committed Jul 15, 2024
commit 216d284f84391cc5fbb19a4b52d3a0a07943c84a
10 changes: 10 additions & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
@@ -178,4 +178,14 @@ user-install:
$(info :: To run you need to make sure "$(BINDIR)" is in your PATH )


ZIPAPP := $(OBJDIR)/umu-run-$(shell git describe --always --long --tags)
ZIPAPP_STAGING := $(OBJDIR)/umu-run_staging

.PHONY: zipapp
zipapp: version | $(OBJDIR)
@$(PYTHON_INTERPRETER) -m pip install -t "$(ZIPAPP_STAGING)" --upgrade .
cp umu/umu_version.json "$(ZIPAPP_STAGING)"/umu
@$(PYTHON_INTERPRETER) -m zipapp $(ZIPAPP_STAGING) -m "umu.__main__:main" -o $(ZIPAPP) -p "$(PYTHON_INTERPRETER)" -c
@echo "Standalone application created: $(ZIPAPP))"

# vim: ft=make
11 changes: 10 additions & 1 deletion umu/umu_run.py
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
import sys
import threading
import time
import zipfile
from _ctypes import CFuncPtr
from argparse import ArgumentParser, Namespace, RawTextHelpFormatter
from concurrent.futures import Future, ThreadPoolExecutor
@@ -691,7 +692,15 @@ def main() -> int: # noqa: D103
}
command: list[AnyPath] = []
opts: list[str] = []
root: Path = Path(__file__).resolve(strict=True).parent
root: Path
try:
root = Path(__file__).resolve(strict=True).parent
except NotADirectoryError:
# raised when whithin a zipapp. Try again in non-strict mode, root
# should be zipapp.pyz/umu. Split and set root to /umu within zip.
root = Path(__file__).resolve().parent
root = zipfile.Path(root.parent, root.name)

args: Namespace | tuple[str, list[str]] = parse_args()

if os.geteuid() == 0: