pavelzw / pixi-pycharm

Conda shim for PyCharm that proxies pixi
https://pixi.sh/dev/ide_integration/pycharm
BSD 3-Clause "New" or "Revised" License
12 stars 0 forks source link

PyCharm automatic import suggestions #17

Closed tibuch closed 1 day ago

tibuch commented 2 months ago

Hi,

I have this code snippet in PyCharm:

def main(
    acquisition_dir: str,
    trace_log_files: list[str],
    order_name: str,
    barcode: str,
):
    img = imread('test.tif')

When I configure the interpreter via conda, PyCharm suggests the correct import (from tifffile import imread). Now I have configured the interpreter via pixi-pycharm, but it will not suggest any imports.

I can still write and execute the code, but I need to write the imports myself. So this is more a quality of life feature :slightly_smiling_face:

If I add the import myself, I can run the code via the configured pixi-pycharm interpreter :+1:

pavelzw commented 2 months ago

Hmm, i cannot seem to reproduce this example...

image image

This shouldn't have anything to do with using pixi or conda. I think(?) how pycharm finds these things is by finding the correct python executable and then just scanning the site-packages directory of this environment (that's what's happening when you see Updating skeletons).

Maybe pycharm just didn't refresh the skeletons yet?

tibuch commented 2 months ago

This is how it looks for me right now: issue

And I only get these suggestions: image

In the Interpreter Paths dialog I can click the refresh button, which triggers Updating skeletons. But in the end nothing changes.

Maybe I will try a fresh install of PyCharm next.

pavelzw commented 2 months ago

Hmm weird, that looks exactly like my setup... It might be that this is a general PyCharm on Linux issue. I only tested this on PyCharm for macOS since I expected that macOS and Linux behave sort-of similar...

tibuch commented 2 months ago

Sounds like a reasonable assumption.

I have no idea where this is going wrong. Also resetted the caches of PyCharm, but so far nothing worked.

tibuch commented 2 months ago

I noticed one difference. This is the External Libraries directory if I load the env via pixi-pycharm: image

This is how it looks like if I load an env with conda: image

In the second (working) screenshot lib-dynload, python3.11, and site-packages have a orange/yellow background.

Further I figured out that I can sym-link the pixi env into the envs dir of conda and add it via conda. If I do that it works as it should.

richardsheridan commented 1 day ago

Hi, found this while troubleshooting a different typing problem. Thanks for the screenshots of the External Libraries widget, it gave me an idea what the problem might be. That highlighting is for "non-project" files, so pycharm thinks that items found in the .pixi folder are actually project files. My typing symptoms went away when I excluded the .pixi folder (right click -> Mark Directory as -> Excluded).

It's not clear to me WHY the project vs non-project distinction confuses pycharm so much. However, I don't think there's anything for this project to fix, except maybe document the need to exclude the pixi folder from the project files if it is in the project folder.

pavelzw commented 1 day ago

Thanks, that sounds doable! @tibuch could you try if that fixed the issue?

tibuch commented 1 day ago

Yes, this works! Thank you @richardsheridan!

But, I can't rename the environment and they are now all called default. But I think this is another issue :slightly_smiling_face:

pavelzw commented 1 day ago

they are now all called default

xref #10