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

Can't locate settings when using stdin on isort 5 #1289

Closed
fsouza opened this issue Jul 6, 2020 · 3 comments
Closed

Can't locate settings when using stdin on isort 5 #1289

fsouza opened this issue Jul 6, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@fsouza
Copy link

fsouza commented Jul 6, 2020

Hi there!

Thank you very much for this cool tool! This seems to be a regression from isort 4. I use isort integrated with my text editor, which means I send the file contents via stdin. In the past, isort was able to use the .isort.cfg in the current directory, but that doesn't seem to be the case anymore.

Here's how to reproduce:

% cat .isort.cfg
[settings]
force_single_line = True
% cat file.py
from os.path import abspath, dirname, join

print(join(abspath(dirname(__file__)), "some", "thing"))

With isort 4.3.21:

% isort --version

/#######################################################################\

     `sMMy`
     .yyyy-                                                      `
    ##soos##                                                    ./o.
          `     ``..-..`         ``...`.``         `   ```` ``-ssso```
     .s:-y-   .+osssssso/.     ./ossss+:so+:`    :+o-`/osso:+sssssssso/
     .s::y-   osss+.``.``     -ssss+-.`-ossso`   ssssso/::..::+ssss:::.
     .s::y-   /ssss+//:-.`   `ssss+     `ssss+   sssso`       :ssss`
     .s::y-   `-/+oossssso/  `ssss/      sssso   ssss/        :ssss`
     .y-/y-       ````:ssss`  ossso.    :ssss:   ssss/        :ssss.
     `/so:`    `-//::/osss+   `+ssss+-/ossso:    /sso-        `osssso/.
       \/      `-/oooo++/-      .:/++:/++/-`      ..           `://++/.


         isort your Python imports for you so you don't have to

                            VERSION 4.3.21

\########################################################################/
% cat file.py | isort -
from os.path import abspath
from os.path import dirname
from os.path import join

print(join(abspath(dirname(__file__)), "some", "thing"))

With isort 5.0.4:

% isort --version

                 _                 _
                (_) ___  ___  _ __| |_
                | |/ _/ / _ \/ '__  _/
                | |\__ \/\_\/| |  | |_
                |_|\___/\___/\_/   \_/

      isort your imports, so you don't have to.

                    VERSION 5.0.4

% cat file.py | isort -
from os.path import abspath, dirname, join

print(join(abspath(dirname(__file__)), "some", "thing"))

It works if I pass the file as parameter though:

% isort -d file.py
from os.path import abspath
from os.path import dirname
from os.path import join

print(join(abspath(dirname(__file__)), "some", "thing"))

Is there a way to either (1) start the search from the current directory (like isort 4 did) or (2) allow users to pass the file path when formatting stdin (similar to prettier's --stdin-filepath)

fsouza added a commit to fsouza/dotfiles that referenced this issue Jul 7, 2020
@timothycrosley timothycrosley added the bug Something isn't working label Jul 8, 2020
@timothycrosley
Copy link
Member

Thanks for reporting! I've fixed this in isort 5.0.5 so that when - is used, settings are found from the current working directory. Note that isort also allows a --settings-path to be explicitly provided (and that can just be the path that the file is in, it will look up to 25 directories up from that point for a support settings file).

@fsouza
Copy link
Author

fsouza commented Jul 8, 2020

Ohh thanks for the info and the quick fix. I thought --settings-path was for explicitly specifying the path to the settings file, my bad x)

@sirosen
Copy link

sirosen commented Jul 15, 2020

I just experienced this on 5.1.0 using vim's ALE. I was able to get things working again by adding let g:ale_python_isort_options = '--settings-path .', which suggests that somehow the fix hasn't taken or maybe there was a regression.

There's also an ALE issue about this, which is where I learned about the workaround, but it seems like the desired behavior is for isort to have --settings-path . when called as isort - < /tmp/foo.py. (So that issue should probably be closed. I might follow-up there if this is sorted out here.)

I'm using pyproject.toml config, if that's relevant.

I'm happy to provide more detailed info if it's useful (e.g. platform, python version).


As always, thanks for the awesome tool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants