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 not running outside script path #1718

Closed
patrickelectric opened this issue Apr 30, 2021 · 7 comments
Closed

Isort not running outside script path #1718

patrickelectric opened this issue Apr 30, 2021 · 7 comments
Labels
question Further information is requested

Comments

@patrickelectric
Copy link

patrickelectric commented Apr 30, 2021

version: 5.8.0
image

@patrickelectric
Copy link
Author

Verbose says nothing..
image

@timothycrosley timothycrosley added the question Further information is requested label May 1, 2021
@timothycrosley
Copy link
Member

Hi @patrickelectric, it looks like (from the outside) you are experiencing the same case as: #1497 - isort uses current working directory as the src directory if you don't explicitly provide one - simply because it has nothing else to go off of! You should be able to fix this by creating a .isort.cfg at the root of your project and list out the project's source directories: https://pycqa.github.io/isort/docs/configuration/config_files/

Hope this helps!

~Timothy

@patrickelectric
Copy link
Author

patrickelectric commented May 1, 2021

Hi @timothycrosley, thanks!
We have multiple python projects under the same repository, is it possible somehow to make it run in all of them without adding each folder individually ?

With --show-files it displays all files under the folder, including this one, but it does not run as you can expect.
It sounds as a bug, because running isort $(git ls-files '*. py'), works for some files but not for others in the same root folder, what is the logic ?
How can I accomplish a global isort configuration without being to maintain each repository + isort configuration.

@timothycrosley
Copy link
Member

timothycrosley commented May 2, 2021

With --show-files it displays all files under the folder, including this one, but it does not run as you can expect.

I don't think that's correct, I think it's running it, it's just that the only src path is the run path of isort, so the output would be different. This is common among many CLI tools, as it's unavoidable without more information provided.

running isort $(git ls-files '*. py'), works for some files but not for others in the same root folder, what is the logic ?

Again, if I'm understanding correctly, it works for all files, it's just that in some of the cases you expect different grouping behavior that's based on the src files location being included as a sort path - which only happens if you cd into that directory when no config is setup up.

How can I accomplish a global isort configuration without being to maintain each repository + isort configuration.

One option would be to create and then reuse your own custom shared profile - see https://github.com/PyCQA/isort/tree/main

However, if the stated case is correct:

We have multiple python projects under the same repository, is it possible somehow to make it run in all of them without adding each folder individually ?

Just put your config as a .isort.cfg in the root of your repository and list out any source paths.

@patrickelectric
Copy link
Author

it's just that the only src path is the run path of isort, so the output would be different. This is common among many CLI tools.

This tools also provide a way to change the running directory, is there such option with isort ? like: --git-dir for git.

Just put your config as a .isort.cfg in the root of your repository and list out any source paths.

Is there a way to accomplish it via command line ?

@patrickelectric
Copy link
Author

In the end I got dirname $(git ls-files "*/setup.py") | xargs -I {} isort --src-path={} {} to do the trick, I'm not sure if there is a better way to accomplish such thing.

@timothycrosley
Copy link
Member

timothycrosley commented May 4, 2021

is there such option with isort ? like: --git-dir for git.

The only option isort uses the current directory for is to populate the default source paths. So the direct equivalent of --git-dir is indeed --src-path

Is there a way to accomplish it via command line ?

Just list one or more src paths from the command execution (this just allows you to treat multiple sub directories as if they are firstparty imports, if you have the most common case you will only need to specifiy a single src path at the root your repo)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants