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

Integration with PyCharm #258

Closed
ramusus opened this issue Feb 20, 2015 · 18 comments
Closed

Integration with PyCharm #258

ramusus opened this issue Feb 20, 2015 · 18 comments

Comments

@ramusus
Copy link

ramusus commented Feb 20, 2015

Is it possible to integrate isort features to PyCharm ?

@benkonrath
Copy link

I'm interested in this as well.

@septs
Copy link

septs commented Mar 17, 2015

Want to support PyCharm.

@jmfederico
Copy link

Super interested in this!

@teeberg
Copy link
Contributor

teeberg commented Apr 23, 2015

You can set up an external tool like this:
screen shot 2015-04-23 at 11 16 46 am
screen shot 2015-04-23 at 11 17 56 am
Then, you can even bind it to a shortcut for easy access:
screen shot 2015-04-23 at 11 20 45 am

@ramusus
Copy link
Author

ramusus commented Apr 25, 2015

awesome, thanks a lot for solution!

@ramusus ramusus closed this as completed Apr 25, 2015
@redpublic
Copy link

It does not work correctly if isort placed somewhere outside of project, i.e. ~/.virtualenvs/*
3rd party modules and project modules are merged together
Though I guess it is pycharm problem - it uses full path when running external program

@teeberg
Copy link
Contributor

teeberg commented Apr 26, 2015

isort does not always correctly detect which modules are third-party and which ones are yours. You can tell it to treat certain modules as third-party by passing -o module_name (-o is short for --thirdparty according to isort --help). I ended up creating an .isort.cfg in my project's top level folder which contains a section like this:

[settings]
known_third_party=caching,provider

This can then be nicely versioned and everybody in your team is on the same page. :-) From inside pycharm, I'm then invoking isort as

$PyInterpreterDirectory$/isort --settings-path $ProjectFileDir$ $FilePath$

Looking at the code, it treats all packages as third-party that have either site-packages or dist-packages in their import path. That probably doesn't include any packages that you installed via pip install -e.

@ramusus
Copy link
Author

ramusus commented Apr 26, 2015

+1 for the trick with settings

@redpublic
Copy link

Thanks for $PyInterpreterDirectory$/isort
I have been running system wide isort which does not have many of project specific 3rd party modules that is why it treated them and project modules the same way.

@teeberg
Copy link
Contributor

teeberg commented May 31, 2016

As of #434, you can now also simply pass --virtual-env <dir> to isort, wherever it is installed

@mr-bo-jangles
Copy link

No longer needed, Pycharm does this itself now :)

@Skyross
Copy link

Skyross commented Aug 31, 2017

@teeberg Update the solution with the description for "Output Filters setup" for console clickable links
https://www.jetbrains.com/help/pycharm/2017.2/add-edit-filter-dialog-2.html?utm_medium=help_link&utm_source=from_product&utm_campaign=PY&utm_content=2017.2

@teeberg
Copy link
Contributor

teeberg commented Aug 31, 2017

@Skyross my console output only shows:

/Users/jonas/code/project/env/bin/isort --settings-path /Users/jonas/code/project --virtual-env=/Users/jonas/code/project/env/bin/../ /Users/jonas/code/project/api.py

Process finished with exit code 0

which part of that do you want to make clickable?

@Skyross
Copy link

Skyross commented Sep 22, 2017

@teeberg In a case of having any errors in sorting. You will get some output with file paths if you run without automatic reformatting. If you running any --diff command for example.

@teeberg
Copy link
Contributor

teeberg commented Sep 22, 2017

@Skyross I'm not sure if you're asking how to do that or if you're asking me to include those instructions in the guide above. If the former, adding this output filter did it for me:
image
However, the way I set up the example above, it always runs on the file that you currently have open anyway, so any filenames that could be matched in the output would just point back to the file that's already open. So I'm still not clear about what you're trying to accomplish. How did you set up isort in pycharm?

@mpasternak
Copy link

mpasternak commented Apr 13, 2020

I was unable to set it up like that, because PyCharm kept running isort external tool without proper paths to virtual environment.

I needed to hardcode the path (think export PYTHONPATH=/Users/mpasternak/envs/bpp/lib/python3.7/site-packages/ ) in the shell script, then run that shell script, then run sort.

Without it, isort as ran by PyCharm was unable to import isort.main

If anybody got a cleaner solution, help welcome.

@rohe
Copy link

rohe commented Jun 26, 2020

If I set up isort as an external tool it seems to be a general setting for PyCharm that is used across all projects I'm working on.
Is there a way to set project specific working directory ??
Or is there a way to say: use the projects root directory ?

@atten
Copy link

atten commented Aug 11, 2021

This configuration automatically picks current virtualenv and working dir:
image

DouglasVSegatto referenced this issue in ferruzzi/scrapheap Dec 6, 2023
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

No branches or pull requests