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 does not search for config when using --filename #1989

Closed
karthiknadig opened this issue Nov 9, 2022 · 2 comments · Fixed by #1992
Closed

isort does not search for config when using --filename #1989

karthiknadig opened this issue Nov 9, 2022 · 2 comments · Fixed by #1992

Comments

@karthiknadig
Copy link

If you have files in this structure:

project
   |- sub-package
        |- pyproject.toml
        |- something.py       

say that pyproject.toml configures for profile black.

Then, this works (picks up the profile black):

C:\project> python -m isort C:\project\sub-package\something.py

but this does not:

C:\project> type C:\project\sub-package\something.py | python -m isort - --filename C:\project\sub-package\something.py

but this does (notice the CWD)

C:\project\sub-package> type C:\project\sub-package\something.py | python -m isort - --filename C:\project\sub-package\something.py

In VS Code extension for isort we are using the stdin way to perform sorting. This is need to support the organize import on save capability. I was able to simulate the same problem using type (on windows) and cat (on linux).

reference issue: microsoft/vscode-isort#138

@karthiknadig
Copy link
Author

Related: #1940

@kaste
Copy link
Contributor

kaste commented Nov 11, 2022

This looks like introduced via 0973421
which looks like a very strange commit because it just removes a line and it is not obvious why this should be okay. The line was introduced like a hotfix here: c0ebbd0

So generally the workaround is to just use --settings_path but with a path not the absolute file name. (--filename is a config option just used for the stdin case and basically does a settings_path = dirname(filename). I do a possible PR here but wasted now an hateful hour or so to get poetry to install this package, let alone run the tests. Damn.

Because isort depends on pip (>=21.1.1) which doesn't match any versions, version solving failed.

kaste added a commit to kaste/isort that referenced this issue Nov 11, 2022
Fixes PyCQA#1989

`--filename` is a shortcut setting used only in the stdin case to set
the `settings_path`.
Generally, `--settings-path=<file_path>` == `--filename=<filename>`
should hold.

This functionality was removed in 0973421 (Reuse config when items
passed in through stdin as used when items passed in explicitly).
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 a pull request may close this issue.

2 participants