Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- #786 Upgrade Actions used in Github Workflows (@lieryan)
- #785 Refactoring movetest.py (@lieryan)
- #788 Introduce the `preferred_import_style` configuration (@nicoolas25, @lieryan)
- #814 Treat `ignored_resources` as non-project files for autoimport purposes (@smheidrich)

# Release 1.13.0

Expand Down
6 changes: 5 additions & 1 deletion rope/contrib/autoimport/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ def get_package_source(
"""Detect the source of a given package. Rudimentary implementation."""
if name in sys.builtin_module_names:
return Source.BUILTIN
if project is not None and project.address in str(package):
if (
project is not None
and project.address in str(package)
and not project.is_ignored(project.get_file(str(package)))
):
return Source.PROJECT
if "site-packages" in package.parts:
return Source.SITE_PACKAGE
Expand Down
24 changes: 24 additions & 0 deletions ropetest/contrib/autoimport/utilstest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Tests for autoimport utility functions, written in pytest"""

import venv
from pathlib import Path

from rope.contrib.autoimport import utils
Expand All @@ -22,6 +23,29 @@ def test_get_package_source_pytest(example_external_package_path):
assert source == Source.SITE_PACKAGE


def test_get_package_source_venv_in_project_dir(example_external_package_path, project):
# Many Python dev tools create .venv folders inside the project directory.
# Modules in such folders should count as SITE_PACKAGE files despite
# technically being inside the project folder.

# Set up actual venv in project folder:
project_venv_path = project.root.pathlib/".venv"
venv.create(project_venv_path)

# Crude approximation of a package installed into this venv:
project_venv_site_packages_path = next(project_venv_path.glob("**/*site-packages"))
project.prefs["python_path"].append(project_venv_site_packages_path)
module_path = project_venv_site_packages_path / "foo.py"
module_path.touch()

# Such directories are normally part of `ignored_resources` (e.g. `.venv`
# is in there by default):
project.prefs["ignored_resources"] += [".venv"]

source = utils.get_package_source(module_path, project, "foo")
assert source == Source.SITE_PACKAGE


def test_get_package_source_typing(typing_path):
assert utils.get_package_source(typing_path, None, "typing") == Source.STANDARD

Expand Down
Loading