Terry J. Reedy added the comment:

Pip's rather extensive command-line API can also be used as a code API. The 
signature of pip.main is (args=None), where args = sys.argv[1:] if not passed. 
I presume this will not change. Reusing the command-list API had the advantage 
of reusing the existing docs, help output, and knowlege of how to use pip.

The API is to run 'status = pip.main(args)', where args is a list containing 
quoted versions of the command-line args, the same as one would pass to 
subprocess.Popen.  Output is strings written to stdout (and stderr), which can 
be captured with StringIO. While not as nice as getting, say, a list of strings 
from a list_command function, I consider this better than repeatedly calling 
Popen and getting encoded bytes (in whatever encoding) from pipes.

I tested this with list, show pip, help install, and install --upgrade pip.  
After a shell restart,  import pip imported the new version. I am working on a 
wrapper for the pip.main call.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue23551>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to