8000 Add black as an auto formatter by jtpavlock · Pull Request #3694 · beetbox/beets · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add black as an auto formatter #3694

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

Closed
wants to merge 9 commits into from
Closed

Add black as an auto formatter #3694

wants to merge 9 commits into from

Conversation

jtpavlock
Copy link
Contributor
@jtpavlock jtpavlock commented Jul 27, 2020

Description

See discussion

  • Adds black a universal and automatic code formatter
  • black is now enforced via an optional pre-commit hook (see below)
  • flake8 is now included in that hook
  • tox -e lint now runs pre-commit run -a (see below)

To add this to your workflow, I recommend creating a git hook with pre-commit. Note that this is optional and you can just run the checks as normal with tox -e lint if you don't want the hooks in your git workflow. Another option, if you don't want to run the hooks for some reason on any particular commit, you can use git commit -n [--no-verify]

To install the hook run pre-commit install. This will now enforce black and flake8 prior to completing the commit. It will only check files that were commited, so the performance hit isn't an issue.

Example workflow for a compliant commit:

$ git commit
black....................................................................Passed
flake8...................................................................Passed
[black 0ab1ef45] good commit
 1 file changed, 1 insertion(+), 1 deletion(-)

Example for a commit that is not compliant with the lint checks:

$ git commit
black....................................................................Failed
- hook id: black
- files were modified by this hook

reformatted setup.py
All done! ✨ 🍰 ✨
1 file reformatted.

flake8...................................................................Passed

Note that since it was a formatting issue, black will automatically apply the chang 8000 es. However, you will need to re-stage and attempt the commit again. These checks will occur prior to writing the commit message if you don't use git commit -m.

To run the linting commands normally on all files (does not require the pre-commit install command) run pre-commit run -a. This is now exactly what tox -e lint will do.

Edit: this would also significantly affect #3673 as a lot of those changes would no longer be required.

To Do

  • Documentation - add info to CONTRIBUTING.rst

@jtpavlock jtpavlock force-pushed the black branch 2 times, most recently from 4ae0755 to 7bec5fb Compare August 1, 2020 03:50
@jtpavlock
Copy link
Contributor Author
jtpavlock commented Aug 1, 2020

Fixed conflicts and rebased off master.

Since there seems to be some crickets on this PR, so I'll make a few comments.

This is an incredibly large PR, and likely impossible to review every change. Merging this basically surrenders our formatting to an external program. While every change may not always be perfect, I believe that overall it will be a net positive as it will increase readability in most cases and also completely removes any formatting frustrations for both reviewers and contributors.

As a side note, the current testing errors are due to #3708. We can be sure black doesn't change any actual code meaning as it creates an AST before and after formatting.

@arogl
Copy link
Contributor
arogl commented Aug 1, 2020

I was looking at #3673 earlier and was going to close, as we are looking at using black as the formatter.

I was then going to re-look at the variable names as suggested by @sampsyo

@arogl
Copy link
Contributor
arogl commented Aug 1, 2020

As a side note, the current testing errors are due to #3708. We can be sure black doesn't change any actual code meaning as it creates an AST before and after formatting.

Are we not looking to drop anything lees than 3.6 when we go to the pathlib changes you are proposing via #3704

@jtpavlock
Copy link
Contributor Author

Are we not looking to drop anything lees than 3.6 when we go to the pathlib changes you are proposing via #3704

I believe the current plan for v1.5.0 is to be the last release that supports python 2.7, 3.4 and 3.5. But, until then, we still have to deal with issues for those python versions.

@jtpavlock jtpavlock mentioned this pull request Aug 2, 2020
3 tasks
davidswarbrick added a commit to davidswarbrick/beets that referenced this pull request Aug 15, 2020
This reverts commit f48ff57.

Decided to leave fixing the linting errors until extra tests etc.
have been integrated, or beetbox#3694 is merged.
@stale
Copy link
stale bot commented Nov 29, 2020

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 29, 2020
@stale stale bot closed this Dec 6, 2020
@arogl arogl mentioned this pull request Aug 27, 2021
3 tasks
@snejus snejus deleted the black branch June 15, 2024 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
0