diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f8413309b1..0da4570790 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -44,62 +44,27 @@ jobs: pandoc-version: "2.9.2" - name: Install tox run: python -m pip install -U pip tox - - name: Set up virtualenv - # our tasks.py wants a virtualenv, so make one - # unfortunately, every step that uses it has to be split by - # platform, because activating it is different on unix and windows - if: runner.os != 'Windows' - run: python -m venv venv - - name: Set up virtualenv (windows) - if: runner.os == 'Windows' + - name: Set up dependencies with invoke run: | - python -m venv venv - if ($LASTEXITCODE -ne 0) { - Write-Host "Virtual environment creation failed: $LASTEXITCODE" - exit $LASTEXITCODE - } - $pwd - # dir venv\Scripts - - name: Set up dependencies with invoke (not windows) - if: runner.os != 'Windows' - run: | - source venv/bin/activate - python -m pip install invoke - python -m invoke setup - - name: Set up dependencies with invoke (windows) - if: runner.os == 'Windows' - run: | - $pwd - . venv\Scripts\activate - Import-Module venv python -m pip install invoke python -m invoke setup + echo "== PYTHON after setup ==" + python --version + python -c "import pytest" - name: Info run: | echo "===== PYTHON =====" python --version echo "===== PANDOC =====" pandoc --version | head -2 - - name: Run tests with coverage (not windows) - if: runner.os != 'Windows' + - name: Run tests with coverage run: | - source venv/bin/activate python -m pytest --cov=pelican ls -l .coverage.* env: # control the filename to avoid issues with uploading # see also https://github.com/actions/upload-artifact/issues/478#issuecomment-2096976037 COVERAGE_FILE: .coverage.${{ matrix.os }}.${{ matrix.python }}.${{ github.event_name }} - - name: Run tests with coverage (windows) - if: runner.os == 'Windows' - run: | - .\venv\bin\activate - python -m pytest --cov=pelican - env: - # control the filename to avoid issues with uploading - # see also https://github.com/actions/upload-artifact/issues/478#issuecomment-2096976037 - COVERAGE_FILE: .coverage.${{ matrix.os }}.${{ matrix.python }}.${{ github.event_name }} - - name: Upload coverage data uses: "actions/upload-artifact@v4" with: diff --git a/tasks.py b/tasks.py index 64409e20b8..39ca7282ec 100644 --- a/tasks.py +++ b/tasks.py @@ -1,4 +1,5 @@ import os +import sys from pathlib import Path from shutil import which @@ -15,9 +16,21 @@ VENV = str(VENV_PATH.expanduser()) VENV_BIN = Path(VENV) / Path(BIN_DIR) +PYTHON = which("python") + TOOLS = ["pdm", "pre-commit", "psutil"] -PDM = which("pdm") or VENV_BIN / "pdm" -PRECOMMIT = which("pre-commit") or VENV_BIN / "pre-commit" + + +def _get_pdm_path(): + return which("pdm") or VENV_BIN / "pdm" + + +def _get_precommit_path(): + return which("pre-commit") or VENV_BIN / "pre-commit" + + +def _get_coverage_path(): + return which("coverage") @task @@ -41,14 +54,14 @@ def docserve(c): @task def tests(c): """Run the test suite""" - c.run(f"{VENV_BIN}/pytest", pty=PTY) + c.run(f"{PYTHON} -m pytest", pty=PTY) @task def coverage(c): """Generate code coverage of running the test suite.""" - c.run(f"{VENV_BIN}/pytest --cov=pelican", pty=PTY) - c.run(f"{VENV_BIN}/coverage html", pty=PTY) + c.run(f"{PYTHON} -m pytest --cov=pelican", pty=PTY) + c.run(f"{PYTHON} -m coverage html", pty=PTY) @task @@ -87,20 +100,23 @@ def tools(c): """Install tools in the virtual environment if not already on PATH""" for tool in TOOLS: if not which(tool): - c.run(f"{VENV_BIN}/python -m pip install {tool}", pty=PTY) + c.run(f"{PYTHON} -m pip install {tool}", pty=PTY) @task def precommit(c): """Install pre-commit hooks to .git/hooks/pre-commit""" - c.run(f"{PRECOMMIT} install", pty=PTY) + precommt = _get_precommit_path() + c.run(f"{precommt} install", pty=PTY) @task def setup(c): - c.run(f"{VENV_BIN}/python -m pip install -U pip", pty=PTY) + c.run(f"{PYTHON} -m pip install -U pip", pty=PTY) tools(c) - c.run(f"{PDM} install", pty=PTY) + pdm = _get_pdm_path() + print(f"***** running {pdm} install", file=sys.stderr) # noqa: T201 + c.run(f"{pdm} install -v", pty=PTY, echo=True) precommit(c)