diff --git a/.github/workflows/flake8.yml b/.github/workflows/flake8.yml new file mode 100644 index 0000000..f383de9 --- /dev/null +++ b/.github/workflows/flake8.yml @@ -0,0 +1,29 @@ +name: Flake8 + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Set up Python 3.8 + uses: actions/setup-python@v4 + with: + python-version: '3.8' + + - name: Install pre-commit hooks + run: | + pip install pre-commit + pre-commit install --install-hooks + + - name: Code style check via pre-commit + run: | + pre-commit run --all-files diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..68827d5 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,14 @@ +# Configuration of checks run by pre-commit +# +# The tests are executed in the CI pipeline, +# see CONTRIBUTING.rst for further instructions. +# You can also run the checks directly at the terminal, e.g. +# +# $ pre-commit install +# $ pre-commit run --all-files +# +repos: +- repo: https://github.com/pycqa/flake8 + rev: '5.0.4' + hooks: + - id: flake8 diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index f9cf7f9..eb70db1 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -30,6 +30,39 @@ This way, your installation always stays up-to-date, even if you pull new changes from the Github repository. +Coding Convention +----------------- + +We follow the PEP8_ convention for Python code +and check for correct syntax with flake8_. +Exceptions are defined under the ``[flake8]`` section +in :file:`setup.cfg`. + +The checks are executed in the CI using `pre-commit`_. +You can enable those checks locally by executing:: + + pip install pre-commit # consider system wide installation + pre-commit install + pre-commit run --all-files + +Afterwards flake8_ is executed +every time you create a commit. + +You can also install flake8_ +and call it directly:: + + pip install flake8 # consider system wide installation + flake8 + +It can be restricted to specific folders:: + + flake8 audfoo/ tests/ + +.. _PEP8: http://www.python.org/dev/peps/pep-0008/ +.. _flake8: https://flake8.pycqa.org/en/latest/index.html +.. _pre-commit: https://pre-commit.com + + Building the Documentation -------------------------- diff --git a/setup.cfg b/setup.cfg index f933dec..d019314 100644 --- a/setup.cfg +++ b/setup.cfg @@ -38,7 +38,6 @@ setup_requires = [tool:pytest] addopts = - --flake8 --doctest-plus --cov=audplot --cov-fail-under=100 @@ -47,6 +46,12 @@ addopts = xfail_strict = true [flake8] -ignore = - W503 # math, https://github.com/PyCQA/pycodestyle/issues/513 - __init__.py F401 # ignore unused imports +exclude = + .eggs, + build, +extend-ignore = + # math, https://github.com/PyCQA/pycodestyle/issues/513 + W503, +per-file-ignores = + # ignore unused imports + __init__.py: F401, diff --git a/tests/requirements.txt b/tests/requirements.txt index e844817..6e530fc 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,7 +1,4 @@ -# To avoid https://github.com/tholo/pytest-flake8/issues/87 -flake8 <5.0.0 librosa pytest -pytest-flake8 pytest-doctestplus pytest-cov