Skip to content

Pin Python venv and conda dependencies #30

Pin Python venv and conda dependencies

Pin Python venv and conda dependencies #30

name: Check Python venv virtual environment
on:
pull_request:
branches:
- main
# Only watch changes related to Python virtual environment venv
paths:
- 'requirements.txt'
- 'scripts/activatePythonEnvironment.sh'
- '.github/workflows/internal-check-python-venv-support.yml' # or when this file changed
jobs:
check-python-venv-environment:
runs-on: ubuntu-22.04
strategy:
matrix:
include:
- python: 3.12
steps:
- name: Checkout GIT Repository
uses: actions/checkout@v5
- name: (Python Setup) Use version ${{ matrix.python }} with venv environment management module
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python }}
cache: 'pip'
- name: Activate virtual environment using venv and check if the required packages were installed
env:
USE_VIRTUAL_PYTHON_ENVIRONMENT_VENV: "true"
# 1. Run the script under test to create, activate and install the virtual environment
# 2. Start with an overall check with pip
# 3. Run pip in dry-mode with full output first to get all infos and fail on missing packages.
# 4a. The leading exclamation mark tells the shell to invert the returned exit code.
# Failing because "Would install" is missing leads to a successful execution.
# 5b. Run pip in dry-run mode without installing or resolving dependencies
# 5c. Suppress all pip output (stderr)
# 5d. Check if pip *would install* anything using grep
# 5e. If there are missing dependencies and the environment is incomplete, fail with code 1 (indicates all requirements already satisfied)
# TODO remove:
# pip install --dry-run --ignore-installed --requirement "./requirements.txt"
# ! pip install --dry-run --no-deps --no-cache-dir --no-index --requirement "./requirements.txt" 2>/dev/null | grep -q "Would install"
run: |
./scripts/activatePythonEnvironment.sh
source .venv/bin/activate
echo "Currently activated environment: ${VIRTUAL_ENV}"
! pip install --dry-run --no-deps --ignore-installed --requirement requirements.txt 2>/dev/null