Merge pull request #1 from realAscot/bugfix/venv-activation

Bugfix 1.0.2
This commit is contained in:
Adam Skotarczak 2025-04-22 09:10:39 +02:00 committed by GitHub
commit 72efb6ac59
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 47 additions and 15 deletions

View File

@ -2,10 +2,16 @@
## pyUpload (TKInter-Version 1.0) ## pyUpload (TKInter-Version 1.0)
- **2025-04-22 - v.1.0.2**
- Behoben
-- Wrapper-Skript `start.py` erkennt nun fehlende `.venv` und startet `main.py` beim Erststart korrekt mit System-Python, danach mit venv (`start.py`).
-- `main.py` verwendet unter Windows statt `os.execv()` nun `subprocess.Popen(..., CREATE_NEW_CONSOLE)` für einen sauberen Neustart mit sichtbarer Konsole (`main.py`).
- Entfernt
-- Nicht mehr benötigte Funktion `activate_venv()` entfernt (`main.py`).
- 2025-04-21 - **2025-04-21 - v.1.0.1**
- Geändert - Geändert
- `main.py` übernimmt nun automatisch die Erstellung der virtuellen Umgebung `.venv` und die Installation der Abhängigkeiten aus `requirements.txt` - `main.py` übernimmt nun automatisch die Erstellung der virtuellen Umgebung `.venv` und die Installation der Abhängigkeiten aus `requirements.txt`
@ -26,3 +32,6 @@
- PowerShell-Inkompatibilitäten mit `set /p` entfernt - PowerShell-Inkompatibilitäten mit `set /p` entfernt
- `.cmd`-Startskripte reagieren jetzt korrekt auf STRG+C - `.cmd`-Startskripte reagieren jetzt korrekt auf STRG+C
- Mehrere Markdown-Korrekturen (Codeblöcke, Leerzeilen, Lesbarkeit) - Mehrere Markdown-Korrekturen (Codeblöcke, Leerzeilen, Lesbarkeit)
- **2025-04-21 - v.1.0.0**
- release!

View File

@ -1 +1 @@
1.0.1 1.0.2

View File

@ -2,7 +2,9 @@
# © 2025 Adam Skotarczak (adam@skotarczak.net) # © 2025 Adam Skotarczak (adam@skotarczak.net)
# Dieses Softwarepaket darf nicht ohne Genehmigung weiterverbreitet werden! # Dieses Softwarepaket darf nicht ohne Genehmigung weiterverbreitet werden!
# Version 1.0.0 (12.03.2025) #
# Version 1.0.2 (22.04.2025 - virtuelle Umgebung korrekt aktiviert)
# Manuel in z.B VS-Code: .\app\.venv\Scripts\activate
import os import os
import sys import sys
@ -16,17 +18,27 @@ VENV_DIR = os.path.join(BASE_DIR, ".venv")
VENV_PYTHON = os.path.join(VENV_DIR, "Scripts", "python.exe") if os.name == "nt" else os.path.join(VENV_DIR, "bin", "python") VENV_PYTHON = os.path.join(VENV_DIR, "Scripts", "python.exe") if os.name == "nt" else os.path.join(VENV_DIR, "bin", "python")
REQUIREMENTS_FILE = os.path.join(BASE_DIR, "requirements.txt") REQUIREMENTS_FILE = os.path.join(BASE_DIR, "requirements.txt")
# Wenn wir NICHT in der venv sind → prüfen, ob venv existiert # Wenn wir NICHT in der venv sind
if sys.prefix == sys.base_prefix and not os.path.exists(VENV_DIR): if sys.prefix == sys.base_prefix:
print("[Setup] Virtuelle Umgebung wird erstellt...") # venv erstellen falls nötig
subprocess.run([sys.executable, "-m", "venv", "--copies", VENV_DIR], check=True) if not os.path.exists(VENV_DIR):
print("[Setup] Virtuelle Umgebung wird erstellt...")
subprocess.run([sys.executable, "-m", "venv", "--copies", VENV_DIR], check=True)
print("[Setup] requirements.txt wird installiert...") print("[Setup] requirements.txt wird installiert...")
subprocess.run([VENV_PYTHON, "-m", "pip", "install", "--upgrade", "pip"], check=True) subprocess.run([VENV_PYTHON, "-m", "pip", "install", "--upgrade", "pip"], check=True)
subprocess.run([VENV_PYTHON, "-m", "pip", "install", "-r", REQUIREMENTS_FILE], check=True) subprocess.run([VENV_PYTHON, "-m", "pip", "install", "-r", REQUIREMENTS_FILE], check=True)
# unabhängig davon: Neustart innerhalb der venv
print("[Setup] Starte erneut mit aktivierter Umgebung...") print("[Setup] Starte erneut mit aktivierter Umgebung...")
os.execv(VENV_PYTHON, [VENV_PYTHON] + sys.argv)
if os.name == "nt":
subprocess.Popen([VENV_PYTHON] + sys.argv, creationflags=subprocess.CREATE_NEW_CONSOLE)
else:
os.execv(VENV_PYTHON, [VENV_PYTHON] + sys.argv)
sys.exit(0)
#os.execv(VENV_PYTHON, [VENV_PYTHON] + sys.argv)
# Wir sind jetzt sicher in der richtigen Umgebung → Rest des Programms geht hier weiter: # Wir sind jetzt sicher in der richtigen Umgebung → Rest des Programms geht hier weiter:
@ -60,8 +72,6 @@ def activate_venv():
print(f"FEHLER: Virtuelle Umgebung nicht gefunden ({VENV_DIR}). Bitte zuerst install.cmd ausführen.") print(f"FEHLER: Virtuelle Umgebung nicht gefunden ({VENV_DIR}). Bitte zuerst install.cmd ausführen.")
sys.exit(1) sys.exit(1)
activate_venv()
# ------------------------------------------------------------------- # -------------------------------------------------------------------
# Globale Konfigurationen & Logging # Globale Konfigurationen & Logging
# ------------------------------------------------------------------- # -------------------------------------------------------------------

View File

@ -1,3 +1,16 @@
import subprocess, os #!/usr/bin/env python3
import os
import sys
import subprocess
os.chdir(os.path.dirname(__file__)) os.chdir(os.path.dirname(__file__))
subprocess.run(["python", "app/main.py"])
# Zielpfad zur venv-Python
venv_python = os.path.join("app", ".venv", "Scripts", "python.exe") if os.name == "nt" else os.path.join("app", ".venv", "bin", "python")
# Verwende venv-Python, wenn vorhanden sonst system-Python für initialen Aufbau
python_exec = venv_python if os.path.exists(venv_python) else sys.executable
# Starte main.py
subprocess.run([python_exec, "app/main.py"] + sys.argv[1:])