Skip to content

Commit

Permalink
TST: use pre-commit for flake8 checks (#56)
Browse files Browse the repository at this point in the history
* TST: use pre-commit for flake8 checks

* Fix remove pytest-flake8

* Update setup.cfg
  • Loading branch information
hagenw authored Jan 4, 2023
1 parent b81ccfd commit 41ec0a5
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 7 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/flake8.yml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
33 changes: 33 additions & 0 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------------------

Expand Down
13 changes: 9 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ setup_requires =

[tool:pytest]
addopts =
--flake8
--doctest-plus
--cov=audplot
--cov-fail-under=100
Expand All @@ -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,
3 changes: 0 additions & 3 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 41ec0a5

Please sign in to comment.