Skip to content

Commit

Permalink
Introduce pre-commit to GitHub workflows.
Browse files Browse the repository at this point in the history
This adds a pre-commit step to the GitHub workflow. It replaces the
separate Black and Ruff runs, but does not fully replace MyPy.
  • Loading branch information
thetorpedodog committed May 10, 2023
1 parent f7c0894 commit 15cb29f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
17 changes: 14 additions & 3 deletions .github/workflows/python-somacore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,30 @@ jobs:
PYTHON_VERSION: "3.7"
steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: pip
cache-dependency-path: python-spec/requirements-py${{ env.PYTHON_VERSION }}-lint.txt
- uses: psf/black@stable

- name: Install static analysis packages
run: |
pip install -r python-spec/requirements-py${{ env.PYTHON_VERSION }}-lint.txt
- name: Restore pre-commit cache
uses: actions/cache@v3
with:
path: ~/.cache/pre-commit
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}

- name: Run mypy
run: mypy ./python-spec/src
- name: Run ruff
run: ruff .
# We maintain this full mypy step since running mypy in pre-commit is
# somewhat limited (cf. comments in .pre-commit-config.yaml).

- name: Pre-commit check
run: pre-commit run -a -v

run-tests:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repos:
# Then others in alphabetical order:

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.243
rev: v0.0.265
hooks:
- id: ruff

Expand Down
8 changes: 8 additions & 0 deletions python-spec/requirements-py3.7-lint.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
anndata==0.8.0
attrs==23.1.0
black==23.3.0
cfgv==3.3.1
click==8.1.3
distlib==0.3.6
filelock==3.12.0
h5py==3.8.0
identify==2.5.24
importlib-metadata==6.6.0
isort==5.11.5
llvmlite==0.39.1
mypy==1.2.0
mypy-extensions==1.0.0
natsort==8.3.1
nodeenv==1.7.0
numba==0.56.4
numpy==1.21.6
packaging==23.1
pandas==1.3.5
pathspec==0.11.1
platformdirs==3.5.0
pre-commit==2.21.0
pyarrow==12.0.0
python-dateutil==2.8.2
pytz==2023.3
PyYAML==6.0
ruff==0.0.265
scipy==1.7.3
six==1.16.0
tomli==2.0.1
typed-ast==1.5.4
typing_extensions==4.5.0
virtualenv==20.23.0
zipp==3.15.0
2 changes: 1 addition & 1 deletion python-spec/update-requirements-txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ CONDIR="$TEMPDIR/py-$LINTVER-lint"
conda create -y -p "$CONDIR" "python=$LINTVER"
(
conda activate "$CONDIR"
pip install .[dev] mypy
pip install .[dev] mypy pre-commit
mypy --install-types --non-interactive ./python-spec/src
pip freeze --exclude somacore >"./python-spec/requirements-py$LINTVER-lint.txt"
)

0 comments on commit 15cb29f

Please sign in to comment.