-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Ensure sorting imports in a modified file picks up the proper configuration #9128
Ensure sorting imports in a modified file picks up the proper configuration #9128
Conversation
This ensures that isort behaves consistently whether or not the file has modifications or has even been saved.
Codecov Report
@@ Coverage Diff @@
## master #9128 +/- ##
==========================================
- Coverage 61.08% 60.71% -0.37%
==========================================
Files 601 629 +28
Lines 33085 34004 +919
Branches 4671 4791 +120
==========================================
+ Hits 20209 20647 +438
- Misses 11858 12350 +492
+ Partials 1018 1007 -11
Continue to review full report at Codecov.
|
@PeterJCLaw Thank you for the PR. Can you look at the merge conflicts? |
2908250
to
58afa14
Compare
58afa14
to
62cdfda
Compare
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.
@PeterJCLaw Thanks, for the PR, however I'd consider revising the approach.
@karthiknadig /cc
I'm not a fan of passing in intput
into the process class (i think it ends up with too much responsibility).
If we're spawning a long running process, which is what execObservable
is for, then the calling code has access to the process object and it can write directly into the stdin
stream.
Else think of other CLIs, they might have muliple inputs. In such a situation the second input can be written into stdin stream only after the first one has been processed. This knowledge is available to the calling code.
Also, what if we need to pass in two lines into stdin (one after the other). For this we need to ensure the process is ready to access the input for the second item.
Considering this I'm not convinced we should be modifying processService
.
I'd like to see this being done outside this class. Elsewhere, e.g. in some isort specific class.
To me the the responsibility of exeObservable is to spawn a process, return the process along with an output stream. If required, the calling code can write directly into the intput stream.
@karthiknadig /cc |
@DonJayamanne thanks for the feedback. The change to Currently the I had hoped that it would be generally useful to be able to pass arbitrary An alternative change I had considered (but decided against) would be to have |
(meta) @karrtikr thanks for your help so far, I'll pick up any other changes tomorrow evening (I'm in GMT). |
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.
Still not a fan of input.
I leave this for @karthiknadig. @pvscteam
Feels this is an exceptional case just for one usage, which could be done by accessing the process itself.
src/client/common/process/proc.ts
Outdated
@@ -112,6 +112,11 @@ export class ProcessService extends EventEmitter implements IProcessService { | |||
}); | |||
}); | |||
|
|||
if (options.input) { |
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.
Just had a thought about this while writing the docs for it -- should we have this do an explicit null
or undefined
check, rather than this implicit one? I'm assuming that (like in Python) this implicit check will be falsey for both null
and empty string, yet the latter might end up being surprising to callers if they've explicitly provided a value which happens to be empty.
@PeterJCLaw we need to discus this with the team. Based on the decision we will let you know if we want to take this or go with @DonJayamanne 's suggestions. |
@karthiknadig just wondering if there's an update on this? |
@PeterJCLaw Sorry, we haven't gotten to this yet. We will have a discussion on this item this sprint. |
@karthiknadig I updated this for Any chance you'll be able to look at this soon? |
@PeterJCLaw We are fixing some flaky tests. We will get to this one. I will take care of addressing this. |
@PeterJCLaw Looks like
If I pass the full path it seems to work as expected.
This is causing the test to fail. This should probably be filed as a bug on |
Thanks for getting back to me.
Hrm, that's rather odd. What versions of Python and I can reproduce that issue (on Linux too) when using the latest development version of The logs do seem to indicate that CI is picking up
There are actually a couple of issues with the latest isort development branch which look like they'll affect us -- I've raised them as PyCQA/isort#1188 and PyCQA/isort#1189. Note that |
On windows 10 in am using |
Ah, I figured out why I couldn't reproduce this. I'm not sure what this means yet though. For me, this works:
But this doesn't:
I get a different diff if I change the config, so I think the config is a red herring here. I think the issue is going to be something around how pipes are handled. I can also reproduce this on both Python 3.6.8 and 3.8.2 (on Windows 10). When I'm back at my other machine I'll try the pipe spelling on Linux, I wonder if it breaks there too? (I've only ever tried the |
The test is failing on CI because it is not picking up |
@PeterJCLaw If we are always using diff and we are going to send file content over stdin in all cases, then may be we should update |
Ok, after some more digging, I don't think this relates to the configuration file at all. If I debug through I think there are a couple of issues here:
Notably, adding a few comment lines to the test file makes I've reproduced these outside Switching to using |
For
|
Yup, that sounds reasonable. I'll look at making that change this evening or tomorrow. |
It's occurred to me that this would actually mean we'd either lose support for isort command line arguments or need to parse them (albeit using the I'm currently exploring replacing |
See comment for details.
This validates that the configuration is picked up for these files.
This mostly reverts d92ceef, except for the extra test assertion it added which is still possibly useful.
SonarCloud Quality Gate failed. 5 Bugs No Coverage information |
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. We can merge this as soon as CI passes. Thanks for working on this, and the patience @PeterJCLaw 🙂
const spawnOptions = { | ||
token, | ||
throwOnStdErr: true, | ||
cwd: path.dirname(uri.fsPath) |
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.
Users expect the cwd to point to the workspace root instead: #14254.
Fixes #4891.
Has telemetry for enhancements.Tests updated in
importSortProvider.unit.test.ts
and a regression test added toextension.sort.test.ts
package-lock.json
has been regenerated by runningnpm install
(if dependencies have changed)