Skip to content

Commit

Permalink
Introduce auto-formatters (ics-py#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
C4ptainCrunch authored Aug 18, 2022
1 parent 133a095 commit c7a48d3
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
26 changes: 26 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-case-conflict
- id: mixed-line-ending
- repo: https://github.com/asottile/pyupgrade
rev: v2.34.0
hooks:
- id: pyupgrade
args: [--py37-plus]
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 22.6.0
hooks:
- id: black
- repo: https://github.com/asottile/blacken-docs
rev: v1.12.1
hooks:
- id: blacken-docs
additional_dependencies: [black==22.6.0]
45 changes: 43 additions & 2 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,49 @@ work.
Style guide
-----------

* Code formatting: `TBD <https://github.com/ics-py/ics-py/issues/344>`_
* Docstrings: `Google Python Style Guide <https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings>`_
Pre-commit checks
^^^^^^^^^^^^^^^

`pre-commit <https://pre-commit.com>`_ is a framework for managing pre-commit
hooks. These hooks help to identify simple issues before committing code for
review. By checking for these issues before code review it allows the reviewer
to focus on the change itself, and it can also help to reduce the number of CI
runs.

To use the tool, first install ``pre-commit`` and then the git hooks:

.. console::

$ python -m pip install pre-commit
$ pre-commit install

On the first commit ``pre-commit`` will install the hooks, these are
installed in their own environments and will take a short while to
install on the first run. Subsequent checks will be significantly faster.
If an error is found an appropriate error message will be displayed.
If the error was with ``black`` or ``isort`` then the tool will go ahead and
fix them for you. Review the changes and re-stage for commit if you are happy
with them.

Code formatting
^^^^^^^^^^^^^^^

* All files should be formatted using the
`black <https://black.readthedocs.io/en/stable/>`_ auto-formatter. This will be
run by ``pre-commit`` if that is configured.
* Use `isort <https://github.com/PyCQA/isort#readme>`_ to automate import sorting.
This will be run by ``pre-commit`` if that is configured.
* String variable interpolation may use
%-formatting, f-strings or ``str.format`` as appropriate, with the goal of
maximizing code readability. In case of doubt, use f-strings.

Docstrings
^^^^^^^^^^

The style to be used in docstrings is still discussed in
`Issue 344 <https://github.com/ics-py/ics-py/issues/344>`_.
In the meantime, you can take inspiration from the
`Google Python Style Guide <https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings>`_.

How to submit an issue
----------------------
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@ checks = [
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.isort]
profile = "black"

0 comments on commit c7a48d3

Please sign in to comment.