-
Notifications
You must be signed in to change notification settings - Fork 56
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 only if imports at the top of the module were edited #238
Conversation
a7c5a32
to
1506c0b
Compare
1506c0b
to
52d841a
Compare
52d841a
to
fdee550
Compare
7cc0ecf
to
031b52a
Compare
031b52a
to
f0e5a4e
Compare
893aca7
to
b5b5f61
Compare
f43bed5
to
7504757
Compare
7504757
to
a844515
Compare
f31df3a
to
51dc438
Compare
50df263
to
c31ed4e
Compare
@yajo, I noticed you gave a thumbs up for this idea in #72. I could include this change in release 1.5.0 – would you be able to do a code review of my pull request here? |
c31ed4e
to
ed09310
Compare
177ff90
to
b6d95b2
Compare
I hopefully managed to clarify the changes a bit in the description of this PR to make reviewing easier. @roniemartinez would you happen to have a bit of time to do a sanity check on this patch? |
This is in preparation for using it when applying isort as well.
It will be reused in isorting. Also renamed some arguments and variables for clarity.
a60a9a0
to
a38fe64
Compare
I've got no idea about the code sorry 😕 However I've tested this and it doesn't seem to do any isort at all. I'm not sure if I'm testing well, though. AFAICS only black runs: Kooha-04-08-2022-07-31-04.mp4 |
@yajo, thanks for testing this! You do need the Is there something we could do to improve documentation so this becomes more obvious? |
@roniemartinez, if the review feels too messy, I could also separate out e.g. the variable renames, function refactorings and |
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.
LGTM
Thanks @roniemartinez! We're getting close to a 1.5.0 release! |
Fixes #72:
The changes are pretty involved. Here's a summary for reviewers:
src/darker/__main__.py:
path_in_repo
->relative_path_in_rev2
src
->absolute_path_in_rev2
relative_path
->relative_path_in_rev2
_isort_and_blacken_single_file()
and_isort_and_blacken_single_file()
now acceptEditedLinenumsDiffer
object instead of creating its ownsrc/darker/git.py:
get_rev1_path()
toget_path_in_repo()
src/darker/import_sorting.py:
apply_isort()
nowEditedLinenumsDiffer
object instead of creating its ownisort
arguments are created in_build_isort_args()
isort
is invoked in_call_isort_code()
isort
_diff_overlaps_with_edits()
does the meat of the new functionality: it checks whether the range of user edits touches the range of reformatted importssrc/darker/diff.py:
diff_chunks()
now combinesdiff_and_get_opcodes()
andopcodes_to_chunks()
behind one call