-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Use black? #4174
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
Comments
For me the only con is the noise on GitHub blame. I imagine a lot of projects are hesitant to add it due to this very reason. Unfortunately, GH does not seem to see it as a feature to add something like this. Is FB a GitHub pro user? If yes, maybe we can build some pressure there? I could live with the additional noise if we keep it to a single commit. If we do this we should at the same time look into some more auto formatting like
I don't understand. Why can't we merge this the normal way? |
Same here
Good point, I think it would be OK to add
I'd just like to keep my contribution history clean, ideally :) |
If that is the only reason, I'm happy to create the PR. No need to bother setting up a new account or bot for this. |
I'd rather not though, specifying a |
If we have
I agree that would be preferred, but compared to |
Because sometimes one may want to apply black without committing. I also wonder how easy/painful it will be to configure IDEs to properly look for the non-default
Yup, that's one of the reason I never use it locally ^^
Very few people will be using |
There's another thing to consider that @mthrok pointed out (thanks Moto!): we'll need to keep GH and fbcode in sync regarding the linting. We don't currently lint torchvision on fbcode, but if we start linting on GH we'll have to lint on fbcode as well. Otherwise, things will get nasty when people submit (unlinted) code from withing fbcode: CI will complain when we import those changes on GH. We could apply the linting while importing to GH, but I'm pretty sure we would need to re-export those linting changes to fbcode to avoid conflicts. The internal fb linter relies on https://github.com/omnilib/ufmt, so we'll have to use that instead of individually apply I'll make some tests next week to make sure this will be working fine, find out which versions we need to pin down, and that we can still make this part of the pre-commit hooks etc. Thanks a lot @pmeier for your efforts so far! |
OK, so I tried internally and applying pyfmt is working fine and is consistent with the internal fb linter. For it to be fully compliant we'll need to add
in the Also, we need to pin down the dependencies as such:
(This command can be run from any fb machine, whether it's a laptop or a devvm). |
I'll update the PR accordingly. |
Formatting the codebase with black would help in a few ways:
Cons:
git blame
, namely 1 extra click. This is for GitHub only, locally nothing is changed (see below)--no-build-isolation
to allpip install --editable
commands [1], as done in 3d1cd1d. This isn't a big deal either as long as we provide good guidelines, and we recommendconda
overpip
anywayUsing black has already been discussed in #2025, with general positive sentiment towards adoption. The main concern seems to be that
black
brakesgit blame
, but it's actually not the case: we can avoid breakinggit glame
thanks to the ignore-revs-file option (unfortunately, GitHub doesn't support it yet, so the Github blame may still be a bit noisy).[1] The reason for this nonsense is that
black
relies (only) on apyproject.toml
file for its configuration. This file was initially intended to declare build-time dependencies (something completely unrelated to code formatting, but oh well), and it can make pip behave differently in editable mode psf/black#683 (comment), as illustrated in https://app.circleci.com/pipelines/github/pytorch/vision/9457/workflows/4007ced4-684c-498d-8c78-f6ee83853a7d/jobs/697466 . We need the --no-build-isolation flag to preservepip
's sane behaviour, now that this file is added.Adopting black would involve:
ignore-revs-file
file, referencing the previous PR forgit-blame
to be preserved.black
, edit the "install from source" docs withpip install -e .
to use the--no-build-isolation
flag, and optionally setup a pre-commit hook as done e.g. in pandasI'm happy to work on this if we agree to rely on
black
from now on.CC @fmassa @pmeier
The text was updated successfully, but these errors were encountered: