Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Python inspector service#1090

Merged
jakebailey merged 19 commits intomicrosoft:masterfrom
jakebailey:python-inspector-service
May 20, 2019
Merged

Python inspector service#1090
jakebailey merged 19 commits intomicrosoft:masterfrom
jakebailey:python-inspector-service

Conversation

@jakebailey
Copy link
Copy Markdown
Member

@jakebailey jakebailey commented May 15, 2019

Opening to get some feedback and thoughts.

The inspector is a partial JSON-RPC server, which takes requests from the LS. Adding more methods is pretty simple, just decorate a function.

Right now, all it does is get the module member names and __all__. This is marginally useful (especially since it's not used anywhere), but we can add more methods to do something like the scraper for full type info, or check for installed versions, etc.

Some things I'm not sure about are:

  • If the process dies, it will be restarted, but the requests that were issued to the crashed process will fail and throw.
  • The process should periodically be killed to save on memory.
  • The scraper takes extra arguments for path modification which I'm not sure I can really handle due to the process persisting (see initial_import in scrape_module.py).
  • Because this uses StreamJsonRpc, I have to implement it in the language server assembly, otherwise the analysis has to depend on that library. The best I can do is declare the interface outside of the LS, but where I've declared it is probably wrong.
  • Because StreamJsonRpc is all async, using the inspector in the analyzer requires some weird tasking (I did a hack in PythonModule to call the inspector for GetModuleMembers, which meant Services.GetService<IPythonInspector>()?.GetModuleMemberNames(Name)?.Result?.Members; not thrilling).

@jakebailey jakebailey changed the title [WIP] Python inspector service Python inspector service May 20, 2019
@jakebailey
Copy link
Copy Markdown
Member Author

Right now, this can give back module members/__all__, and try to find the version of a module through pkg_resources. If the process dies, then the pending requests will fail, but further requests will restart the process. The service could be disposed at any time to trigger a restart (though it's somewhat of a hack and not thread safe; it doesn't keep a pending request count to know it's safe to restart).

It's only used in its own tests. I have some stashed code that would go into PythonModule to grab info from the service, but it's a bit hacky and it'll be better to wait until this can be a provider for information (alongside the real analysis or database, etc).

Comment thread src/Analysis/Ast/Impl/Inspection/IPythonInspector.cs Outdated
@jakebailey jakebailey merged commit 09dc4a0 into microsoft:master May 20, 2019
@jakebailey jakebailey deleted the python-inspector-service branch May 20, 2019 20:37
jakebailey added a commit to jakebailey/python-language-server that referenced this pull request Nov 1, 2019
Add python inspector, a JSON-RPC subprocess to make queries to python for info.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants