pip.list_all_versions now can read index_url

This commit is contained in:
xy@zhihu.com 2018-02-09 17:46:32 +08:00
parent 78fed2df0b
commit be8427fdc9
3 changed files with 19 additions and 5 deletions

View file

@ -198363,7 +198363,7 @@ installed pip is new enough.
.UNINDENT
.INDENT 0.0
.TP
.B salt.modules.pip.list_all_versions(pkg, bin_env=None, include_alpha=False, include_beta=False, include_rc=False, user=None, cwd=None)
.B salt.modules.pip.list_all_versions(pkg, bin_env=None, include_alpha=False, include_beta=False, include_rc=False, user=None, cwd=None, index_url=None)
New in version 2017.7.3.
.sp
@ -198392,6 +198392,9 @@ The user under which to run pip
.TP
.B cwd
Current working directory to run pip from
.TP
.B index_url
Base URL of Python Package Index
.UNINDENT
.sp
CLI Example:

View file

@ -1305,7 +1305,8 @@ def list_all_versions(pkg,
include_beta=False,
include_rc=False,
user=None,
cwd=None):
cwd=None,
index_url=None):
'''
.. versionadded:: 2017.7.3
@ -1334,6 +1335,9 @@ def list_all_versions(pkg,
cwd
Current working directory to run pip from
index_url
Base URL of Python Package Index
CLI Example:
.. code-block:: bash
@ -1344,6 +1348,13 @@ def list_all_versions(pkg,
cmd = [pip_bin, 'install', '{0}==versions'.format(pkg)]
if index_url:
if not salt.utils.url.validate(index_url, VALID_PROTOS):
raise CommandExecutionError(
'\'{0}\' is not a valid URL'.format(index_url)
)
cmd.extend(['--index-url', index_url])
cmd_kwargs = dict(cwd=cwd, runas=user, output_loglevel='quiet', redirect_stderr=True)
if bin_env and os.path.isdir(bin_env):
cmd_kwargs['env'] = {'VIRTUAL_ENV': bin_env}

View file

@ -180,7 +180,7 @@ def _check_pkg_version_format(pkg):
def _check_if_installed(prefix, state_pkg_name, version_spec,
ignore_installed, force_reinstall,
upgrade, user, cwd, bin_env):
upgrade, user, cwd, bin_env, index_url):
# result: None means the command failed to run
# result: True means the package is installed
@ -227,7 +227,7 @@ def _check_if_installed(prefix, state_pkg_name, version_spec,
available_versions = __salt__['pip.list_all_versions'](
prefix_realname, bin_env=bin_env, include_alpha=include_alpha,
include_beta=include_beta, include_rc=include_rc, user=user,
cwd=cwd)
cwd=cwd, index_url=index_url)
desired_version = ''
if any(version_spec):
for version in reversed(available_versions):
@ -682,7 +682,7 @@ def installed(name,
version_spec = version_spec
out = _check_if_installed(prefix, state_pkg_name, version_spec,
ignore_installed, force_reinstall,
upgrade, user, cwd, bin_env)
upgrade, user, cwd, bin_env, index_url)
# If _check_if_installed result is None, something went wrong with
# the command running. This way we keep stateful output.
if out['result'] is None: