You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How can the community help with this? Who would be able to sign off on a proposal to solve this? Which part of the code base would need to be impacted? Thanks!
Which portion of this isn't working? Pyright (the type checker that pylance is built upon) already supports pth files, so I would think that this would already work.
It would be helpful if you could provide a specific example project, set of installation steps, and an indication of expected vs. observed behaviors for that project.
Note here the pth file does not inject the path as normally does but rather installs a custom import hook that resolves imports. So the pth file support does not work. Here you need custom import hook support, or something like that.
Are you saying that the code is dynamically modifying the module map? Static analysis tools like linters, language servers, and type checkers (including pylance) do not execute the Python code. If the behavior is completely dynamic, then we probably won't be able to make PEP 660 work with pylance. Is there a way for pylance to statically find the editable install without executing any Python code?
Are you saying that the code is dynamically modifying the map module?
It's dynamically adding the foo module as an editable install (e.g. settings things up so imports pull from the source code in the workspace and not somewhere in site-packages).
If this is an entirely dynamic mechanism, that would be really unfortunate. We probably won't be able to support it in pylance then, and we'll need to recommend against anyone using it if they want to take advantage of any static analysis tools or language servers.
Can we come up together with a mechanism that provides enough info for the IDE/language server on what's being done, that perhaps the backends can call? E.g. in this case we could say module x is available at path Y in a JSON file? (and at runtime would be an import dynamic hook, but the language server would know from where to materialize it by using the static analysis tools).
If this is an entirely dynamic mechanism, that would be really unfortunate.
This mechanism is, yes.
https://peps.python.org/pep-0660/ outlines how to tell build tools the user wants an editable install, but it doesn't prescribe the solution. The one mentioned here is one possible approach, but it's also the one gaining traction.
As Bernát Gábor (@gaborbernat) mentioned while I was typing this, can the Pylance team and the packaging community collaborate on a solution that build tools can use in order to support editable installs but is defined in such a way you can process the information appropriately?
The import resolution mechanism in Python is already incredibly complex and customizable. Do we really need yet another incompatible mechanism that the entire ecosystem needs to now implement? Why can't this mechanism make use of "pth" files so the location of the library is automatically added to the import resolution paths?
If PEP 660 is incomplete and didn't take into account static analysis tools, that's a big miss. It sounds like a follow-on PEP — or an amendment to PEP 660 — may be required to fix the problem.
Why can't this mechanism make use of "pth" files so the location of the library is automatically added to the import resolution paths?
The big problem with pth files is that they are very strict and does not allow you to handle files generated during the build 🤔 What would be a good API for pylance, that could somehow handle files generated dynamically. To bring up an example imagine you have a JSON Schema and you're generating the python code from it during package build time via https://pydantic-docs.helpmanual.io/datamodel_code_generator
Import resolution should not require tools to open source files and scan for comments. I'll give you points for creativity, but let's keep looking for better options.
This is probably not the right forum to be discussing this. We should move this to typing-sig or some other forum where other tools developers can weigh in.
This is probably not the right forum to be discussing this. We should move this to typing-sig or some other forum where other tools developers can weigh in.
Tool developers don't hang out in that forum. You will get more attention from them if you post in the typing-sig or the discussions section of python/typing.
But this isn't related to the typing system. This is purely about packaging 🤔 and this issue was a call for input from the PyLance team 🤔 there's no point in us agreeing on something that the pylance team then doesn't adopt.
Bernát Gábor (@gaborbernat), this is an issue that goes beyond pylance. A viable solution must also work for other static analysis tooling (mypy, pytype, pyre, pylint, PyCharm, etc.). If you want to engage with authors of static analysis tools and get their support, you need to go to the forums where they hang out, and you need to work with that community on a standard.
If the standard involves one of the existing mechanisms for discovering import resolution paths in a static manner (as I recommend), then there will be no need for pylance or any other existing tools to do any work to support PEP 660.
If there is some new mechanism required, then it should take the form of a PEP that goes through the normal review and ratification process. Once a mechanism is agreed upon, pylance will implement support for it.
I just noticed that you started a thread on the typing-sig mailing list. Thanks for doing that! I'm hopeful that we'll receive some good ideas and input from the broader community within that discussion forum.
Activity
brettcannon commentedon Feb 22, 2022
Discussion about adding support in various editors has now been opened at https://discuss.python.org/t/pep-660-support-and-ides/13878 .
gaborbernat commentedon Mar 22, 2022
How can the community help with this? Who would be able to sign off on a proposal to solve this? Which part of the code base would need to be impacted? Thanks!
erictraut commentedon Mar 22, 2022
Which portion of this isn't working? Pyright (the type checker that pylance is built upon) already supports pth files, so I would think that this would already work.
It would be helpful if you could provide a specific example project, set of installation steps, and an indication of expected vs. observed behaviors for that project.
gaborbernat commentedon Mar 22, 2022
Note here the pth file does not inject the path as normally does but rather installs a custom import hook that resolves imports. So the pth file support does not work. Here you need custom import hook support, or something like that.
erictraut commentedon Mar 22, 2022
Are you saying that the code is dynamically modifying the module map? Static analysis tools like linters, language servers, and type checkers (including pylance) do not execute the Python code. If the behavior is completely dynamic, then we probably won't be able to make PEP 660 work with pylance. Is there a way for pylance to statically find the editable install without executing any Python code?
brettcannon commentedon Mar 22, 2022
It's dynamically adding the
foomodule as an editable install (e.g. settings things up so imports pull from the source code in the workspace and not somewhere insite-packages).erictraut commentedon Mar 22, 2022
If this is an entirely dynamic mechanism, that would be really unfortunate. We probably won't be able to support it in pylance then, and we'll need to recommend against anyone using it if they want to take advantage of any static analysis tools or language servers.
gaborbernat commentedon Mar 22, 2022
Can we come up together with a mechanism that provides enough info for the IDE/language server on what's being done, that perhaps the backends can call? E.g. in this case we could say module x is available at path Y in a JSON file? (and at runtime would be an import dynamic hook, but the language server would know from where to materialize it by using the static analysis tools).
brettcannon commentedon Mar 22, 2022
This mechanism is, yes.
https://peps.python.org/pep-0660/ outlines how to tell build tools the user wants an editable install, but it doesn't prescribe the solution. The one mentioned here is one possible approach, but it's also the one gaining traction.
As Bernát Gábor (@gaborbernat) mentioned while I was typing this, can the Pylance team and the packaging community collaborate on a solution that build tools can use in order to support editable installs but is defined in such a way you can process the information appropriately?
erictraut commentedon Mar 22, 2022
The import resolution mechanism in Python is already incredibly complex and customizable. Do we really need yet another incompatible mechanism that the entire ecosystem needs to now implement? Why can't this mechanism make use of "pth" files so the location of the library is automatically added to the import resolution paths?
erictraut commentedon Mar 22, 2022
If PEP 660 is incomplete and didn't take into account static analysis tools, that's a big miss. It sounds like a follow-on PEP — or an amendment to PEP 660 — may be required to fix the problem.
gaborbernat commentedon Mar 22, 2022
The big problem with pth files is that they are very strict and does not allow you to handle files generated during the build 🤔 What would be a good API for pylance, that could somehow handle files generated dynamically. To bring up an example imagine you have a JSON Schema and you're generating the python code from it during package build time via https://pydantic-docs.helpmanual.io/datamodel_code_generator
12 remaining items
erictraut commentedon Mar 24, 2022
No, that's not how language servers work.
Import resolution should not require tools to open source files and scan for comments. I'll give you points for creativity, but let's keep looking for better options.
This is probably not the right forum to be discussing this. We should move this to typing-sig or some other forum where other tools developers can weigh in.
gaborbernat commentedon Mar 25, 2022
The forum for that is https://discuss.python.org/t/pep-660-support-and-ides/13878/9 but tool developers doesn't seem to weigh much in 😊
erictraut commentedon Mar 25, 2022
Tool developers don't hang out in that forum. You will get more attention from them if you post in the typing-sig or the discussions section of python/typing.
gaborbernat commentedon Mar 25, 2022
But this is a topic about packaging why would open a discussion on the unrelated typing forum?
judej commentedon Apr 19, 2022
Until the typing community and the packaging community agree on a direction, there is nothing that Pylance can do.
gaborbernat commentedon Apr 20, 2022
But this isn't related to the typing system. This is purely about packaging 🤔 and this issue was a call for input from the PyLance team 🤔 there's no point in us agreeing on something that the pylance team then doesn't adopt.
erictraut commentedon Apr 20, 2022
Bernát Gábor (@gaborbernat), this is an issue that goes beyond pylance. A viable solution must also work for other static analysis tooling (mypy, pytype, pyre, pylint, PyCharm, etc.). If you want to engage with authors of static analysis tools and get their support, you need to go to the forums where they hang out, and you need to work with that community on a standard.
If the standard involves one of the existing mechanisms for discovering import resolution paths in a static manner (as I recommend), then there will be no need for pylance or any other existing tools to do any work to support PEP 660.
If there is some new mechanism required, then it should take the form of a PEP that goes through the normal review and ratification process. Once a mechanism is agreed upon, pylance will implement support for it.
erictraut commentedon Apr 20, 2022
I just noticed that you started a thread on the typing-sig mailing list. Thanks for doing that! I'm hopeful that we'll receive some good ideas and input from the broader community within that discussion forum.