Skip to content

Commit

Permalink
Add black formatting in tox + rev ignore in git blame
Browse files Browse the repository at this point in the history
As part of our effort to standardize our project repos, we are adding
black formatting to freshmaker in tox.

This commit:
    - adds a step with `black --check` in tox, to verify the code is
      well formatted
    - adds a `.git-blame-ignore-revs` file to keep track of large
      reformatting commits that should be ignored by `git blame`
    - adds instructions on how to use `.git-blame-ignore-revs`
      automatically in a local environment
    - add E203 to flake8 ignores, to prevent conflicts with black's style

For more information, please see the following links:
https://black.readthedocs.io/en/stable/guides/introducing_black_to_your_project.html
https://akrabat.com/ignoring-revisions-with-git-blame/
https://stackoverflow.com/questions/34957237/can-i-configure-git-blame-to-always-ignore-certain-commits-want-to-fix-git-blam/57129540#57129540
https://docs.github.com/en/repositories/working-with-files/using-files/viewing-a-file#ignore-commits-in-the-blame-view

JIRA: CWFHEALTH-2279
  • Loading branch information
FernandesMF committed Sep 21, 2023
1 parent e306144 commit c4b864f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Have a look at
# https://stackoverflow.com/questions/34957237/can-i-configure-git-blame-to-always-ignore-certain-commits-want-to-fix-git-blam/57129540#57129540
# https://akrabat.com/ignoring-revisions-with-git-blame/
# https://docs.github.com/en/repositories/working-with-files/using-files/viewing-a-file#ignore-commits-in-the-blame-view

# Run code through black for formatting
e3061441e1492f44386d10b1c6426162e6d0c81c
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,23 @@ python -m pip install pip-tools
```

more info available at: https://github.com/jazzband/pip-tools/


# Ignoring large reformattings with git blame

The commits listed in `.git-blame-ignore-revs` are automatically ignored in github blame view
(https://docs.github.com/en/repositories/working-with-files/using-files/viewing-a-file#ignore-commits-in-the-blame-view).
This feature is meant to ignore commits that just introduced reformatting, and maintain the logical
contributions of each line.

You can make use of the `.git-blame-ignore-revs` file locally by passing it as an argument to the
blame command:
```
git blame --ignore-revs-file .git-blame-ignore-revs ...
```
or by adding it to your local git configurations:
```
git config --local blame.ignoreRevsFile .git-blame-ignore-revs
```
Note that this should be done for per-project, as some projects may lack the `.git-blame-ignore-revs`
file, and in this case `git blame` would return an error.
10 changes: 8 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# and then run "tox" from this directory.

[tox]
envlist = bandit, docs, flake8, mypy, py311
envlist = bandit, docs, flake8, black, mypy, py311
ignore_base_python_conflict = True

[testenv]
Expand All @@ -30,6 +30,12 @@ skip_install = true
deps = flake8
commands = flake8

[testenv:black]
basepython = python3
deps = black
commands = black --line-length 100 --check . \
--extend-exclude="dev_scripts\/|freshmaker\/migrations\/|\.tox\/|build\/|__pycache__|scripts\/print_handlers_md\.py|\.copr\/|\.env"

[testenv:mypy]
description = type check
deps =
Expand All @@ -51,7 +57,7 @@ ignore_outcome = True

[flake8]
skip_install = true
ignore = E501,E731,W503,W504
ignore = E501,E731,W503,W504,E203
exclude = dev_scripts/*,freshmaker/migrations/*,.tox/*,build/*,__pycache__,scripts/print_handlers_md.py,.copr/*,.env

[testenv:docs]
Expand Down

0 comments on commit c4b864f

Please sign in to comment.