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

For more information, please see the following links:
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

JIRA: CWFHEALTH-2279
  • Loading branch information
FernandesMF committed Sep 18, 2023
1 parent 84635e2 commit 43318e3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
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
84635e2dd3fd26f1c63ff50c854890a9d04e83b3
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.
7 changes: 6 additions & 1 deletion 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,11 @@ skip_install = true
deps = flake8
commands = flake8

[testenv:black]
basepython = python3
deps = black
commands = black --line-length 100 --check freshmaker tests --exclude freshmaker/migrations/

[testenv:mypy]
description = type check
deps =
Expand Down

0 comments on commit 43318e3

Please sign in to comment.