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
pip needs an API that can be used by build automation #2450
Comments
I want this too. Specifically a way to get dependencies and check a packages availability pypi. |
I want this too. Edit: I am using |
Most of the requested APIs can be handled in a supported manner by calling pip as a command using the We understand the desire for a pip API, but "just providing it" isn't as simple as it seems. Pip is designed as a command line program, not as a library, so the internal APIs are not really designed to be exposed. Also, there are risks to installing/uninstalling packages in a running Python process (the Python import machinery isn't designed with that scenario in mind) so even if we did provide an API, it would probably come with a lot of warnings and caveats anyway... |
@pfmoore the behavior @andy-maier and I requested should not un/install packages. We want an api to package meta-data. I also wanted an api for resolving package dependencies, but IIRC this isn't possible with pip's current architecture because it isn't determined before install time. |
local metadata is available via packaging and/or setuptools pkg_ressources |
... and the original request on this issue was for install/uninstall, which @andy-maier said he wanted too, hence my comment. Searching on PyPI is pretty trivial using the XMLRPC API directly, and distlib provides functions for that if you prefer a "pre-packaged" version. As @RonnyPfannschmidt says, for dependency info, For remote files, dependency data isn't exposed. That's a limitation of current metadata. The only way of getting dependency information for an uninstalled package is to download it, unpack it, and run |
@pfmoore Yes, I get that you want to keep the current API's internal and not have stable API through them. This request wasn't a matter of doing that but instead formulating an API something that works with the regular commands, potentially with better error handling. Eg distinguishing between fatal and non-fatal uninstallation errors currently involves parsing console output |
OK, then I suggest that you check the setuptools, distlib and packaging APIs. And possibly elsewhere on PyPI. They may have what you want. If not, then it should be possible to write a module (and publish it on PyPI) that does what you want. I'm not clear why this has to be in pip. If you do have a reason why it must be in pip, then you could create a PR proposing the API you require, It wouldn't be easy to get it accepted, as you'd need to address all the existing reservations the pip devs have about exposing a stable API, as well as explaining how the proposed API would avoid acting as the "thin end of the wedge", prompting more and more requests for APIs in other areas. But if you feel that the effort is worth it, then by all means submit a PR. Personally, I doubt there's any real need for something like this to be in pip, as opposed to a separate project. |
I still disagree with above since imo such a library would as far as I see it basically be re-implementation of pip internals and if it would actually be high quality, pip would have little room for existing other than as a shim on top of it. However, I'm not going to proceed with the PR against pip and will withdraw my feature request since obviously developers disagree with the idea of the API in pip despite the severe limitations using pip in any automations currently has |
Note that as a user, I'd be interested in such a library, I wasn't just suggesting a theoretical option. I don't see how it would re-implement pip, as it's specifically been noted that it won't do installs, which is a huge part of the complexity of pip. But if you don't want to pursue the idea, that's fine. Thanks for the suggestion in any case. |
@pfmoore See my first comment. This feature request's scope was API to do installs, upgrades, uninstalls and getting list of installed packages. I don't get where you got the idea of not doing installs. I don't personally care about those other use cases mentioned here |
Sorry, I was confused - it was @cowlicks who commented
Agreed, if you're asking for full pip functionality then yes it would need to be an API exposed by pip (or you;d have to rewrite most of pip). In which case, the original comment stands - sorry, we don't expose a supported API. So:
As an alternative, projects like |
Yes, I do use it through subprocess currently. The problem is sometimes there's bogus errors on uninstallation but I already figured out a workaround so I guess I don't need this at all. Basically: |
Currently pip doesn't have a public API so a developer using pip to automatically create deployable environments must use pip as a subprocess. It would be better if pip had a simple public API for most common things. I'm proposing these
This combination would allow a flow clean+build through a Python build script.
The text was updated successfully, but these errors were encountered: