Repository navigation
Ruff violation icn001 fix - #15899
Conversation
|
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
|
Hi @Shaheer-Ahmd. Thanks for opening the PR! I like the rule ICN001 and think it's worth implementing. This PR is quite ambitious in that it fixes ICN001 everywhere in Astropy. In Ensure compliance with more Ruff rules we actually recommend breaking these large PRs into a few smaller ones. That way not everyone in Astropy has to sign off on an omnibus PR, instead you can get these PRs in faster by needing only 1 or 2 people to approve for each PR. |
|
We shouldn't write weird code just to satisfy a linter, but there is nothing strange about |
|
No, but would anyone have chosen to alias it to something like |
|
We could just use |
|
I'm fine with the current state, somewhat preferring the renaming (all this may become irrelevant anyway, as surely at some point someone is going to suggest we switch to |
mhvk
left a comment
There was a problem hiding this comment.
I think this is now all fine! Thanks, @Shaheer-Ahmd
p.s. Very small suggestion for future PRs: push commits in batches so one avoids running CI for every commit separately.
|
Is this merge-ready then? Any other changes? |
|
If everyone agrees on the custom alias, that should be ready, but needs squeezing. If you want to do it yourself, reducing to 2-3 commits should probably be ok. |
|
By the "full set of enforced aliases" you mean |
That is the full list, but since most of these are not imported anywhere within astropy, and many likely never will be, it should be enough to add
No, squashing (sorry, my typo before) is done on your existing branch, as described in |
851a2a4 to
fabc216
Compare
fabc216 to
ee641b5
Compare
…mport in mpl_normalize and updated docs
ee641b5 to
1a68f4a
Compare
|
squashed and updated the docs. |
|
Thanks a lot, looking great now! Apparently there is a new deprecation in numpy-dev, but that's nothing that needs to concern this PR. |
| import numpy as np | ||
| import matplotlib as mpl | ||
| import matplotlib.pyplot as plt | ||
| import pandas as pd |
There was a problem hiding this comment.
If anybody ever deviates from the naming conventions ICN001 enforces then the Ruff hook in pre-commit will clearly state where in the code the violation occurred and what name it expects to be used. It is even possible to have Ruff fix the violations automatically. I don't think this text in the developer documentation is informative anymore.
There was a problem hiding this comment.
Personally I prefer to know what I am expected to write before a pre-commit tool tells me I've done it wrong and how to fix it. Besides, we are still seeing issues with contributors who are unable to set up their pre-commit locally.
If we have section in the docs stating in some detail what import styles Ruff is or is going to enforce via isort, flake8 conventions and what else, that might replace this explicit list, but currently I don't see such a reference. Opinions may vary on this.
Also it is a good reminder of what plt.figure stands for when encountered anywhere in the code without even having to look at the imports.
There was a problem hiding this comment.
I'm not sure if people are actually having problems installing pre-commit. I consider it much more likely that they haven't followed our instructions to install pre-commit simply because they have not read our developer documentation at all, in which case nothing we write there is going to help them.
I'd rather not write down any specific rules that Ruff would be enforcing anyways because I believe the shorter our developer documentation is the more people might actually read it.
There was a problem hiding this comment.
I suspect similarly. I've installed pre-commit on everything from a Python env on my phone (bad idea, don't do dev work on the phone) to a compute cluster. I've never once run into a problem with the pip install except when I didn't have git on a machine.
There was a problem hiding this comment.
Currently the docs do not even state that you must install and activate pre-commit before you are allowed to push anything upstream, so that would need to be changed along the way. And then how would you handle cases when a series of commits fail in the CI pre-commit, you ask the contributor to run pre-commit locally and they state they have it installed, yet it is apparently allowing invalid commits? I thought the point of all the pre-commit tools was to lower the threshold for new contributors, but that is not always reflected by my experience – apparently it is not that easy for everyone, or are those just some freak cases of exotic Windows installations?
There was a problem hiding this comment.
Is this conversation blocking merge? Should I wait?
There was a problem hiding this comment.
A first-time contributor who needs multiple commits to get the code style checks to pass has proven themselves to be untrustworthy when it comes to code style and the related tooling.
It is technically possible to get multiple commits to pass and then fail pre-commit. But this requires rebases and other fancy stuff that then skip the "pre-commit".
Our CI run of pre-commit should tell any contributor exactly what to fix. And the comment pre-commit autofix can take care of many stuff server side.
Installing pre-commit locally AFAIK is always as easy as pip install pre-commit; cd <git repo>; pre-commit install and makes their life much easier.
There was a problem hiding this comment.
Is this conversation blocking merge? Should I wait?
I think we should update some of our developer documentation, but doing that properly is beyond the scope here and shouldn't block merging.
There was a problem hiding this comment.
Indeed, this is moving to an entirely different topic and certainly needs more discussion.
The PR was already squashed; I probably would not have added the as np imports just to rename them later, but I think our commit history can live with that. ;-)
There was a problem hiding this comment.
To conclude this part of the discussion here, in my experience it simply is not straightforward for every first-time contributor to parse a report like https://results.pre-commit.ci/run/github/2081289/1703509121.Z6WkqI4KQVm9d2te2s3qhg and make the required fixes, and if I see such commits coming in even after mentioning the use of pre-commit, I am still hesitant to label anyone as "untrustworthy" without knowing myself about any possible pitfalls on a given platform. For which we don't seem to be able to provide that much guidance e.g. for the various Windows platforms.
|
Thanks, all! |
|
Hmm, maybe I misunderstood the interpretation of the "rebase or squash necessary?" checkmark... |
|
@dhomeier , what do you mean? |
|
I normally check the marks in the sense of "no further action required" since @Shaheer-Ahmd had already squashed down to 3 commits locally. But that list is only used very inconsistently anyway. |
|
Oh... I only noticed that the box in the origin post was not checked. 😬
|
|
But that box does not mean "if unchecked the PR will always be squashed on merge"? We surely have smaller PRs merged with more commits... |
|
Sorry, it is my bad. I didn't know you wanted it not squashed. I made a call at merge time and apparently I made the wrong call. I will take full responsibility. But seems overkill to revert and I don't want to force push to main. I will be more careful next time! |
|
No problem, I think it can fit into a single commit – I meant to reply to Eero that it was already squashed, but did not get to it while the discussion on pre-commit was still going on. Thanks everyone! |
Description
This PR fixes the violation of RUFF rule ICN001
unconventional-import-alias (ICN001)
Derived from the flake8-import-conventions linter.
Fix is sometimes available.
What it does
Checks for imports that are typically imported using a common convention,
like
import pandas as pd, and enforces that convention.Why is this bad?
Consistency is good. Use a common convention for imports to make your code
more readable and idiomatic.
For example,
import pandas as pdis a commonconvention for importing the
pandaslibrary, and users typically expectPandas to be aliased as
pd.Example
Use instead:
This pull request is to address ...
Fixes #14818