python-rope / rope

a python refactoring library
GNU Lesser General Public License v3.0
1.96k stars 164 forks source link

fix: Fix import paths with `site-packages` as part of package name #756

Open last-partizan opened 8 months ago

last-partizan commented 8 months ago

Description

This is another fix, related to #722, i just started using python-lsp-server and rope for autoimports, and noticed it includes .direnv.python-3.11.lib.python3.11 as part of module name when importing.

We need to cut part of the path to site-packages, to generate correct import name.

That was my first attempt to fix this, but turned that wasn't a problem. The problem was, in my case - that local venv .venv was included in project resources.

As far as i understand, we have two caches

And when .venv is in the same dir as a project, it was included in project files.

My current first attempt just filters out path if it has "site-packages" in it, but, maybe we need smarter solution, for example:

get_python_files should exclude any file from get_python_path_folders (except project root).

For this i need some guidance, @tkrabel @lieryan

Checklist (delete if not relevant):