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 <noreply@anthropic.com>
This commit is contained in:
@@ -2,3 +2,7 @@
|
|||||||
__pycache__/
|
__pycache__/
|
||||||
*.pyo
|
*.pyo
|
||||||
work/ausgabe.txt
|
work/ausgabe.txt
|
||||||
|
.venv/
|
||||||
|
out/
|
||||||
|
.vscode/
|
||||||
|
*.swp
|
||||||
|
|||||||
@@ -13,22 +13,31 @@ result to text/CSV output files.
|
|||||||
**This is Python 2 code** (print statements, `ConfigParser`, `sets.Set`, `UserList`,
|
**This is Python 2 code** (print statements, `ConfigParser`, `sets.Set`, `UserList`,
|
||||||
`string.split`, old-style `raise Exception, "msg"`, `xrange`, `dict.has_key`,
|
`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
|
`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
|
build system, test suite, or linter configured in this repo. `requirements.txt` exists but
|
||||||
interpreter with only the standard library is sufficient to run it.
|
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
|
## Running the program
|
||||||
|
|
||||||
Entry point is `libs/platz.py`, invoked via the wrapper scripts in `bin/`, which set up
|
Entry point is `libs/platz.py`, invoked via the scripts in `bin/` (each provided as a
|
||||||
environment variables and `PYTHONPATH` before calling it — the scripts never take a script
|
`.bat`/`.sh` pair, following the "Standard Programm Template" convention — see
|
||||||
argument, they just launch `platz.py`:
|
`~/.claude/CLAUDE.md` for the template rules):
|
||||||
|
|
||||||
- `bin/run` (bash, for Linux/macOS) — hardcodes `PLATZ=/Users/sm/develop/python/platz`
|
- `bin/setenv.bat` / `bin/setenv.sh` — derives `PLATZ` from the script's own location (no
|
||||||
- `bin/run.bat` (Windows) — hardcodes `PLATZ=h:\develop\python\platz` and a Python 2.4 interpreter path
|
path editing needed), sets `PLATZ_BIN`, `PLATZ_CFG`, `PLATZ_LIBS`, `PLATZ_WORK`,
|
||||||
|
`PLATZ_IN`, `PLATZ_OUT`, adds `PLATZ_LIBS` to `PYTHONPATH` (idempotently), and creates
|
||||||
Both scripts set `PLATZ_CFG`, `PLATZ_LIBS`, `PLATZ_WORK` and add `PLATZ_LIBS` to
|
missing folders. Sourced by every other script; not normally invoked directly. The `.sh`
|
||||||
`PYTHONPATH`, then run `python $PLATZ_LIBS/platz.py`. **The hardcoded paths at the top of
|
variant must be sourced (`source bin/setenv.sh`), not executed.
|
||||||
these scripts must be edited to match wherever this repo is actually checked out** before
|
- `bin/install_py.bat` / `bin/install_py.sh` — calls `setenv`, then creates `.venv` (via
|
||||||
they will work.
|
`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`
|
Configuration is driven by `cfg/platz.cfg`, which points (via `$PLATZ_CFG`/`$PLATZ_WORK`
|
||||||
env-var expansion) to:
|
env-var expansion) to:
|
||||||
|
|||||||
@@ -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`,
|
**This is Python 2 code** (print statements, `ConfigParser`, `sets.Set`, `UserList`,
|
||||||
`string.split`, old-style `raise Exception, "msg"`, `xrange`, `dict.has_key`,
|
`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
|
`dict.iteritems`). There are no third-party dependencies (standard library only), so
|
||||||
(standard library only).
|
`requirements.txt` is empty — it exists only so `bin/install_py` has something to install.
|
||||||
|
|
||||||
## Project structure
|
## Project structure
|
||||||
|
|
||||||
```
|
```
|
||||||
platz/
|
platz/
|
||||||
├── bin/ # launcher scripts (bash + Windows batch)
|
├── bin/ # environment + launcher scripts (.bat + .sh pairs)
|
||||||
├── cfg/ # GA cycle definition and penalty scheme
|
├── cfg/ # GA cycle definition and penalty scheme
|
||||||
├── libs/ # the two Python modules (ga.py, Strukturdaten.py, platz.py)
|
├── libs/ # the two Python modules (ga.py, Strukturdaten.py, platz.py)
|
||||||
└── work/ # per-run input (table layout, guest list) and output
|
└── work/ # per-run input (table layout, guest list) and output
|
||||||
@@ -29,29 +29,48 @@ platz/
|
|||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
1. Install a Python 2 interpreter (2.4+; no `pip install` needed, standard library only).
|
1. Install a Python interpreter (`py` on Windows / `python3` on Linux/macOS must be on
|
||||||
2. Edit the hardcoded paths at the top of the launcher script for your platform:
|
`PATH`).
|
||||||
- `bin/run` (bash): `PLATZ=/Users/sm/develop/python/platz`
|
2. Run the installer for your platform to create a `.venv` and install `requirements.txt`:
|
||||||
- `bin/run.bat` (Windows): `PLATZ=h:\develop\python\platz` and `PYTHONSHELL=l:\tools\i486_nt\python24`
|
|
||||||
|
|
||||||
Point `PLATZ` at wherever you checked out this repository.
|
|
||||||
|
|
||||||
## Running
|
|
||||||
|
|
||||||
From a shell:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Linux/macOS
|
|
||||||
source bin/run
|
|
||||||
```
|
|
||||||
|
|
||||||
```bat
|
```bat
|
||||||
:: Windows
|
:: Windows
|
||||||
bin\run.bat
|
bin\install_py.bat
|
||||||
```
|
```
|
||||||
|
|
||||||
The launcher sets `PLATZ_CFG`, `PLATZ_LIBS`, `PLATZ_WORK`, adds `PLATZ_LIBS` to
|
```bash
|
||||||
`PYTHONPATH`, and runs `libs/platz.py`.
|
# 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
|
||||||
|
|
||||||
|
```bat
|
||||||
|
:: Windows
|
||||||
|
bin\activate_venv.bat
|
||||||
|
bin\platz.bat
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Linux/macOS
|
||||||
|
source bin/activate_venv.sh
|
||||||
|
bin/platz.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
`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`.
|
||||||
|
|
||||||
|
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
|
### Configuring a run
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -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%"
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# ================================================================
|
||||||
|
# Shell mit gesetzten Umgebungsvariablen oeffnen
|
||||||
|
# ================================================================
|
||||||
|
|
||||||
|
source "$(dirname "${BASH_SOURCE[0]}")/setenv.sh"
|
||||||
|
exec "$SHELL"
|
||||||
@@ -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!
|
||||||
|
)
|
||||||
|
|
||||||
@@ -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
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
@echo off
|
||||||
|
REM ================================================================
|
||||||
|
REM Startet das Sitzplatzprogramm
|
||||||
|
REM ================================================================
|
||||||
|
|
||||||
|
call "%~dp0setenv.bat"
|
||||||
|
|
||||||
|
python "%PLATZ_LIBS%\platz.py"
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# ================================================================
|
||||||
|
# Startet das Sitzplatzprogramm
|
||||||
|
# ================================================================
|
||||||
|
|
||||||
|
source "$(dirname "${BASH_SOURCE[0]}")/setenv.sh"
|
||||||
|
|
||||||
|
python "$PLATZ_LIBS/platz.py"
|
||||||
@@ -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
|
|
||||||
-21
@@ -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
|
|
||||||
@@ -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%
|
||||||
|
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
Reference in New Issue
Block a user