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

(🎁) Adopt Black and isort as code formatters #12424

Merged
merged 2 commits into from
Jul 27, 2022

Conversation

KotlinIsland
Copy link
Contributor

@KotlinIsland KotlinIsland commented Mar 22, 2022

Description

⚠ When merging this don't squash the commits, we need the config and the formatting kept separate.

Changes:

  • add configuration to pyproject.toml
  • add test dependencies
  • add to tox lint
  • configure flake8 to be compatible
  • add commands to runtests.py
  • add .git-blame-ignore-revs
  • Add badges to the readme
  • Configure pre-commit for black and isort

Anything else?, Oh yeah:

  • format the code (:trollface:)

TODO after this is merged

If your PR has conflicts follow these steps

  1. Rebase onto the configuration commit (not the format commit).
  2. Interactively rebase from the start of your branch pausing on every commit.
  3. Run git checkout --theirs .; black .; isort .; git add -A; git rebase --continue
  4. repeat 3 until you pass over all commits
  5. Once complete rebase onto master
Alternative suggestion by @jhance 1. Rebase onto the black configuration commit. 2. Run black and commit on the top of your PR. 3. Re-parent your diff on top of the black commit (NOT a rebase). Checkout the black commit and then `git checkout .` 4. Re-create the original commits 5. Rebase onto master

@KotlinIsland KotlinIsland force-pushed the blacken branch 4 times, most recently from f33312c to 41f687d Compare March 22, 2022 14:05
@github-actions

This comment has been minimized.

4 similar comments
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@JelleZijlstra JelleZijlstra mentioned this pull request Mar 22, 2022
5 tasks
@jhance
Copy link
Collaborator

jhance commented Mar 22, 2022

Can you split the actual formatting to its own commit for review purposes?

@KotlinIsland
Copy link
Contributor Author

@jhance Done!

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

pyproject.toml Outdated Show resolved Hide resolved
@KotlinIsland KotlinIsland force-pushed the blacken branch 2 times, most recently from 2967b20 to 2b1997a Compare March 26, 2022 02:52
@github-actions

This comment has been minimized.

@KotlinIsland KotlinIsland force-pushed the blacken branch 3 times, most recently from c358440 to 1ad461a Compare March 26, 2022 03:50
@github-actions

This comment has been minimized.

2 similar comments
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@hmc-cs-mdrissi
Copy link
Contributor

hmc-cs-mdrissi commented Mar 27, 2022

One tip, .git-blame-ignore-revs is useful when doing a large reformatting commit like this. It allows git blame to skip certain commits as otherwise git history becomes more annoying to use. Github is about to support it, https://docs.github.com/en/repositories/working-with-files/using-files/viewing-a-file#ignore-commits-in-the-blame-view (currently in beta) and git cli has supported it for a while. It effectively skips ignored commits when doing git blame.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. πŸ€–πŸŽ‰

Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

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

I have just one comment. Please fix it and also rebase the PR (it has conflicts), and then I will merge it. It is waiting for too long.

pyproject.toml Outdated Show resolved Hide resolved
@hauntsaninja
Copy link
Collaborator

(This PR always has merge conflicts, which makes it annoying to merge. If you remove the reformatting commit, I'd be happy to merge past CI and reformat with whatever is on master at the time)

@KotlinIsland
Copy link
Contributor Author

@hauntsaninja the reformat requires manual fixup regarding type comments, I'm happy to rebase and reformat to get these changes done.

@KotlinIsland KotlinIsland force-pushed the blacken branch 2 times, most recently from 90b36ea to 17b1c3c Compare July 26, 2022 23:27
@KotlinIsland
Copy link
Contributor Author

@ilevkivskyi @hauntsaninja LET'S GOOO!!!

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. πŸ€–πŸŽ‰

1 similar comment
@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. πŸ€–πŸŽ‰

@KotlinIsland
Copy link
Contributor Author

⚠️ Remember, DO NOT squash the commits when merging, we need to preserve both separately.

@ilevkivskyi ilevkivskyi merged commit 97c5ee9 into python:master Jul 27, 2022
@KotlinIsland
Copy link
Contributor Author

@ilevkivskyi Can you add the pre-commit.ci app to the project configuration now?

@KotlinIsland
Copy link
Contributor Author

@ilevkivskyi
Copy link
Member

I think I can't, at least I can't figure out how do this (it only allows me to install it to my personal repos). I guess only an org admin can add apps.

@hauntsaninja
Copy link
Collaborator

cc @JelleZijlstra who did this for python/typeshed

@KotlinIsland
Copy link
Contributor Author

Perhaps only owners can add apps? @JukkaL

@AlexWaygood
Copy link
Member

Thanks for persisting with this @KotlinIsland, great to see this happen! Very minor, but the "code style with black" README badge doesn't look quite right:

Screenshot_20220727-102417_Opera

@KotlinIsland
Copy link
Contributor Author

KotlinIsland commented Jul 27, 2022

Thanks! Oops, I'll fix that next chance I get, if someone else doesn't fix it first 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Format code using Black?