@@ -15,6 +15,12 @@ DOCKER_COMPOSE_BUNDLE_REF=${BUNDLE_REF:-main}
1515STOP_REGISTRY_IMPORTER_DIR=" ./stop-registry-importer"
1616STOP_REGISTRY_VENV_DIR=" ${STOP_REGISTRY_IMPORTER_DIR} /.venv-stop-registry"
1717STOP_REGISTRY_REQUIREMENTS_FILE=" ${STOP_REGISTRY_IMPORTER_DIR} /requirements.txt"
18+ STOP_REGISTRY_REQUIREMENTS_IN_FILE=" ${STOP_REGISTRY_IMPORTER_DIR} /requirements.in"
19+
20+ # Python/pip executables inside the stop-registry virtualenv. These are
21+ # populated by `ensure_python_venv` so that every Python-related command uses
22+ # the correct interpreter and isolated environment.
23+ STOP_REGISTRY_VENV_PYTHON=" ${STOP_REGISTRY_VENV_DIR} /bin/python"
1824
1925# Define a Docker Compose project name to distinguish
2026# the docker environment of this project from others
@@ -62,6 +68,11 @@ print_usage() {
6268 python:setup
6369 Creates/updates Python virtualenv for stop-registry importer and installs dependencies.
6470
71+ python:update-reqs
72+ Recompiles stop-registry-importer/requirements.txt from requirements.in using
73+ pip-tools (pip-compile). Run this after changing requirements.in. You must run python:setup
74+ to install the updated dependencies after review.
75+
6576 stop
6677 Stop the dependencies and the dockerized application.
6778
@@ -260,12 +271,49 @@ upload_zones() {
260271}
261272
262273setup_python () {
274+ ensure_python_venv
275+
276+ echo " Installing dependencies from ${STOP_REGISTRY_REQUIREMENTS_FILE} ..."
277+ " $STOP_REGISTRY_VENV_PYTHON " -m pip install -r " $STOP_REGISTRY_REQUIREMENTS_FILE "
278+ }
279+
280+ # Ensures the stop-registry virtualenv exists and that pip is up to date.
281+ #
282+ # This is the common entry point for all Python commands: it guarantees that
283+ # subsequent calls to "$STOP_REGISTRY_VENV_PYTHON" use the correct interpreter
284+ # and isolated environment regardless of the host Python setup.
285+ ensure_python_venv () {
263286 if [ ! -d " $STOP_REGISTRY_VENV_DIR " ]; then
287+ echo " Creating Python virtualenv in ${STOP_REGISTRY_VENV_DIR} ..."
264288 python3 -m venv " $STOP_REGISTRY_VENV_DIR "
265289 fi
266290
267- " $STOP_REGISTRY_VENV_DIR /bin/pip" install --upgrade pip
268- " $STOP_REGISTRY_VENV_DIR /bin/pip" install -r " $STOP_REGISTRY_REQUIREMENTS_FILE "
291+ if [ ! -x " $STOP_REGISTRY_VENV_PYTHON " ]; then
292+ echo " ERROR: Python executable not found in virtualenv: ${STOP_REGISTRY_VENV_PYTHON} " >&2
293+ echo " Try removing ${STOP_REGISTRY_VENV_DIR} and running 'python:setup' again." >&2
294+ exit 1
295+ fi
296+
297+ " $STOP_REGISTRY_VENV_PYTHON " -m pip install --upgrade pip
298+ }
299+
300+ # Recompiles requirements.txt from requirements.in using pip-tools and installs
301+ # the resolved dependency set into the virtualenv.
302+ update_python_requirements () {
303+ ensure_python_venv
304+
305+ if [ ! -f " $STOP_REGISTRY_REQUIREMENTS_IN_FILE " ]; then
306+ echo " ERROR: requirements input file not found: ${STOP_REGISTRY_REQUIREMENTS_IN_FILE} " >&2
307+ exit 1
308+ fi
309+
310+ " $STOP_REGISTRY_VENV_PYTHON " -m pip install --upgrade pip-tools
311+
312+ echo " Compiling ${STOP_REGISTRY_REQUIREMENTS_FILE} from ${STOP_REGISTRY_REQUIREMENTS_IN_FILE} ..."
313+ " $STOP_REGISTRY_VENV_PYTHON " -m piptools compile \
314+ --strip-extras \
315+ --output-file " $STOP_REGISTRY_REQUIREMENTS_FILE " \
316+ " $STOP_REGISTRY_REQUIREMENTS_IN_FILE "
269317}
270318
271319# ## Control flow
@@ -301,6 +349,10 @@ case $COMMAND in
301349 setup_python
302350 ;;
303351
352+ python:update-reqs)
353+ update_python_requirements
354+ ;;
355+
304356 stop)
305357 stop
306358 ;;
0 commit comments