-
Notifications
You must be signed in to change notification settings - Fork 175
Description
Describe the bug
When Rope's autoimport finds packages that are installed in a virtualenv placed within the project folder (typically named .venv by convention), it assigns them the package source PROJECT, even though SITE_PACKAGES would be correct because such venvs contain dependencies rather than files belonging to the project itself.
To Reproduce
Steps to reproduce the behavior:
- Create a virtualenv folder
.venvin the current directory, e.g.python3 -m venv .venv. - Activate the venv:
. .venv/bin/activate - Install
pytestas an example external dependency:pip install pytest - Run this script which calls autoimport's
get_package_sourceto try and findpytest's package source type:
from rope.base.project import Project
from rope.contrib.autoimport import utils
project = Project(".")
resource = project.find_module("pytest")
source = utils.get_package_source(resource.pathlib, project, "pytest")
print(source)Expected result
Source.SITE_PACKAGES because it's an external dependency installed in a .venv folder (and even has site-packages in its full path).
Actual result
Source.PROJECT
Screenshots
Not needed.
Editor information (please complete the following information):
No editor needed, Rope 1.13 or master, doesn't matter.
Additional context
Tools like python-lsp-server that use Rope's autoimport functionality factor in the package type when sorting the suggestions, as people normally want results from within the project itself show up higher in the list. This bug makes those results much worse, of course.