snippets:python:start
Differences
This shows you the differences between two versions of the page.
| snippets:python:start [2026-01-02 15:03] – created malte70 | snippets:python:start [2026-01-02 17:19] (current) – Snippet „zipapp“ hinzugefügt malte70 | ||
|---|---|---|---|
| Line 44: | Line 44: | ||
| db.close() | db.close() | ||
| </ | </ | ||
| + | |||
| + | ===== Skript inkl. Abhängigkeiten als ausführbare ZIP-Datei ===== | ||
| + | |||
| + | > **Achtung!** Dieses Snippet ist nur eine Roh-Fassung und muss noch überarbeitet werden! | ||
| + | |||
| + | Mithilfe von Pythons [[https:// | ||
| + | |||
| + | Die erzeugte Datei ist ein ZIP-Archiv mit Shebang, und kann so auf jedem System ausgeführt werden, solange Python installiert ist (Was unter Unix/Linux meist der Fall ist). | ||
| + | |||
| + | Das folgende Skript erstellt eine zipapp für [[https:// | ||
| + | |||
| + | <code bash> | ||
| + | # Python zipapp for pushover-notify | ||
| + | |||
| + | cd " | ||
| + | |||
| + | wget " | ||
| + | echo '# requirements.txt | ||
| + | # for standalone pushover-notify zipapp | ||
| + | |||
| + | pushover @ git+https:// | ||
| + | toml==0.10.2 | ||
| + | ' > requirements_pushover_notify.txt | ||
| + | |||
| + | |||
| + | # | ||
| + | # Create pushover_notify package containing the script and | ||
| + | # all of it's dependencies | ||
| + | # | ||
| + | mkdir pushover_notify/ | ||
| + | |||
| + | # Empty __init__.py | ||
| + | touch pushover_notify/ | ||
| + | |||
| + | # The script itself | ||
| + | cp pushover-notify pushover_notify/ | ||
| + | |||
| + | # requirements.txt | ||
| + | # (used later to install dependencies into the pushover_notify package) | ||
| + | mv requirements_pushover_notify.txt pushover_notify/ | ||
| + | |||
| + | # Example config | ||
| + | echo ' | ||
| + | appname | ||
| + | api_key | ||
| + | user_key = " | ||
| + | |||
| + | # Optional: Alternative apps | ||
| + | [app.foo] | ||
| + | appname = " | ||
| + | api_key = " | ||
| + | ' > pushover_notify/ | ||
| + | |||
| + | |||
| + | # Install external requirements | ||
| + | python -m pip install -r pushover_notify/ | ||
| + | |||
| + | # Clean up after pip | ||
| + | rm -rf pushover_notify/ | ||
| + | |||
| + | |||
| + | # | ||
| + | # Create a .pyz file from the module pushover_notify | ||
| + | # | ||
| + | python -m zipapp \ | ||
| + | pushover_notify/ | ||
| + | -p "/ | ||
| + | -o po-notify.pyz \ | ||
| + | -c | ||
| + | |||
| + | </ | ||
| + | |||
snippets/python/start.1767366204.txt.gz · Last modified: by malte70
