Skip to content

Commit

Permalink
Add files for pre-commit configuration (pylint and black) (#2567)
Browse files Browse the repository at this point in the history
* add .pre-commit-config.yaml pyproject.toml

* version of black for pre-commit

* [skip ci]

* describe pre-commit in the docs

* exclude doc files; add installation notes

* change

* fix link, wording

* no new lines
  • Loading branch information
antalszava authored May 17, 2022
1 parent 6892a0c commit bcd837b
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
repos:
- repo: local
hooks:
- id: pylint
name: pylint
entry: pylint
language: system
types: [python]
args:
[
"-rn", # Only display messages
"-sn", # Don't display the score
"--rcfile=.pylintrc", # Link to your config file
]
exclude: ^(doc/|tests/)
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
exclude: ^doc/
language_version: python3.8
39 changes: 39 additions & 0 deletions doc/development/guide/pullrequests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,41 @@ merged.
* **Code factor**: `Code factor <https://www.codefactor.io/>`_ checks several common code quality
characteristics.

To make sure that the formatting and the quality of the new piece of code is up
to `PEP8 <https://www.python.org/dev/peps/pep-0008/>`_ dedicated tools
(``black`` and ``pylint``) should be run locally.

The PennyLane repository provides top-level files (``.pre-commit-config.yaml``
and a ``pyproject.toml``) for configuring `pre-commit
<https://pre-commit.com/>`_ to run ``black`` and ``pylint`` as a ``git``
pre-commit hook. Once configured, issuing ``git commit`` will run the tools
automatically. If any of the checks fail, committing fails too. A failed
``black`` check will reformat the required files. Running the pre-commit hook
mechanisms can be disabled for a commit by passing the ``-n/--no-verify``
option.

The ``pre-commit`` package can be installed e.g., via ``pip``:

.. code-block:: bash
pip install pre-commit
Then, it can be installed for a specific repository by running

.. code-block:: bash
pre-commit install
in the folder where the ``.pre-commit-config.yaml`` file exists (the top-level
folder for PennyLane).

.. note::

The ``.pre-commit-config.yaml`` file pins ``black`` to a specific version.
As new versions of ``black`` are released, developers will have to run
``pre-commit autoupdate`` to update the package versions used by
``pre-commit``.

* **Tests**: Github Actions runs the core tests and device tests for a series of different Python
versions and interface installations.

Expand All @@ -67,6 +102,10 @@ Using the "Search" toolbar on the top left of the generated website can help wit
or updated pages. New functions or classes that are available for users should appear as
search results.

Note that including ``skip ci`` (or a similar string) will mark a ``git commit``
such that `CI checks are being skipped
<https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs>`_.

Ready for review?
-----------------

Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[tool.black]
line-length = 100
include = 'pennylane\.pyi?$, tests\.pyi?$'

0 comments on commit bcd837b

Please sign in to comment.