mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
#47698 improve run-speed of pip package state checks by only loading the current package list once when checking multiple packages
This commit is contained in:
parent
00a13761c7
commit
4fec8f6bcc
1 changed files with 15 additions and 5 deletions
|
@ -186,16 +186,19 @@ 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, env_vars,
|
||||
**kwargs):
|
||||
pip_list=False,**kwargs):
|
||||
# result: None means the command failed to run
|
||||
# result: True means the package is installed
|
||||
# result: False means the package is not installed
|
||||
ret = {'result': False, 'comment': None}
|
||||
|
||||
# If we are not passed a pip list, get one:
|
||||
if not pip_list:
|
||||
pip_list = __salt__['pip.list'](prefix, bin_env=bin_env,
|
||||
user=user, cwd=cwd,
|
||||
env_vars=env_vars, **kwargs)
|
||||
|
||||
# Check if the requested package is already installed.
|
||||
pip_list = __salt__['pip.list'](prefix, bin_env=bin_env,
|
||||
user=user, cwd=cwd,
|
||||
env_vars=env_vars, **kwargs)
|
||||
prefix_realname = _find_key(prefix, pip_list)
|
||||
|
||||
# If the package was already installed, check
|
||||
|
@ -716,6 +719,13 @@ def installed(name,
|
|||
# No requirements case.
|
||||
# Check pre-existence of the requested packages.
|
||||
else:
|
||||
# Attempt to pre-cache a the current pip list
|
||||
try:
|
||||
pip_list = __salt__['pip.list'](bin_env=bin_env, user=user, cwd=cwd)
|
||||
# If we fail, then just send False, and we'll try again in the next function call
|
||||
except:
|
||||
pip_list = False
|
||||
|
||||
for prefix, state_pkg_name, version_spec in pkgs_details:
|
||||
|
||||
if prefix:
|
||||
|
@ -724,7 +734,7 @@ def installed(name,
|
|||
out = _check_if_installed(prefix, state_pkg_name, version_spec,
|
||||
ignore_installed, force_reinstall,
|
||||
upgrade, user, cwd, bin_env, env_vars,
|
||||
**kwargs)
|
||||
pip_list,**kwargs)
|
||||
# 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:
|
||||
|
|
Loading…
Add table
Reference in a new issue