Skip to content

Commit

Permalink
pre-commit and pre-commit-ci
Browse files Browse the repository at this point in the history
Add pre-commit and pre-commit-ci with the following hooks:

- black for formatting code.

For more info see `docs/developers.rst`.
  • Loading branch information
aucampia committed Jan 29, 2022
1 parent b1dc449 commit b2e124d
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 1 deletion.
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
ci:
# https://pre-commit.ci/#configuration
autoupdate_schedule: weekly
autofix_prs: false

repos:
- repo: https://github.com/psf/black
# WARNING: rev should be the same as in `black.toml`.
rev: 21.9b0
hooks:
- id: black
40 changes: 40 additions & 0 deletions docs/developers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,46 @@ Check types with `mypy <http://mypy-lang.org/>`_:
python -m mypy --show-error-context --show-error-codes rdflib
pre-commit and pre-commit ci
----------------------------

We have `pre-commit <https://pre-commit.com/>`_ configured with `black
<https://github.com/psf/black>`_ for formatting code.

Some useful commands for using pre-commit:

.. code-block:: bash
# Install pre-commit.
pip install --user --upgrade pre-commit
# Install pre-commit hooks, this will run pre-commit
# every time you make a git commit.
pre-commit install
# Run pre-commit on changed files.
pre-commit run
# Run pre-commit on all files.
pre-commit run --all-files
There is also two tox environments for pre-commit:

.. code-block:: bash
# run pre-commit on changed files.
tox -e precommit
# run pre-commit on all files.
tox -e precommitall
There is no hard requirement for pull requests to be processed with pre-commit (or the underlying processors), however doing this makes for a less noisy codebase with cleaner history.

We have enabled `https://pre-commit.ci/ <https://pre-commit.ci/>`_ and this can
be used to automatically fix pull requests by commenting ``pre-commit.ci
autofix`` on a pull request.

Using tox
---------------------

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[tool.black]
# WARNING: This should be the same as in `.pre-commit-config.yaml`.
required-version = "21.9b0"
line-length = "88"
skip-string-normalization = true
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ filterwarnings =
ignore:Code. pytest_mock_example_attribute_that_shouldnt_exist is not defined in namespace .*:UserWarning
# The below warning is a consequence of how pytest detects fixtures and how DefinedNamespace behaves when an undefined attribute is being accessed.
ignore:Code. _pytestfixturefunction is not defined in namespace .*:UserWarning

[isort]
profile = black
10 changes: 9 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
envlist =
py37,py38,py39,py310
py37,py38,py39,py310,precommit

[testenv]
setenv =
Expand Down Expand Up @@ -46,6 +46,14 @@ setenv =
commands =
sphinx-build -n -T -b html -d {envtmpdir}/doctrees docs docs/_build/html

[testenv:precommit{,all}]
skip_install = true
deps = pre-commit
passenv = HOMEPATH # needed on Windows
commands =
precommit: pre-commit run
precommitall: pre-commit run --all-files

[pytest]
# log_cli = true
# log_cli_level = DEBUG
Expand Down

0 comments on commit b2e124d

Please sign in to comment.