Skip to content

MNT add isort to pre-commit hooks #23362

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 12 commits into from

Conversation

adrinjalali
Copy link
Member

@adrinjalali adrinjalali commented May 13, 2022

9705422 adds isort to pre-commit hooks, then 6f96864 applies isort to the repo and fixes issues that came as a result.
Then e6cd604 adds the same step to the Azure pipeline CI.

The few things I had to change manually:

  • change a few imports to importing from the file instead of module since they were causing circular import issue due to changed order of imports.
  • changed and ignored minor things in a few files to make flake8 pass (unused imports, etc).

towards #22853

@ogrisel
Copy link
Member

ogrisel commented May 13, 2022

Is enforcing import order consistency beneficial enough to justify the added complexity in tooling usage for contributors?

I like consistent import statements but I have the feeling that this additional linter might add a layer of friction (both to first time contributors and to grumpy old-style core developers who might not embrace the joys of a well configured pre-commit setup ;)

For black the ratio of complexity cost vs gains (consistent code style + not having to explains the rules of PEP8 to users) was more favorable.

@jjerphan
Copy link
Member

Thanks for exploring this, @adrinjalali.

I would also be in favour of sorted imports for the longer term, yet I think it comes with drawbacks.

Should we add it to a vote during the next core-dev meeting?

@adrinjalali
Copy link
Member Author

We can discuss and see what people feel like, and then if we think there might be a consensus, we can call for a vote on the mailing list :)

@glemaitre
Copy link
Member

@adrinjalali could you paste what would be a failure in the CI if someone does not import in the right order?

@adrinjalali
Copy link
Member Author

The CI failure shows a clear list of issues. Example: https://dev.azure.com/scikit-learn/scikit-learn/_build/results?buildId=42219&view=logs&j=32e2e1bb-a28f-5b18-6cfc-3f01273f5609&t=8a54543f-0728-5134-6642-bedd98e03dd0

--- /home/vsts/work/1/s/.github/scripts/label_title_regex.py:before	2022-05-17 09:51:04.962912
+++ /home/vsts/work/1/s/.github/scripts/label_title_regex.py:after	2022-05-17 09:51:42.390988
@@ -1,9 +1,10 @@
 """Labels PRs based on title. Must be run in a github action with the
 pull_request_target event."""
+import json
+import os
+import re
+
 from github import Github
-import os
-import json
-import re

@glemaitre
Copy link
Member

Thanks @adrinjalali. I don't find it more complex than the output of black.

If we error with those tools, it could be cool to print a message showing the command to run to fix the problem (for black and isort).

I would be +1 but let's discuss it in the next developer meeting.

@ogrisel
Copy link
Member

ogrisel commented May 18, 2022

If we error with those tools, it could be cool to print a message showing the command to run to fix the problem (for black and isort).

That indeed should help a lot!

@ogrisel
Copy link
Member

ogrisel commented May 30, 2022

So at the dev meeting we decided that the first step would be to improve the CI message to give specific directions to the contributor to fix linter formatted errors by pointing them to a specific command line or a script in the repo (+ the pip install command to install the correct version of black) and optionally link to some online doc that explains how to setup pre-commit.

Then once this is done, we can upgrade this PR to also include isort in the feedback from the CI.

Then, as a nice to have follow-up PR, we could have a bot that provides the CI feedback as a pull request feedback instead of just text hidden in the raw CI log.

@adrinjalali
Copy link
Member Author

superseded by #26649

@adrinjalali adrinjalali deleted the isort branch June 21, 2023 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants