-
Notifications
You must be signed in to change notification settings - Fork 95
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
[STY] Use black
and isort
to manage library code style
#758
Conversation
I'm leaning toward merging #696 before running black and isort in this PR, since it's so close. I'm happy to deal with conflicts in the other PRs, rather than wait on this one until they're merged. |
Most other PRs are recent enough that they could probably just rebased and then have these run on them. However, a different concern is that there's actually a few corner-cases for running pre-commit hooks that would automatically run the formatting for you. However, if you forget and then make a commit, it's possible that the commit could abort if |
It seems like there's a bit of a rabbit-hole on pre-commit hooks. The crux of the issue is that you can have separate working and staged areas, but you can't run |
It's the one thing black always messes up.
Codecov Report
@@ Coverage Diff @@
## main #758 +/- ##
==========================================
- Coverage 93.20% 93.20% -0.01%
==========================================
Files 27 27
Lines 2209 2208 -1
==========================================
- Hits 2059 2058 -1
Misses 150 150
Continue to review full report at Codecov.
|
I'm a little lost, since pre-commit hooks are a bit like magic to me. If you stage an incorrectly-formatted version of the code, what happens? Assuming you commit something that's not correctly formatted and open a PR to EDIT: Also, what about "format on save" settings within editors, like this one for running black on save in VSCode? |
The issue is that what's staged and what's in the working area are two different things, so your commit will not necessarily contain something correctly formatted. Many pre-commit hooks use Again, one way around this is to use a full-fledged tool like pre-commit, where somebody much more experienced than me has figured out how to work things like this out. I'm not sure about format on save settings in general, as I'm still using You can see discussion about this on the |
What about a set-up like this one ? https://ljvmiranda921.github.io/notebook/2018/06/21/precommits-using-black-and-flake8/ Does that trigger the same commit fail issues ? |
I believe |
If you use EVIL mode (vim and Emacs) you can set it up to format on save. I'm afraid I know nothing about |
I'm ok with adding this as a developer dependency, since code-formatting will now be a bigger part of the development workflow ! Do you think its handling would make a reasonable workflow, at least ? I feel like failing a commit isn't viable. |
The only stumble is that |
If pre-commit hooks are going to take a bit more time to figure out, should we just document our code style, resolve conflicts, and get this merged first, and then address auto-styling in a later PR? |
That seems reasonable. We should go ahead and add checks to the Makefile's Additionally, if I run
|
I added
That's weird... I'm not seeing those when I run |
Hm, maybe I'm misunderstanding something, but under the style check it seems to only be using
Might |
I think
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Does the toml file fix linting errors on merge?
The TOML file just defines the settings for |
Since #795 introduces a number of style-based changes due to black and isort auto-formatting, I'd love to get this PR merged before that one. That way the style stuff will track back to a style PR instead of a content one. If anyone has time to review (especially the config files, rather than the reformatted code), that would be super helpful. |
Thanks @eurunuela! @jbteves, would you be willing to review? Since we chose to push pre-commit hook information until a later PR, I think it would be fine for you to be a reviewer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues jumped out at me, the code runs, and I was able to get Black working in my IDE. I can't really review the specific configuration changes that set Black as the new standard. I know others have looked at that so your choice on whether to wait for one more pair of eyes to look at the configuration changes before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @tsalo ! At some point I'll see if I can figure out the easiest way to get it to run automatically for commits.
Thanks all. Merging now. |
Closes #219. This PR is a combined effort from @jbteves and @tsalo.
Changes proposed in this pull request:
black
andisort
settings to package configuration files.black
andisort
-related linting is done in CI.black
coding style.black
andisort
on the package.