Skip to content

Commit

Permalink
Rephrase GitHub Actions in terms of Nox actions
Browse files Browse the repository at this point in the history
This reduces duplication of GitHub vs local/Nox CI actions by changing
the GitHub actions to call out to Nox.

That said, this is not a full-fledged embrace of the Nox way: Nox will
usually install dependencies in its own virtualenvs. However, these
would come in addition to Poetry's virtualenv, and we have not currently
set up caching for anything but the Poetry virtualenvs.

Work around this by setting up the appropriate Python versiion and
installing all the necesary dependencies in the Poetry virtualenv
(i.e. outside of Nox). We can then run Nox with --no-venv --no-install
to explicitly disable the Nox virtualenvs (which also disables the
Python version paramtetrization inside Nox).

For this to work, we also need to adjust our install_groups() helper in
noxfile.py to detect when it's running without Nox virtualenvs and skip
installation in this case.

In summary, this avoids an extra layer of virtualenvs and should also
retain the same useful caching of the Poetry virtualenvs, but at the
cost of running the Nox sessions in a slightly different way compared
to running Nox in your local development environment: We do Python
version parametrization and dependency installation the Github Actions +
Poetry way, and then only use Nox to abstract away the actual commands
run inside each CI action.

Time will tell if this creates too many issues to be worthwhile.
  • Loading branch information
jherland committed Jan 5, 2023
1 parent 406205a commit 486d485
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
22 changes: 9 additions & 13 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ jobs:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-poetry-tests-${{ hashFiles('poetry.lock') }}
- name: Install project
run: poetry install --no-interaction --sync --with=test
- name: Run tests
run: poetry run pytest
run: poetry install --no-interaction --sync --with=nox,test
- name: Run tests on Python ${{ matrix.python-version }}
run: poetry run nox --no-venv --no-install --non-interactive -s tests

mypy:
strategy:
Expand All @@ -47,9 +47,9 @@ jobs:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-poetry-mypy-${{ hashFiles('poetry.lock') }}
- name: Install project
run: poetry install --no-interaction --sync --with=mypy
- name: Run type-checking
run: poetry run mypy fawltydeps tests
run: poetry install --no-interaction --sync --no-root --only=nox,mypy
- name: Run Mypy on Python ${{ matrix.python-version }}
run: poetry run nox --no-venv --no-install --non-interactive -s mypy

lint:
strategy:
Expand All @@ -71,13 +71,9 @@ jobs:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-poetry-lint-${{ hashFiles('poetry.lock') }}
- name: Install project
run: poetry install --no-interaction --sync --with=lint
- name: Check formatting with Black
run: poetry run black . --check
- name: Run linter
run: poetry run pylint fawltydeps tests
- name: Run import sort checker
run: poetry run isort fawltydeps tests --check-only
run: poetry install --no-interaction --sync --no-root --only=nox,lint
- name: Run linters
run: poetry run nox --no-venv --no-install --non-interactive -s lint

# Inspiration for the CI setup:
# https://github.com/marketplace/actions/python-poetry-action
Expand Down
8 changes: 8 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ def install_groups(
Auto-skip the `poetry export` step if the poetry.lock file is unchanged
since the last time this session was run.
"""
if isinstance(session.virtualenv, nox.virtualenv.PassthroughEnv):
session.warn(
"Running outside a Nox virtualenv! We will skip installation here, "
"and simply assume that the necessary dependency groups have "
"already been installed by other means!"
)
return

lockdata = Path("poetry.lock").read_bytes()
digest = hashlib.blake2b(lockdata).hexdigest()
requirements_txt = Path(session.cache_dir, session.name, "reqs_from_poetry.txt")
Expand Down

0 comments on commit 486d485

Please sign in to comment.