Skip to content
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 take 2 #2686

Merged
merged 3 commits into from
Jul 7, 2023
Merged

isort take 2 #2686

merged 3 commits into from
Jul 7, 2023

Conversation

jakkdl
Copy link
Member

@jakkdl jakkdl commented Jul 5, 2023

#2538 got abandoned, but that felt in large part because it was just a one-off random big reorg. This adds isort to CI, and it only needed a single isort: skip for it to work for the whole project.

@codecov
Copy link

codecov bot commented Jul 5, 2023

Codecov Report

Merging #2686 (d99e0f0) into master (042f035) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2686      +/-   ##
==========================================
- Coverage   98.84%   98.84%   -0.01%     
==========================================
  Files         113      113              
  Lines       16488    16474      -14     
  Branches     3003     3004       +1     
==========================================
- Hits        16297    16283      -14     
  Misses        134      134              
  Partials       57       57              
Impacted Files Coverage Δ
trio/_abc.py 100.00% <ø> (ø)
trio/_core/_io_common.py 100.00% <ø> (ø)
trio/_core/_ki.py 100.00% <ø> (ø)
trio/_highlevel_open_tcp_listeners.py 100.00% <ø> (ø)
trio/_highlevel_socket.py 100.00% <ø> (ø)
trio/_tests/test_util.py 100.00% <ø> (ø)
trio/abc.py 100.00% <ø> (ø)
trio/lowlevel.py 100.00% <ø> (ø)
trio/__init__.py 100.00% <100.00%> (ø)
trio/_channel.py 100.00% <100.00%> (ø)
... and 78 more

@A5rocks
Copy link
Contributor

A5rocks commented Jul 6, 2023

Huh, CI failing seems weird. It doesn't seem to be any sort of environment change but it's hard to imagine import re-ordering affecting static tools like that- actually, it isn't that hard to imagine.

I'll guess there's maybe duplicate somethings somewhere...? Or I don't know, maybe just revert certain files and # isort: skip them. Not sure.

I'm also not too sure about how I feel about such a large diff that will probably lead to a ton of merge conflicts! It's probably fine though since I think most open PRs are dead (as far as I know).

Comment on lines 425 to 459
if tool == "jedi" and sys.version_info >= (3, 11):
if class_ in (
trio.DTLSChannel,
trio.MemoryReceiveChannel,
trio.MemorySendChannel,
trio.SSLListener,
trio.SocketListener,
):
missing.remove("__aenter__")
missing.remove("__aexit__")
if class_ in (trio.DTLSChannel, trio.MemoryReceiveChannel):
missing.remove("__aiter__")
missing.remove("__anext__")
# if tool == "jedi" and sys.version_info >= (3, 11):
# if class_ in (
# trio.DTLSChannel,
# trio.MemoryReceiveChannel,
# trio.MemorySendChannel,
# trio.SSLListener,
# trio.SocketListener,
# ):
# missing.remove("__aenter__")
# missing.remove("__aexit__")
# if class_ in (trio.DTLSChannel, trio.MemoryReceiveChannel):
# missing.remove("__aiter__")
# missing.remove("__anext__")
Copy link
Member Author

@jakkdl jakkdl Jul 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the 3.11&3.12 failures are because I accidentally pushed this - I think my local environment updated jedi or something and these are no longer missing, but I forgot to undo the commenting before pushing in this PR.

Will look at the windows fails

Comment on lines 71 to 80
if sys.platform != "win32" or not _t.TYPE_CHECKING:
try:
from socket import (
sethostname as sethostname,
if_indextoname as if_indextoname,
if_nameindex as if_nameindex,
if_nametoindex as if_nametoindex,
if_indextoname as if_indextoname,
sethostname as sethostname,
)
except ImportError:
pass
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The windows CI fails is because pyright now doesn't see if_indextoname, if_nameindex or if_nametoindex on windows ... but it sees sethostname? And why did it "work" in the first place, since sys.platform == "win32" and _t.TYPE_CHECKING == TRUE it shouldn't have ever seen these symbols if it's parsing the if statement.

Regardless, I don't think it's an issue, and I don't care to dig deeper into it atm, so I'll just Remove those in the test.

@jakkdl
Copy link
Member Author

jakkdl commented Jul 6, 2023

I'm also not too sure about how I feel about such a large diff that will probably lead to a ton of merge conflicts! It's probably fine though since I think most open PRs are dead (as far as I know).

They're either dead, or by me 😇
In the long term this should cut down on merge conflicts from imports though, and hopefully any dead PR's that get resurrected doesn't play around too much with imports, and resolving import conflicts is usually much easier than in normal code (esp when you can just add both sets fully, then run isort+flake8 w/ f401)

@jakkdl
Copy link
Member Author

jakkdl commented Jul 6, 2023

The only failing check is an erroneously duplicated codecov/project

Copy link
Contributor

@A5rocks A5rocks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passes a spot check. I didn't look too hard but I assume this is all good cause tests pass!

I'm going to see if people on Gitter have Opinions about this but I think this is a good enough change to merge despite merge conflicts it will cause.

pyproject.toml Outdated Show resolved Hide resolved
trio/__init__.py Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to run isort after it's regenerated?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I manually sorted the imports in gen_exports.py so they pass - though upon reflection I should probably just # isort: skip as that's how the black formatting is handled, and shoehorning in isort to work with gen_exports.py --check or forcing future people to manually sort the imports does not sound fun.

@Kludex
Copy link

Kludex commented Jul 7, 2023

I didn't read the PR or issue, but this is useful for this kind of refactor.

@jakkdl
Copy link
Member Author

jakkdl commented Jul 7, 2023

I didn't read the PR or issue, but this is useful for this kind of refactor.

oooh, this is great. Thanks a lot!

@Kludex
Copy link

Kludex commented Jul 7, 2023

I don't think you can add the .git-blame-ignore-revs on this PR, it needs to be on the next one, cause the commits are going to be squashed (I guess).

@jakkdl
Copy link
Member Author

jakkdl commented Jul 7, 2023

I don't think you can add the .git-blame-ignore-revs on this PR, it needs to be on the next one, cause the commits are going to be squashed (I guess).

I rebased and split the PR among three commits, one to add isort to CI and configuring it (that's not ignored by blame, so people can see when it was introduced), one that runs isort on all the files, and a third one that adds .git-blame-ignore-revs. I can then merge/rebase it without squashing and keep all three commits

@Kludex
Copy link

Kludex commented Jul 7, 2023

[...] without squashing and keep all three commits

Great! 👍

@jakkdl
Copy link
Member Author

jakkdl commented Jul 7, 2023

Since nobody's complaining, I'll go ahead and merge 🚀

@jakkdl jakkdl merged commit 755f520 into python-trio:master Jul 7, 2023
33 checks passed
@jakkdl jakkdl deleted the isort branch July 7, 2023 10:32
@Kludex
Copy link

Kludex commented Jul 7, 2023

I think the commit is actually 933f77b ?

@jakkdl
Copy link
Member Author

jakkdl commented Jul 7, 2023

oh huh, yep. It's definitely listed as bec33b2 in this PR, so it must've gotten changed when I rebased it onto master. Will do a quick PR to fix it, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants