-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
How to create plugin for PIP #3999
Comments
There's no official API for that. We've had some discussions on the possibility (search the issues for details) but there's nothing at the moment. |
@pfmoore and what prevents to make public API? I can see lot of commands can be called from the module pip it very nice for automation tools. Or problem more deep and stoped by require improve the internal quality of the product? |
I'd say this is duplicate of #3121 |
@xavfernandez no sure that you right. There I talk about plugin but public API is depends problem. |
@vit1251 It's simply that there is no API for pip at the moment. Not for being called from other programs, nor for plugins. We're not against either of these in principle, but there are a number of significant issues that would need to be thrashed out first (check out the various related issues for details). And in all honesty, it's not a high priority for the limited available time the devs have. I hope that answers your question, even if it's not the answer you'd hoped for. |
@pfmoore @ncoghlan I would like to dedicate my time for developing pip API. However, I would need some guidance on what should be structure of API. I worked on tkinter front-end for
|
Some very quick thoughts (sorry, not much time at the moment). Your item 1 is not a pip issue, it's how the Python import system works. Installing new packages into the site-packages of a running interpreter is not safe - I'd be inclined to say that Python doesn't support it, but I don't think there's any explicit statement on this, so that's just my view. This is fundamentally the biggest issue with a "pip API" - any such API is designed to allow users to install packages into a running interpreter, and when things go wrong as a result, they will be reported as pip issues, when in fact they are simply cases of "you shouldn't do that". I don't have a good suggestion about how to resolve that, in the absence of support from the Python import system for changing site-packages on the fly. Your item (2) is interesting, in that direct access to read pip's logs as they are produced would help here. But equally, realtime access to subprocess output streams is a standard issue, and a general "run a subprocess and capture its output as it is produced" routine for tkinter would address this without needing any change to pip. And should be perfectly possible - I'm sure I've seen other applications that manage it. (Although stdio buffering might hinder this in the general case - Making pip thread-safe is likely to be a major undertaking. My immediate thought would be that any pip API should not promise thread safety in the first instance. Maybe if we had a stable API, carefully adding thread safety guarantees would be possible, but we're a long, long way from that state at the moment. For (4), I don't see any reason we couldn't add some sort of machine-readable output option (much like we have |
FTR I agree with @pfmoore with the one correction that caching of installed packages (in the PyPI sense) as far as pip is concerned is not exactly a Python problem but a |
I'm going to close this, we're unlikely to add a plugin API to pip. |
You can not go around the directory and look for the .py files and attach them to the pip entry point? This is an elementary task! Look this implementation:
Plugins directory registry may be inside user home directory ~/.pip_plugins. |
PIP API is key element of most automatic deploying system. Every application before start should check environment. Every installation script and scenarios should uninstall and install package via API. Now most of this tools invoke os.system pip but it very stupid style for upgrading and update environment. Also PIP may provide pypi search and other similar utilites. |
@vit1251 The library APIs you are looking for are
As the internal capabilities of As far as closing the issue goes, I agree - any build-time extensions will be based on |
Disclaimer: This is not a pip python API (because of which this issue was closed). It's simply invokes scripts from within pip. Following the discussion from #6081, I've successfully created a plugin system for pip that seems to work fine with existing packages. Here is the branch I'm working on (see - plugin.py) Why?Well it's really because plugins are quite convinient. It allows users to extend cargo has had a very successful story with subcommands, and I would love to see this with pip. Even npm has scripts, which are considered almost essential to devel workflow in JS land. This really has the potential to improve python devel workflow. pip plugins won't require any intervention from pip developers once the functionality is merged into master. Plus the cross-virtualenv capabilities that this plugin system brings, means that us developers don't have to keep reinstalling common pip utilites on our virtualenvs! And frankly, I don't feel like this brings substantial baggage to the pip codebase, to not consider having it. I also presume that a lot of issues like #4551 can be just resolved using plugins, instead of modifying pip codebase, which I understand, could be a challenging task. How it works?
This architecture allows for plugins that are independent of the actual package, which I think is quite nice. It also solves the major recurring problem related to cross-virtualenv execution. Any plugins written with this architecture can be made so that they only need to be installed once on the global python, and then used from within a virtualenv. I have also added a How to actually write plugins?plugingen is a small utility for generating a plugin. It allows exposing an existing python CLI as a pip plugin. Also, Here is a proof of concept that contains some popular packages wrapped as plugins. It's obviously not ready to be merged. I need to run the tests (and write new ones). I would be happy to continue this work if you guys think it's a viable thing to do. |
Also, now that I think about it, this could also potentially solve @upendra-k14's use cases, since the plugin system allows overriding built-in commands. Like He could just add a simple pre-install hook, and then reissue pip install with I should probably look into how this would result in security issues. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Description:
How to create plugin to extends PIP with additional command for example I want to make more extendable requirement.txt format. How to do that?
What I've run:
I just only ask ;-)
The text was updated successfully, but these errors were encountered: