Skip to content

Commit

Permalink
Add pre-commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Delgan committed Jun 19, 2022
1 parent 6592c64 commit ae3ed2c
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 26 deletions.
30 changes: 30 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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-added-large-files
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.3.0
hooks:
- id: pretty-format-ini
args: [--autofix]
- id: pretty-format-yaml
args: [--autofix, --indent, '2']
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
- repo: https://github.com/ambv/black
rev: 22.3.0
hooks:
- id: black
args: [-l, '100', --target-version, py35]
- repo: https://github.com/pycqa/flake8
rev: 4.0.1
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear
- pep8-naming
34 changes: 20 additions & 14 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ An ideal bug report includes:
Implementing changes
--------------------

If you are willing to enhance `Loguru` by implementing non-trivial changes, please `open a new issue`_ first to keep a reference about why such modifications are made (and potentially avoid unneeded work). Then, the workflow would look as follows:
If you are willing to enhance `Loguru` by implementing non-trivial changes, please `open a new issue`_ first to keep a reference about why such modifications are made (and potentially avoid unneeded work).

1. Fork the `Loguru`_ project from GitHub
Prefer using a relatively recent Python version as some dependencies required for development may have dropped support for oldest Python versions. Then, the workflow would look as follows:

1. Fork the `Loguru`_ project from GitHub.
2. Clone the repository locally::

$ git clone git@github.com:your_name_here/loguru.git
Expand All @@ -42,28 +44,32 @@ If you are willing to enhance `Loguru` by implementing non-trivial changes, plea
$ python -m virtualenv env
$ source env/bin/activate

4. Create a new branch from ``master``::
4. Install `Loguru` in development mode::

$ pip install -e ".[dev]"

5. Install pre-commit hooks that will check your commits::

$ pre-commit install --install-hooks

6. Create a new branch from ``master``::

$ git checkout master
$ git branch fix_bug
$ git checkout fix_bug

5. Install `Loguru` in development mode::

$ pip install -e ".[dev]"

6. Implement the modifications wished. During the process of development, honor `PEP 8`_ as much as possible.
7. Add unit tests (don't hesitate to be exhaustive!) and ensure none are failing using::
7. Implement the modifications wished. During the process of development, honor `PEP 8`_ as much as possible.
8. Add unit tests (don't hesitate to be exhaustive!) and ensure none are failing using::

$ tox

8. Remember to update documentation if required
9. Update the ``CHANGELOG.rst`` file with what you improved
10. ``add`` and ``commit`` your changes, ``rebase`` your branch on ``master``, ``push`` your local project::
9. Remember to update documentation if required.
10. If your development modifies `Loguru` behavior, update the ``CHANGELOG.rst`` file with what you improved.
11. ``add`` and ``commit`` your changes, then ``push`` your local project::

$ git add .
$ git commit -m 'Add succinct explanation of what changed'
$ git rebase master
$ git push origin fix_bug

11. Finally, `open a pull request`_ before getting it merged!
12. If previous step failed due to the pre-commit hooks, fix reported errors and try again.
13. Finally, `open a pull request`_ before getting it merged!
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
extras_require={
"dev": [
# Setup.
"pre-commit==2.19.0 ; python_version>='3.7'",
"tox>=3.9.0",
# Testing framework.
"pytest>=4.6.2",
Expand All @@ -74,7 +75,7 @@
"Sphinx==5.0.1 ; python_version>='3.6'",
"sphinx-autobuild==2021.3.14 ; python_version>='3.6'",
"sphinx-rtd-theme==1.0.0 ; python_version>='3.6'",
"docutils==0.16",
"docutils==0.16 ; python_version>='3.6'",
]
},
python_requires=">=3.5",
Expand Down
26 changes: 15 additions & 11 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,29 @@ envlist = py{35,36,37,38,39,310,py3}
setenv = PYTHONPATH = {toxinidir}
extras = dev
commands =
flake8 --exit-zero loguru tests docs setup.py
pytest --cov loguru/ --cov-report xml --cov-report term-missing
pytest --cov loguru/ --cov-report=
coverage report -m
coverage xml

[testenv:format]
commands =
isort --profile black -l 100 loguru tests setup.py
black -l 100 loguru tests setup.py

[pytest]
addopts = -l
[isort]
line_length = 100
profile = black

[flake8]
max_line_length = 100
max_doc_length = 100
ignore =
* W503 # Line break before binary operator (PEP8 now recommend to break after binary operator)
* E203 # Whitespace before ":" in slices
W503 # Line break before binary operator (PEP8 now recommend to break after binary operator)
E203 # Whitespace before ":" in slices
exclude =
tests/exceptions/source


[pytest]
addopts = -l
testpaths =
tests


[mypy]
mypy_path = $MYPY_CONFIG_FILE_DIR/loguru

0 comments on commit ae3ed2c

Please sign in to comment.