Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure auto-import to omit src from import statements #753

Open
daara-s opened this issue Feb 5, 2024 · 3 comments
Open

Configure auto-import to omit src from import statements #753

daara-s opened this issue Feb 5, 2024 · 3 comments

Comments

@daara-s
Copy link

daara-s commented Feb 5, 2024

Is your feature request related to a problem? Please describe.
I work in python projects that use poetry for dependency management, and use a src/ folder for the repository. When importing an anything from within the repo, rope defaults to importing relative to the root directory, instead of from the package source.
e.g.

from src.REPO.x import y

Describe the solution you'd like
I'd like to be able to set a configuration for rope (eg in pytool.toml) to tell Rope to not reference the src in the import, and instead just use the repo name.
e.g.

from REPO.x import y

Describe alternatives you've considered
See discussion in pylsp: python-lsp/python-lsp-server#525

I've experimented with changing the existing config of python_files and source_folders, but this hasn't given much success.

Additional context
I use rope as part of pylsp.

@daara-s
Copy link
Author

daara-s commented Feb 5, 2024

I've created a repo to show an example of what currently happens when using rope in pylsp for importing a function:
https://github.com/daara-s/poetry-repo-example/tree/master/my-package

@bagel897
Copy link
Contributor

bagel897 commented Feb 6, 2024

It'd be better to have it automatically use another venv path. You can probably do this in pylsp by editing the rope config.

@lieryan
Copy link
Member

lieryan commented Feb 6, 2024

pytool.toml is global config file, unless you want this to be applied to all of your projects (which is unlikely), you'll likely want to use a local config file for this purpose, rope reads [tool.rope] section in pyproject.toml but projectroot is given by the integration (pylsp in this case) rather than something you can configure from pyproject.toml.

Maybe rope could read poetry's section in pyproject.toml to find the real application's root? The Project(projectroot) is where you might want to poke around to see if setting the projectroot as projectroot (from editor/lsp server) / src_path_from_pyproject_toml might work.

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

No branches or pull requests

3 participants