Skip to content

Commit

Permalink
ci(github): Run pre-commit in github actions
Browse files Browse the repository at this point in the history
- Configure github actions to run pre-commit on the repo to check
style, etc.
- Update to stable/new versions of hooks to avoid spurious failures from
upstream updates.
- Flag a few imports in tests and examples with NOQA.  This is to avoid
bugs in isort.  In particular, isort is environment dependent.

    PyCQA/isort#1147
    PyCQA/isort#952
    PyCQA/isort#1007

- Disable one flake8 lint: 501, line too long
  • Loading branch information
musoke committed Mar 9, 2020
1 parent 99a464f commit 16cfe3b
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 9 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# https://github.com/pre-commit/action
# Run all pre-commit lints

name: pre-commit

on:
- push
- pull_request

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
- name: set PY
run: echo "::set-env name=PY::$(python --version --version | sha256sum | cut -d' ' -f1)"
- uses: actions/cache@v1
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
- uses: pre-commit/action@v1.0.1
7 changes: 3 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
rev: v2.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/psf/black
rev: stable
rev: 19.10b0
hooks:
- id: black

- repo: https://github.com/timothycrosley/isort
rev: 4.3.21-2
rev: 4.3.21
hooks:
- id: isort
types: ['python']

- repo: https://gitlab.com/pycqa/flake8
rev: '3.7.9' # pick a git hash / tag to point to
Expand Down
3 changes: 2 additions & 1 deletion examples/example_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import matplotlib.pyplot as plt # type: ignore
import numpy as np # type: ignore

from learn_as_you_go.emulator import emulator
# TODO: remove NOQA when isort is fixed
from learn_as_you_go.emulator import emulator # NOQA


def main():
Expand Down
3 changes: 2 additions & 1 deletion examples/example_emcee.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import numpy as np # type: ignore

from learn_as_you_go.emulator import emulator
# TODO: remove NOQA when isort is fixed
from learn_as_you_go.emulator import emulator # NOQA


def main():
Expand Down
8 changes: 8 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
[tool:pytest]
python_files = test_*.py *_test.py testing/*/*.py example_*.py
python_functions = test_* example_*

[flake8]
ignore =
# line too long
E501,

[tool:isort]
known_first_party=learn_as_you_go
3 changes: 2 additions & 1 deletion tests/test_check_good.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import numpy as np # type: ignore
import pytest # type: ignore

from learn_as_you_go.emulator import check_good
# TODO: remove NOQA when isort is fixed
from learn_as_you_go.emulator import check_good # NOQA


@pytest.mark.parametrize("test_input", [0, 1, 1.0, np.array(1.0)])
Expand Down
3 changes: 2 additions & 1 deletion tests/test_emulator_accuracy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import numpy as np # type: ignore
import pytest # type: ignore

from learn_as_you_go.emulator import emulator
# TODO: remove NOQA when isort is fixed
from learn_as_you_go.emulator import emulator # NOQA

DEFAULT_ABS_ERR = 0.05
DEFAULT_REL_ERR = 1.0
Expand Down
3 changes: 2 additions & 1 deletion tests/test_train_threshold.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import numpy as np # type: ignore
import pytest # type: ignore

from learn_as_you_go.emulator import emulator
# TODO: remove NOQA when isort is fixed
from learn_as_you_go.emulator import emulator # NOQA


@pytest.mark.xfail
Expand Down

0 comments on commit 16cfe3b

Please sign in to comment.