akaihola / darker

Apply black reformatting to Python files only in regions changed since a given commit. For a practical usage example, see the blog post at https://dev.to/akaihola/improving-python-code-incrementally-3f7a
https://pypi.org/project/darker/
Other
638 stars 55 forks source link

Respect isort's `skip_glob` setting #751

Open akaihola opened 1 month ago

akaihola commented 1 month ago

Fixes #615.

akaihola commented 1 month ago

@ranelpadon I started by successfully adding a failing unit test. Next, looking deeper into the reason for the wrong behavior. It's somehow related to the fact that Darker calls isort's API directly instead of running it as a subprocess.

I invited you as a collaborator on this repository, hoping you could be the reviewer for this PR. Would you have time for that?

akaihola commented 1 month ago

Ok @ranelpadon there seem to be two reasons for isort ignoring skip_glob =:

  1. a bug in passing the directory of the configuration file to isort
  2. we pass Python code directly to isort.code instead of letting it read the file from the disk (see darker.import_sorting:137), and in this case isort simply disregards the skip_glob = setting (see isort.api:188)

Reason 1. is easily fixed, but 2. is a trickier one. I'll need to spend a little more time on it.

akaihola commented 1 month ago

Not so difficult to fix after all. @ranelpadon could you verify that this branch works for you?

This PR is best reviewed one commit at a time.