-
Notifications
You must be signed in to change notification settings - Fork 133
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
isort support #1323
isort support #1323
Conversation
for more information, see https://pre-commit.ci
Although this tool does standardize the code (so people don't have to worry about import orders), it does result in a large diff in this PR (and hence soiling git blame). If having a good git blame is important, might be worth adding a |
for more information, see https://pre-commit.ci
That's pretty much it for this feature. Happy to discuss more, or merge if it looks good. Completely up to you and your team @erikvansebille if you want to merge this, or stick with manual import sorting. |
from parcels import ParticleSetSOA, ParticleFileSOA, KernelSOA # noqa | ||
from parcels import ParticleSetAOS, ParticleFileAOS, KernelAOS # noqa |
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.
isort will mess with the custom sorting here.
from parcels import ( # noqa | ||
AdvectionAnalytical, | ||
AdvectionDiffusionEM, | ||
AdvectionDiffusionM1, | ||
AdvectionEE, | ||
AdvectionRK4, | ||
AdvectionRK4_3D, | ||
AdvectionRK45, | ||
ErrorCode, | ||
Field, | ||
FieldSet, | ||
JITParticle, | ||
KernelAOS, | ||
KernelSOA, | ||
ParticleFileAOS, | ||
ParticleFileSOA, | ||
ParticleSetAOS, | ||
ParticleSetSOA, | ||
ScipyParticle, | ||
StateCode, | ||
logger, | ||
) |
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.
Do you know why there's only one class per line in this import call (and similar files)? From the isort documentation, it seems that multiple classes are also supported. Or is this intentional because it's even cleaner?
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.
This is the way imports are formatted using the black
auto formatter, which isort
is compatible with by specifying the profile to be black
(see the modified setup.cfg
).
Although we don't use black
at the moment, it is a really popular formatter that I think would be good to consider introducing in future. This is just a small step in that direction, preventing reformatting the imports again should we start using black
.
Thanks for implementing this, @VeckoTheGecko; looks great! I agree with you that using tools like isort to clean up the code (and keep it clean) will facilitate development. So I'm happy to merge into master after you've answered my question above on the one-per-line-import in the test*-files |
@erikvansebille would you mind bringing |
Yup, will do after I also merged #1325. But can't you do it yourself? |
|
OK, I've just invited you to the OceanParcels team, so that you can commit directly on the OceanParcels repo. Welcome to the team! |
Glad to be aboard! 🥳🥳🥳🥳 |
isort sorts your imports so that you don't have to. The tool organises them into 5 sections separated by newlines:
from __future__ import annotations
)import os
)import xarray
)import parcels.Field
)from .utils import square
)Within each section the imports are sorted alphabetically, and also squashes imports down to one line.
eg.
becomes
This will make import statements through the codebase much more structured, and easier to read. isort also has good integration with pre-commit.
You can add
# isort:skip
to a line to prevent isort from moving the import statement.