Skip to content

Add black formatter for Python code #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 15, 2020

Conversation

PokhodenkoSA
Copy link
Contributor

@PokhodenkoSA PokhodenkoSA commented Oct 3, 2020

black is "The Uncompromising Code Formatter".

  • Use the black badge in project's README.md for indicating the code style
  • Add GitHub Actions for black for check code style
  • Ignore versioneer.py because it is 3rd party file (see pyproject.toml)
  • Format all Python code with black (just black .)
  • Add ignoring revisions in blame so you can see meaningful blame info after global formatting commit
  • Update CONTRIBUTING.md for all developers to use black in everyday work

Usage is simple: black .

This PR should be merged, not squashed.

See black in pandas - https://pandas.pydata.org/pandas-docs/stable/development/contributing.html#python-pep8-black

@diptorupd
Copy link
Contributor

Black is good. The only thing about it that I do not like is the 88 char wide lines. But, I can live with it.

@PokhodenkoSA
Copy link
Contributor Author

Black is good. The only thing about it that I do not like is the 88 char wide lines. But, I can live with it.

Line width is configurable via --line-length.

@PokhodenkoSA
Copy link
Contributor Author

PokhodenkoSA commented Oct 5, 2020

Using this instruction we can format whole code with black and make git blame to show original authors for all formatted lines of code.

@oleksandr-pavlyk
Copy link
Contributor

I think it is best to run this tool after #93 is merged, to avoid creating extensive conflicts.

@PokhodenkoSA
Copy link
Contributor Author

@oleksandr-pavlyk Thank you for your attention.
I have plan about it. This PR is only demonstration of black possibilities.
I will reformat all in one commit and will add this commit to special file which will be used for ignoring commits during git blame and history.

@diptorupd diptorupd modified the milestones: beta10, gold Oct 8, 2020
This GitHub Action checks that code in pull request
is formatted with black.

See https://black.readthedocs.io/en/stable/github_actions.html
versioneer.py is not a part of the project.

Add pyproject.toml file with section [tool.black] and parameter
exclude = 'versioneer.py'. This file will be used by developers and
GitHub Actions for black.

Usign pyproject.toml allows use black like this: `black .`
Use black version 20.8b1 or branch [stable](https://github.com/psf/black/tree/stable)).

Command: black .
File .git-blame-ignore-revs contains a list of revisions to use for
ignoring in blame. Example:
$ git blame FILE --ignore-revs-file .git-blame-ignore-revs

Also you can configure git to automatically ignore revisions listed
in a file on every call to git blame:
$ git config blame.ignoreRevsFile .git-blame-ignore-revs

Requirements: Git >=2.23
@PokhodenkoSA PokhodenkoSA merged commit 519312f into IntelPython:master Oct 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants