Skip to content

Conversation

@last-partizan
Copy link
Contributor

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

  • generate_cache creates project-specific cache
  • generate_module_cache creates cache of system/venv modules.

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):

  • I have added tests that prove my fix is effective or that my feature works (not yet)
  • I have updated CHANGELOG.md (not yet)

pass
else:
# If path includes "site-packages", we're interested in part after this.
rel_path_parts = rel_path_parts[site_packages_index + 1:]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's temporary code from my first attempt, but we probably need to leave here a check for no "site-packages" in path. Just in case.

Comment on lines +228 to +237
extra_ignores = [
p.pathlib.relative_to(self.root.pathlib)
for p in self.get_python_path_folders()
if p.pathlib.is_relative_to(self.root.pathlib)
and "site-packages" in p.pathlib.parts
]
for p in extra_ignores:
# I'm using this approach, because self.prefs.add after _init_prefs
# does not work for some reason.
prefs["ignored_resources"].append(str(p))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's my second attempt, and i need feedback here.

Is it good approach, or maybe some other ideas?

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

Successfully merging this pull request may close these issues.

1 participant