From e8911df7e9437b7d0083cda443ca080dcfd994bd Mon Sep 17 00:00:00 2001 From: Michael Stangl Date: Thu, 9 Jul 2026 11:57:05 +0200 Subject: [PATCH] Use setenv in launcher scripts, add requirements.txt and missing .sh scripts platz.bat/platz.sh now derive PLATZ via setenv instead of hardcoded paths, matching the Standard Programm Template already applied to setenv/install_py/activate_venv/get_cmd. Added the missing .sh counterparts to those .bat scripts, an empty requirements.txt for install_py to install (project only uses the stdlib), and ignore entries for .venv/, out/, .vscode/, *.swp. Co-Authored-By: Claude Sonnet 5 --- .gitignore | 4 ++++ CLAUDE.md | 33 ++++++++++++++++++---------- README.md | 51 +++++++++++++++++++++++++++++-------------- bin/activate_venv.bat | 20 +++++++++++++++++ bin/activate_venv.sh | 20 +++++++++++++++++ bin/get_cmd.bat | 7 ++++++ bin/get_cmd.sh | 7 ++++++ bin/install_py.bat | 21 ++++++++++++++++++ bin/install_py.sh | 20 +++++++++++++++++ bin/platz.bat | 8 +++++++ bin/platz.sh | 8 +++++++ bin/run | 17 --------------- bin/run.bat | 21 ------------------ bin/setenv.bat | 35 +++++++++++++++++++++++++++++ bin/setenv.sh | 32 +++++++++++++++++++++++++++ requirements.txt | 8 +++++++ 16 files changed, 246 insertions(+), 66 deletions(-) create mode 100644 bin/activate_venv.bat create mode 100644 bin/activate_venv.sh create mode 100644 bin/get_cmd.bat create mode 100644 bin/get_cmd.sh create mode 100644 bin/install_py.bat create mode 100644 bin/install_py.sh create mode 100644 bin/platz.bat create mode 100644 bin/platz.sh delete mode 100755 bin/run delete mode 100644 bin/run.bat create mode 100644 bin/setenv.bat create mode 100644 bin/setenv.sh create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore index 419c3b9..fcf5227 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,7 @@ __pycache__/ *.pyo work/ausgabe.txt +.venv/ +out/ +.vscode/ +*.swp diff --git a/CLAUDE.md b/CLAUDE.md index e1628a3..8f2b251 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -13,22 +13,31 @@ result to text/CSV output files. **This is Python 2 code** (print statements, `ConfigParser`, `sets.Set`, `UserList`, `string.split`, old-style `raise Exception, "msg"`, `xrange`, `dict.has_key`, `dict.iteritems`). It will not run under Python 3 without a 2to3-style port. There is no -`requirements.txt`, build system, test suite, or linter configured in this repo — a Python 2 -interpreter with only the standard library is sufficient to run it. +build system, test suite, or linter configured in this repo. `requirements.txt` exists but +is empty/commented — everything used is standard library — it's there only so +`bin/install_py.*` has something to install into the `.venv`. ## Running the program -Entry point is `libs/platz.py`, invoked via the wrapper scripts in `bin/`, which set up -environment variables and `PYTHONPATH` before calling it — the scripts never take a script -argument, they just launch `platz.py`: +Entry point is `libs/platz.py`, invoked via the scripts in `bin/` (each provided as a +`.bat`/`.sh` pair, following the "Standard Programm Template" convention — see +`~/.claude/CLAUDE.md` for the template rules): -- `bin/run` (bash, for Linux/macOS) — hardcodes `PLATZ=/Users/sm/develop/python/platz` -- `bin/run.bat` (Windows) — hardcodes `PLATZ=h:\develop\python\platz` and a Python 2.4 interpreter path - -Both scripts set `PLATZ_CFG`, `PLATZ_LIBS`, `PLATZ_WORK` and add `PLATZ_LIBS` to -`PYTHONPATH`, then run `python $PLATZ_LIBS/platz.py`. **The hardcoded paths at the top of -these scripts must be edited to match wherever this repo is actually checked out** before -they will work. +- `bin/setenv.bat` / `bin/setenv.sh` — derives `PLATZ` from the script's own location (no + path editing needed), sets `PLATZ_BIN`, `PLATZ_CFG`, `PLATZ_LIBS`, `PLATZ_WORK`, + `PLATZ_IN`, `PLATZ_OUT`, adds `PLATZ_LIBS` to `PYTHONPATH` (idempotently), and creates + missing folders. Sourced by every other script; not normally invoked directly. The `.sh` + variant must be sourced (`source bin/setenv.sh`), not executed. +- `bin/install_py.bat` / `bin/install_py.sh` — calls `setenv`, then creates `.venv` (via + `py -m venv` / `python3 -m venv`) and `pip install -r requirements.txt` if `.venv` doesn't + already exist. +- `bin/activate_venv.bat` / `bin/activate_venv.sh` — calls `setenv`, then activates the + existing `.venv` (errors out if `install_py` hasn't been run yet). +- `bin/get_cmd.bat` / `bin/get_cmd.sh` — calls `setenv`, then opens a new shell with the + `PLATZ_*` environment already set. +- `bin/platz.bat` / `bin/platz.sh` — calls `setenv`, then runs `python + "$PLATZ_LIBS/platz.py"`. This is the actual program entry point (replaces the old + `bin/run` / `bin/run.bat`, which hardcoded absolute paths and have been removed). Configuration is driven by `cfg/platz.cfg`, which points (via `$PLATZ_CFG`/`$PLATZ_WORK` env-var expansion) to: diff --git a/README.md b/README.md index e8c8355..95f5bcc 100644 --- a/README.md +++ b/README.md @@ -7,14 +7,14 @@ using a small custom GA framework, and writes the result to text/CSV output file **This is Python 2 code** (print statements, `ConfigParser`, `sets.Set`, `UserList`, `string.split`, old-style `raise Exception, "msg"`, `xrange`, `dict.has_key`, -`dict.iteritems`). It needs a Python 2 interpreter; there are no third-party dependencies -(standard library only). +`dict.iteritems`). There are no third-party dependencies (standard library only), so +`requirements.txt` is empty — it exists only so `bin/install_py` has something to install. ## Project structure ``` platz/ -├── bin/ # launcher scripts (bash + Windows batch) +├── bin/ # environment + launcher scripts (.bat + .sh pairs) ├── cfg/ # GA cycle definition and penalty scheme ├── libs/ # the two Python modules (ga.py, Strukturdaten.py, platz.py) └── work/ # per-run input (table layout, guest list) and output @@ -29,29 +29,48 @@ platz/ ## Setup -1. Install a Python 2 interpreter (2.4+; no `pip install` needed, standard library only). -2. Edit the hardcoded paths at the top of the launcher script for your platform: - - `bin/run` (bash): `PLATZ=/Users/sm/develop/python/platz` - - `bin/run.bat` (Windows): `PLATZ=h:\develop\python\platz` and `PYTHONSHELL=l:\tools\i486_nt\python24` +1. Install a Python interpreter (`py` on Windows / `python3` on Linux/macOS must be on + `PATH`). +2. Run the installer for your platform to create a `.venv` and install `requirements.txt`: - Point `PLATZ` at wherever you checked out this repository. + ```bat + :: Windows + bin\install_py.bat + ``` + + ```bash + # Linux/macOS + bin/install_py.sh + ``` + +All `bin/` scripts derive `PLATZ` automatically from their own location (no path editing +required) by calling `setenv.bat`/`setenv.sh` first. ## Running -From a shell: +```bat +:: Windows +bin\activate_venv.bat +bin\platz.bat +``` ```bash # Linux/macOS -source bin/run +source bin/activate_venv.sh +bin/platz.sh ``` -```bat -:: Windows -bin\run.bat -``` +`bin/platz.bat` / `bin/platz.sh` call `setenv` to set `PLATZ`, `PLATZ_CFG`, `PLATZ_LIBS`, +`PLATZ_WORK`, `PLATZ_IN`, `PLATZ_OUT`, add `PLATZ_LIBS` to `PYTHONPATH`, and then run +`libs/platz.py`. -The launcher sets `PLATZ_CFG`, `PLATZ_LIBS`, `PLATZ_WORK`, adds `PLATZ_LIBS` to -`PYTHONPATH`, and runs `libs/platz.py`. +Other helper scripts (`bin/setenv.*`, `bin/get_cmd.*`) follow the same environment +convention: + +- `setenv` — sets all `PLATZ_*` environment variables and creates missing folders; sourced + by every other script, not normally called directly. +- `activate_venv` — activates the `.venv` created by `install_py`. +- `get_cmd` — opens a new shell with the `PLATZ_*` environment already set. ### Configuring a run diff --git a/bin/activate_venv.bat b/bin/activate_venv.bat new file mode 100644 index 0000000..f3a1ca4 --- /dev/null +++ b/bin/activate_venv.bat @@ -0,0 +1,20 @@ +@echo off +REM ================================================================ +REM TEST - Python Virtual Environment aktivieren +REM ================================================================ + +call "%~dp0setenv.bat" + +if not exist "%PLATZ%\.venv" ( + echo FEHLER: Virtual environment nicht gefunden. + echo Bitte zuerst bin\install_py.bat ausfuehren. + exit /b 1 +) + +call "%PLATZ%\.venv\Scripts\activate.bat" +echo Virtuelle Umgebung aktiviert. +echo Python-Version: +python --version +echo. +echo Installierte Pakete: +pip list diff --git a/bin/activate_venv.sh b/bin/activate_venv.sh new file mode 100644 index 0000000..faa3e3f --- /dev/null +++ b/bin/activate_venv.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# ================================================================ +# Python Virtual Environment aktivieren +# ================================================================ + +source "$(dirname "${BASH_SOURCE[0]}")/setenv.sh" + +if [ ! -d "$PLATZ/.venv" ]; then + echo "FEHLER: Virtual environment nicht gefunden." + echo "Bitte zuerst bin/install_py.sh ausfuehren." + return 1 2>/dev/null || exit 1 +fi + +source "$PLATZ/.venv/bin/activate" +echo "Virtuelle Umgebung aktiviert." +echo "Python-Version:" +python --version +echo "" +echo "Installierte Pakete:" +pip list diff --git a/bin/get_cmd.bat b/bin/get_cmd.bat new file mode 100644 index 0000000..067622d --- /dev/null +++ b/bin/get_cmd.bat @@ -0,0 +1,7 @@ +@echo off +REM ================================================================ +REM TEST - Shell mit gesetzten Umgebungsvariablen oeffnen +REM ================================================================ + +call "%~dp0setenv.bat" +start cmd /k "echo TEST Umgebung aktiv. && echo PLATZ=%PLATZ%" diff --git a/bin/get_cmd.sh b/bin/get_cmd.sh new file mode 100644 index 0000000..93c35aa --- /dev/null +++ b/bin/get_cmd.sh @@ -0,0 +1,7 @@ +#!/bin/bash +# ================================================================ +# Shell mit gesetzten Umgebungsvariablen oeffnen +# ================================================================ + +source "$(dirname "${BASH_SOURCE[0]}")/setenv.sh" +exec "$SHELL" diff --git a/bin/install_py.bat b/bin/install_py.bat new file mode 100644 index 0000000..11a52f5 --- /dev/null +++ b/bin/install_py.bat @@ -0,0 +1,21 @@ +@echo off +REM ================================================================ +REM TEST - Python Virtual Environment einrichten +REM ================================================================ + +call "%~dp0setenv.bat" + +if not exist "%PLATZ%\.venv" ( + echo Initialisiere Python virtual environment... + py -m venv "%PLATZ%\.venv" --upgrade-deps + echo Erfolgreich. + + call "%PLATZ%\.venv\Scripts\activate.bat" + echo Installiere erforderliche Python Packages... + pip install -r "%PLATZ%\requirements.txt" -q + echo Erfolgreich. + deactivate +) else ( + echo Erforderliche Python Packages bereits installiert! +) + diff --git a/bin/install_py.sh b/bin/install_py.sh new file mode 100644 index 0000000..6e0409d --- /dev/null +++ b/bin/install_py.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# ================================================================ +# Python Virtual Environment einrichten +# ================================================================ + +source "$(dirname "${BASH_SOURCE[0]}")/setenv.sh" + +if [ ! -d "$PLATZ/.venv" ]; then + echo "Initialisiere Python virtual environment..." + python3 -m venv "$PLATZ/.venv" --upgrade-deps + echo "Erfolgreich." + + source "$PLATZ/.venv/bin/activate" + echo "Installiere erforderliche Python Packages..." + pip install -r "$PLATZ/requirements.txt" -q + echo "Erfolgreich." + deactivate +else + echo "Erforderliche Python Packages bereits installiert!" +fi diff --git a/bin/platz.bat b/bin/platz.bat new file mode 100644 index 0000000..0bf7533 --- /dev/null +++ b/bin/platz.bat @@ -0,0 +1,8 @@ +@echo off +REM ================================================================ +REM Startet das Sitzplatzprogramm +REM ================================================================ + +call "%~dp0setenv.bat" + +python "%PLATZ_LIBS%\platz.py" diff --git a/bin/platz.sh b/bin/platz.sh new file mode 100644 index 0000000..ea804ec --- /dev/null +++ b/bin/platz.sh @@ -0,0 +1,8 @@ +#!/bin/bash +# ================================================================ +# Startet das Sitzplatzprogramm +# ================================================================ + +source "$(dirname "${BASH_SOURCE[0]}")/setenv.sh" + +python "$PLATZ_LIBS/platz.py" diff --git a/bin/run b/bin/run deleted file mode 100755 index 4f3799e..0000000 --- a/bin/run +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -# ------------------------------------- -# Wo ist das Programm hinkopiert -export PLATZ=/Users/sm/develop/python/platz -echo $PLATZ -# ------------------------------------- - -# Umgebung setzen -export PLATZ_CFG=$PLATZ/cfg -export PLATZ_LIBS=$PLATZ/libs -export PLATZ_WORK=$PLATZ/work - -# Wo sind die Pythonskripte ? -export PYTHONPATH=$PYTHONPATH:$PLATZ_LIBS - -# Startet das Sitzplatzprogramm -python $PLATZ_LIBS/platz.py diff --git a/bin/run.bat b/bin/run.bat deleted file mode 100644 index 02c953e..0000000 --- a/bin/run.bat +++ /dev/null @@ -1,21 +0,0 @@ -echo off -REM Hier die Umgebung anpassen -REM ------------------------------------- -REM Wo ist das Programm hinkopiert -set PLATZ=h:\develop\python\platz -REM Wo liegt der Interpreter -set PYTHONSHELL=l:\tools\i486_nt\python24 -REM ------------------------------------- - -REM Umgebung setzen -set PLATZ_CFG=%PLATZ%\cfg -set PLATZ_LIBS=%PLATZ%\libs -set PLATZ_WORK=%PLATZ%\work - -set PATH=%PYTHONSHELL%;%PATH% - -REM Wo sind die Pythonskripte ? -set PYTHONPATH=%PLATZ_LIBS% - -REM Startet das Sitzplatzprogramm -python %PLATZ_LIBS%\platz.py diff --git a/bin/setenv.bat b/bin/setenv.bat new file mode 100644 index 0000000..e16dd63 --- /dev/null +++ b/bin/setenv.bat @@ -0,0 +1,35 @@ +@echo off +REM ------------------------------------- +REM Wo ist das Programm hinkopiert +for %%I in ("%~dp0..") do set PLATZ=%%~fI +echo %PLATZ% +REM ------------------------------------- + +REM Umgebung setzen +set PLATZ_BIN=%PLATZ%\bin +set PLATZ_CFG=%PLATZ%\cfg +set PLATZ_LIBS=%PLATZ%\libs +set PLATZ_WORK=%PLATZ%\work +set PLATZ_IN=%PLATZ%\in +set PLATZ_OUT=%PLATZ%\out + +REM Wo sind die Pythonskripte ? +if "%PYTHONPATH%"=="" ( + set PYTHONPATH=%PLATZ_LIBS% +) else ( + echo %PYTHONPATH% | find /I "%PLATZ_LIBS%" > nul + if errorlevel 1 set PYTHONPATH=%PYTHONPATH%;%PLATZ_LIBS% +) + +if not exist "%PLATZ_WORK%" mkdir "%PLATZ_WORK%" +if not exist "%PLATZ_OUT%" mkdir "%PLATZ_OUT%" + +echo PLATZ=%PLATZ% +echo PLATZ_BIN=%PLATZ_BIN% +echo PLATZ_CFG=%PLATZ_CFG% +echo PLATZ_LIBS=%PLATZ_LIBS% +echo PLATZ_WORK=%PLATZ_WORK% +echo PLATZ_IN=%PLATZ_IN% +echo PLATZ_OUT=%PLATZ_OUT% +echo PYTHONPATH=%PYTHONPATH% + diff --git a/bin/setenv.sh b/bin/setenv.sh new file mode 100644 index 0000000..33fad87 --- /dev/null +++ b/bin/setenv.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# ------------------------------------- +# Wo ist das Programm hinkopiert +export PLATZ="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +echo $PLATZ +# ------------------------------------- + +# Umgebung setzen +export PLATZ_BIN=$PLATZ/bin +export PLATZ_CFG=$PLATZ/cfg +export PLATZ_LIBS=$PLATZ/libs +export PLATZ_WORK=$PLATZ/work +export PLATZ_IN=$PLATZ/in +export PLATZ_OUT=$PLATZ/out + +# Wo sind die Pythonskripte ? +case ":$PYTHONPATH:" in + *":$PLATZ_LIBS:"*) ;; + *) export PYTHONPATH=$PYTHONPATH:$PLATZ_LIBS ;; +esac + +mkdir -p "$PLATZ_WORK" +mkdir -p "$PLATZ_OUT" + +echo PLATZ=$PLATZ +echo PLATZ_BIN=$PLATZ_BIN +echo PLATZ_CFG=$PLATZ_CFG +echo PLATZ_LIBS=$PLATZ_LIBS +echo PLATZ_WORK=$PLATZ_WORK +echo PLATZ_IN=$PLATZ_IN +echo PLATZ_OUT=$PLATZ_OUT +echo PYTHONPATH=$PYTHONPATH diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..00b347d --- /dev/null +++ b/requirements.txt @@ -0,0 +1,8 @@ +# Python-Abhaengigkeiten fuer platz +# +# Aktuell werden nur Module aus der Standardbibliothek verwendet +# (ConfigParser, xml.dom.minidom, sets, UserList, random, ...). +# Keine externen Pakete erforderlich. +# +# Beispiel: +# requests==2.31.0