Skip to content
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

Add a new *public* main() method #5149

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions news/5149.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Add public, supported replacement for `pip.main` which uses
`subprocess.check_call` to invoke
${sys.executable} -m pip ...
with the given arguments. e.g. `pip.main('install', '-U', 'setuptools')` is now
supported usage.

This means that the behavior may be different from `pip.main` on `pip<10.0.0`.
26 changes: 26 additions & 0 deletions src/pip/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
from __future__ import absolute_import
import subprocess
import sys

__version__ = "10.0.0.dev0"


def main(*args):
"""
This function is included primarily for backwards compatibility.

Although anything using `pip.main()` in pip<9.0.2 was engaged in a
non-supported mode of use, as a pragmatic accommodation, `pip.main()` is
being *added* as a *new* piece of functionality with very similar behaviors
and call signature.

Why use check_call instead of check_output?
It's behavior is slightly closer to the older `pip.main()` behavior,
printing output information directly to stdout.

check_call was added in py2.5 and is supported through py3.x , so it's more
compatible than some alternatives like subprocess.run (added in py3.5)
"""
return subprocess.check_call([sys.executable, '-m', 'pip'] + list(args))


__all__ = ('main',)