-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
RFC isort as linter and import sorter #22853
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
Historically, we do not really have opinions on import order, so the benefit of
I am overall +0. |
We did it for black so we could consider it again.
Actually you already need 2 :) black doesn't deal with unused import for instance so you need to run flake8. |
I'm +1 since I like anything that enforces common style throughout the project. And I don't like to think about import orders and I don't like to review import order changes unrelated to the PR |
I am +1 for it such that @jeremiedbb does not complain when I manually sort imports :) |
I am worried about imposing yet another dev dependency to our first time contributors. As long as we do not enforce isort in the linter step, then why not. What would be great would be to have a sklearn-format-bot such as commenting a PR with And we would comment with this only prior to merging. Then we could make black linting optional: it would not block the other builds and it would be the responsibility of the merger to format the PR. We could still use |
My experience during the last sprint was that people skipped the pre-commit hook installation cause we have them as optional, and then a ton of those PRs' CI failed because of linting issues. I think we should make that step more of a "mandatory" step, and have less linting issues, and if we do that, then having Making us do the |
pre-commit.ci has a service of automatically pushing to a PR to auto format. It can also be configured to manually format with a "pre-commit.ci autofix" comment. Our CI already "early fails" when linting breaks, so I am okay with a |
I would rather like not to automatically push formatting commits in PRs because first time contributors not very experience with git will not understand the error message they will get when trying to git push a new commit to their branch without pull first, and once they pull they are likely to get merge conflicts. I would prefer to only manually do the reformatting with |
We could make that more mandatory during sprints but people contributing online without attending a sprint will still not use pre-commit. Also pre-commit the way it is currently configured is a bit confusing in case of black failure: the first commit fails but black has fixed the files so the second commit will succeed. I find this behavior ok, but the messages of black and pre-commit are not natural to understand what's going on and what you are expected to do to move forward. |
I agree. And since we have a pair of windows and macos builds that takes up to 40 min for a reason I do not understand, this can be annoying. |
This would make reviewing PRs somewhat harder since they'd have very odd random formats. I'm happy with what we've got, by the time we review PRs, they're nicely formatted. I'm happy with I do agree that the way they're setup right now can be confusing, but I'm happy for us to improve that (not sure how). |
SciPy exposes developer tools through a single cli: https://github.com/scipy/scipy/blob/main/dev.py It is "goto place" for developers to do anything they want with the library, like running For me, the downside is that this cli tool is package specific, which means the knowledge is not transferable to other projects. XREF: scipy/scipy#15489 |
Nice, at least it's better than what we have I think. |
@ogrisel since adding I don't want this to be an example of "we don't think this solution is ideal, even though we almost do it already, and we don't really have the time to implement the perfect solution", especially since it doesn't really have anything to do with the library itself. |
FWIW I have been using pre-commit.ci in another project and did a sprint with new contributors using it. It does indeed take some getting used to it pushing fixes to PRs but overall I find it's really useful for contributors who generally don't setup pre-commit or other dev tools right. I would argue that aside from sprints for new contributors, contributors with a least some experience (or former devs) don't read contributing guide. Say you want to fix something in pandas. Are you going to read their contributing guide to see whatever style guide they have? No, you are going to make the fix open a PR and see if the CI is happy. Even if you read it last year, by now the style/tools used might have changed. So in that sense pre-commit.ci does make the workflow smoother. As for very new contributors, that does mean they need to know how to fix merge conflicts, but at least that's a more useful skill than figuring out how to install the right dev tools.
Yes, for code styling pre-commit is the way to go IMO. Then it doesn't even matter what it runs (black, isort or others) there is just 1 dev dependency. But that's in the long term, in the short term, I'm indeed not sure what would be the small iterative improvements over the current situation. |
So my take is that we don't have any particular objection to I'll open a PR with |
Ruff includes isort and flake8. If we replace flake8 with ruff, then we get isort without increasing the number of CLI tools. |
What do we think of
isort
? I've seen it in other projects and seems like a sane tool.We could add it to our linter and pre-commit hooks if others think it's a good thing. It does look nice to me.
Looking at the import section of
test_common.py
, we have:And running
isort --profile black sklearn/tests/test_common.py
will result in:with the following diff:
The text was updated successfully, but these errors were encountered: