Skip to content
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

Switch to using black for code formatting #6361

Merged
merged 6 commits into from
May 5, 2021

Conversation

mtreinish
Copy link
Member

Summary

This PR migrates the qiskit-terra repo to use black for code formatting. It replaces our usage of
pycodestyle for code style enforcement. This removes any questions or uncertainty around code formatting as black is
automated and formats the code for us in consistent style. Contributors simply just need to run black locally and the code will
be updated to use a consistent formatting.

This PR runs black on the entire repository (hence the gigantic diff) and updates the CI and local lint configurations to run black
in check mode instead of pycodestyle.

Details and comments

This PR builds on the work done by @levbishop in #6032 and #5883 but also adds the necessary CI configuration and documentation to the contributing guide. It also runs black on the current state of the repository.

levbishop and others added 6 commits May 5, 2021 07:30
This commit updates the CI configuration and local tox configuration to
leverage black instead of pycodestyle. It adds a check job to ci and the
tox lint job so we can quickly check if black has been run. A tox job
named 'black' is added to run black on all the code in the repo.
This commit reformats all the code in the qiskit-terra repository to use
black. It changes no functionality in the project and just adjusts the
code formatting to be consistent and automated. If you are looking at
this commit in the git log you can likely safely ignore any diff from
this commit as it is just the result of running '`black' on the repo
and instead you should look at any commits before or after this for
functional changes.
Copy link
Member

@ajavadia ajavadia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me


## Style and lint

Qiskit Terra uses 2 tools for verify code formatting and lint checking. The
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather phase out the name Terra from docs that users see - just saying Qiskit (especially as black will likely be done in other repos too).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can clean this up later, I was planning to update the overall contributing documentation when we've unified on using black everywhere: https://qiskit.org/documentation/contributing_to_qiskit.html#style-guide right now it just says pycodestyle and pylint

@mtreinish mtreinish merged commit 2eee566 into Qiskit:main May 5, 2021
@mtreinish mtreinish deleted the black-everything branch May 5, 2021 13:53
mtreinish added a commit to mtreinish/qiskit-core that referenced this pull request May 5, 2021
This commit adds a new file with the SHA1 of commits to ignore when
running git blame. This is important because of the recent adoption of
black as our code formatting tool in Qiskit#6361 we caused a large amount of
code churn to change the code formatting. However using the ignore file
is a local opt-in feature for git and not something we can enable
globally by default. To facilitate this a section is added to the bottom
of the contributing guide to document how this file can be used.
mergify bot pushed a commit that referenced this pull request May 5, 2021
This commit adds a new file with the SHA1 of commits to ignore when
running git blame. This is important because of the recent adoption of
black as our code formatting tool in #6361 we caused a large amount of
code churn to change the code formatting. However using the ignore file
is a local opt-in feature for git and not something we can enable
globally by default. To facilitate this a section is added to the bottom
of the contributing guide to document how this file can be used.
mtreinish pushed a commit that referenced this pull request May 7, 2021
In #6361 the CONTRIBUTING.md was updated to reflect the use of black for code formatting.
However, as part of that change a typo was made in the link to pylint. This commit corrects that
issue so the link to pylint works in the rendered markdown.
@levbishop levbishop mentioned this pull request Jun 20, 2021
@1ucian0 1ucian0 added the Changelog: None Do not include in changelog label Jun 25, 2021
ElePT pushed a commit to ElePT/qiskit that referenced this pull request Jun 27, 2023
* make compatible with pylint and pycodestyle

* black config

* flake8 compatible config

* Missing newline

* Add black check to CI and dev requirements

This commit updates the CI configuration and local tox configuration to
leverage black instead of pycodestyle. It adds a check job to ci and the
tox lint job so we can quickly check if black has been run. A tox job
named 'black' is added to run black on all the code in the repo.

* Run black on everything

This commit reformats all the code in the qiskit-terra repository to use
black. It changes no functionality in the project and just adjusts the
code formatting to be consistent and automated. If you are looking at
this commit in the git log you can likely safely ignore any diff from
this commit as it is just the result of running '`black' on the repo
and instead you should look at any commits before or after this for
functional changes.

Co-authored-by: Lev S. Bishop <18673315+levbishop@users.noreply.github.com>
ElePT pushed a commit to ElePT/qiskit-algorithms-test that referenced this pull request Jul 17, 2023
* make compatible with pylint and pycodestyle

* black config

* flake8 compatible config

* Missing newline

* Add black check to CI and dev requirements

This commit updates the CI configuration and local tox configuration to
leverage black instead of pycodestyle. It adds a check job to ci and the
tox lint job so we can quickly check if black has been run. A tox job
named 'black' is added to run black on all the code in the repo.

* Run black on everything

This commit reformats all the code in the qiskit-terra repository to use
black. It changes no functionality in the project and just adjusts the
code formatting to be consistent and automated. If you are looking at
this commit in the git log you can likely safely ignore any diff from
this commit as it is just the result of running '`black' on the repo
and instead you should look at any commits before or after this for
functional changes.

Co-authored-by: Lev S. Bishop <18673315+levbishop@users.noreply.github.com>
ElePT pushed a commit to ElePT/qiskit-algorithms that referenced this pull request Jul 27, 2023
* make compatible with pylint and pycodestyle

* black config

* flake8 compatible config

* Missing newline

* Add black check to CI and dev requirements

This commit updates the CI configuration and local tox configuration to
leverage black instead of pycodestyle. It adds a check job to ci and the
tox lint job so we can quickly check if black has been run. A tox job
named 'black' is added to run black on all the code in the repo.

* Run black on everything

This commit reformats all the code in the qiskit-terra repository to use
black. It changes no functionality in the project and just adjusts the
code formatting to be consistent and automated. If you are looking at
this commit in the git log you can likely safely ignore any diff from
this commit as it is just the result of running '`black' on the repo
and instead you should look at any commits before or after this for
functional changes.

Co-authored-by: Lev S. Bishop <18673315+levbishop@users.noreply.github.com>
ElePT pushed a commit to ElePT/qiskit-ibm-provider that referenced this pull request Oct 9, 2023
* make compatible with pylint and pycodestyle

* black config

* flake8 compatible config

* Missing newline

* Add black check to CI and dev requirements

This commit updates the CI configuration and local tox configuration to
leverage black instead of pycodestyle. It adds a check job to ci and the
tox lint job so we can quickly check if black has been run. A tox job
named 'black' is added to run black on all the code in the repo.

* Run black on everything

This commit reformats all the code in the qiskit-terra repository to use
black. It changes no functionality in the project and just adjusts the
code formatting to be consistent and automated. If you are looking at
this commit in the git log you can likely safely ignore any diff from
this commit as it is just the result of running '`black' on the repo
and instead you should look at any commits before or after this for
functional changes.

Co-authored-by: Lev S. Bishop <18673315+levbishop@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: None Do not include in changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants