Skip to content

Commit

Permalink
Manage pre-commit with Poetry in GitHub Actions
Browse files Browse the repository at this point in the history
https://github.com/pre-commit/mirrors-mypy/issues/3#issuecomment-547999959
pre-commit/pre-commit#880 (comment)

pre-commit runs mypy from an isolated virtualenv, so it requires a
duplicate list of Python requirements. Furthermore, these requirements
are installed by pip, which reduces compatibility with Poetry. Editable
installs require a setup.py, which is not present in Poetry projects.
The following error is seen:

```text
❯ pip install -e .

ERROR: File "setup.py" not found. Directory cannot be installed in
editable mode (A "pyproject.toml" file was found, but editable mode
currently requires a setup.py based build.)
```

There is no ideal solution to this problem. The simplest is to add
`language: system`, which means "you have to rely on whatever state the
user's machine is in" (https://github.com/pre-commit/mirrors-mypy/issues/3#issuecomment-547999959).
That's fine, and just requires an update to the GitHub Actions workflow
to install the Poetry project, as I do before running pytest.
  • Loading branch information
br3ndonland committed Oct 10, 2020
1 parent 8c9081d commit 84b25bc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
16 changes: 15 additions & 1 deletion .github/workflows/hooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,33 @@ on:
jobs:
pre-commit:
runs-on: ubuntu-latest
env:
POETRY_VIRTUALENVS_CREATE: false
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Set up Poetry cache for Python dependencies
uses: actions/cache@v2
if: startsWith(runner.os, 'Linux')
with:
path: ~/.cache/pypoetry
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
restore-keys: ${{ runner.os }}-poetry-
- name: Set up pre-commit cache
uses: actions/cache@v2
if: startsWith(runner.os, 'Linux')
with:
path: ~/.cache/pre-commit
key: ${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
restore-keys: ${{ runner.os }}-pre-commit-
- name: Install Poetry
run: |
curl -fsS -o get-poetry.py https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py
python get-poetry.py -y
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
- name: Install dependencies
run: python -m pip install pre-commit
run: poetry install --no-interaction -E fastapi
- name: Run pre-commit hooks
run: pre-commit run --all-files
3 changes: 1 addition & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ repos:
rev: v0.790
hooks:
- id: mypy
additional_dependencies:
- pytest-mock
language: system
- repo: https://github.com/prettier/prettier
rev: 2.1.2
hooks:
Expand Down

0 comments on commit 84b25bc

Please sign in to comment.