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

Custom import handling #1408

Closed
jesse-sony opened this issue Sep 24, 2019 · 2 comments
Closed

Custom import handling #1408

jesse-sony opened this issue Sep 24, 2019 · 2 comments

Comments

@jesse-sony
Copy link

jesse-sony commented Sep 24, 2019

I work in a company that has its own python library for managing paths and imports. In our code, you'll see things like:
moduleName = importer.importPackage('moduleName')
which does a lot of work under the hood in figuring out what moduleName refers to, where on disk it lives, puts that path on the sys.path, and then asks python to import it. We've written a pylint plugin that makes this work in pylint; it walks the AST and everywhere it finds one of those calls, it does a similar lookup to find where the module lives and then tells pylint to parse it and add it as an import to the current module.

I'm wondering about the feasibility of adding support for something like this to Jedi. We've started using Jedi a lot more recently and while it works great for normal style imports, anytime it hits any of our custom imports, we don't get any auto-completion. It seems that Jedi cannot current support something like this (no plugin interface). I was wondering if such a thing would be possible and consistent with Jedi's design. I'm happy to help contribute code towards that end if such a thing would be considered.

@davidhalter
Copy link
Owner

There is a plugin interface (look at jedi.plugins.builtins). It's just that it's not public. While your use case can work easily with that plugin system, it's just not documented and "stable".

So feel free to implement something that plugs into that (or possibly just fork Jedi, it's probably the easiest way). However I will not support you if you go down that road (Consulting is of course possible).

It's also quite possible that Jedi will change the API and you will need to rewrite some things. But it could definitely be beneficial for you guys.

As a side note I would probably recommend you guys to use the sys.meta_path stuff. That stuff could potentially also work with Jedi and you can still use normal imports while still doing magic. What you guys did is probably a bad idea.

@davidhalter
Copy link
Owner

I'm closing in favor of #626.

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

2 participants