Skip to content

Commit

Permalink
Bundle tox categories into tox -e test and tox -e format-and-lint (
Browse files Browse the repository at this point in the history
…#151)

* Bundle the lint- and test-categories in tox

* Update the discussion of tox

* Update the pre-commit hook versions

* Explain why doc-dependencies are in a separate file

* Discuss tox and pre-commit versions in the dev docs

* Fix the doc-build
  • Loading branch information
pnkraemer authored Apr 23, 2024
1 parent 127f8d8 commit b09cc13
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 52 deletions.
22 changes: 6 additions & 16 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,11 @@ jobs:
with:
python-version: "3.x"
- uses: actions/checkout@v4
- name: Lint with black through tox
- name: Lint through tox
run: |
pip install tox
tox -e black
- name: Lint with isort through tox
run: |
pip install tox
tox -e isort
- name: Lint with pylint through tox
run: |
pip install tox
tox -e pylint
tox -e format-and-lint
tests:

runs-on: ${{ matrix.os }}
Expand All @@ -42,14 +35,11 @@ jobs:
with:
python-version: "3.x"
- uses: actions/checkout@v4
- name: Run tests with pytest
run: |
pip install tox
tox -e py3
- name: Run doctests for python snippets in markdown files
- name: Run tests through tox
run: |
pip install tox
tox -e doctest
tox -e test
docs:
runs-on: ubuntu-latest
steps:
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ default_language_version:
python: python3
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-added-large-files
args: ['--maxkb=1000']
Expand All @@ -30,16 +30,16 @@ repos:
# exclude autogenerated files
exclude: /README\.rst$|\.pot?$
- repo: https://github.com/psf/black
rev: 24.1.0 # Make sure to use the same tag/version as specified in tox.ini.
rev: 24.4.0
hooks:
- id: black
language_version: python3
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1 # Make sure to use the same tag/version as specified in tox.ini.
rev: v5.10.1
hooks:
- id: isort
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.7.1
rev: 1.8.5
hooks:
- id: nbqa-black
additional_dependencies: [black==22.8.0]
Expand Down
16 changes: 13 additions & 3 deletions docs/source/docs_dev/continuous_integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,32 @@ Install `tueplots` with all ci-related dependencies via
```
pip install .[ci]
```


## Tox
Run all checks via
```
tox
```
or only run the tests via
```
tox -e pytest
tox -e test
```
or use tox (which also runs the linter, and the python-code-snippets in this readme).
or only run the linter via
```
tox
tox -e format-and-lint
```

## Pre-commit hook
The CI checks for compliance of the code with black and isort, and runs the tests and the notebooks.
To automatically satisfy the former, there is a pre-commit that can be used (do this once):
```
pip install pre-commit
pre-commit install
```
From then on, your code will be checked for isort and black compatibility automatically.


Both the pre-commit hook and tox point to isort, black, and so on.
We do our best to match their versions. If you run into version conflicts
between those two tools, please let us know!
46 changes: 17 additions & 29 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,56 +1,44 @@

[tox]
envlist = pytest, doctest, black, isort, pylint, docs
envlist = test, format-and-lint, docs
isolated_build = True

[testenv:pytest]
description = Executing tests with pytest
[testenv:test]
description = Execute all sorts of tests
deps =
pytest
pytest-cases
commands =
pytest {posargs}

[testenv:doctest]
description = Executing code snippets in readme with doctest
deps =
matplotlib
commands =
pytest {posargs}
python -m doctest docs/source/getting_started/application_icml2022.md
python -m doctest docs/source/getting_started/usage_example.md


[testenv:black]
description = Code linting with Black
[testenv:format-and-lint]
description = Lint the code with black, isort, and pylint
deps =
black
nbqa
commands =
black --check --diff .
nbqa black --check --diff .

[testenv:isort]
description = Sorting imports with isort
deps =
isort
nbqa
commands =
isort --check --diff .
nbqa isort --check --diff .

[testenv:pylint]
description = Linting (pylint)
deps =
pylint
ignore_errors = true
commands =
pylint tueplots --jobs=0
pylint tests --jobs=0 --disable="missing-function-docstring"
black --check --diff . --quiet
isort --check --diff . --quiet
nbqa black --check --diff . --quiet
nbqa isort --check --diff . --quiet
pylint tueplots --jobs=0 --score no
pylint tests --jobs=0 --disable="missing-function-docstring" --score no



[testenv:docs]
description = Build the HTML docs
passenv = HOME
deps =
# The doc-dependencies are separate because
# we need to be able to tell readthedocs where
# to find them (there is no access to tox).
-r {toxinidir}/docs/requirements-sphinx-build.txt
changedir = docs
allowlist_externals = make
Expand Down

0 comments on commit b09cc13

Please sign in to comment.