Add support for pip list format=columns (#21990)
* Use 'pip list --format=freeze' to simplify output code parse
This commit is contained in:
parent
49eb81d573
commit
73e19c2ed1
1 changed files with 3 additions and 14 deletions
|
@ -250,7 +250,7 @@ def _get_full_name(name, version=None):
|
||||||
def _get_packages(module, pip, chdir):
|
def _get_packages(module, pip, chdir):
|
||||||
'''Return results of pip command to get packages.'''
|
'''Return results of pip command to get packages.'''
|
||||||
# Try 'pip list' command first.
|
# Try 'pip list' command first.
|
||||||
command = '%s list' % pip
|
command = '%s list --format=freeze' % pip
|
||||||
lang_env = dict(LANG='C', LC_ALL='C', LC_MESSAGES='C')
|
lang_env = dict(LANG='C', LC_ALL='C', LC_MESSAGES='C')
|
||||||
rc, out, err = module.run_command(command, cwd=chdir, environ_update=lang_env)
|
rc, out, err = module.run_command(command, cwd=chdir, environ_update=lang_env)
|
||||||
|
|
||||||
|
@ -267,19 +267,8 @@ def _get_packages(module, pip, chdir):
|
||||||
def _is_present(name, version, installed_pkgs, pkg_command):
|
def _is_present(name, version, installed_pkgs, pkg_command):
|
||||||
'''Return whether or not package is installed.'''
|
'''Return whether or not package is installed.'''
|
||||||
for pkg in installed_pkgs:
|
for pkg in installed_pkgs:
|
||||||
# Package listing will be different depending on which pip
|
if '==' in pkg:
|
||||||
# command was used ('pip list' vs. 'pip freeze').
|
pkg_name, pkg_version = pkg.split('==')
|
||||||
if 'list' in pkg_command:
|
|
||||||
pkg = pkg.replace('(', '').replace(')', '')
|
|
||||||
if ',' in pkg:
|
|
||||||
pkg_name, pkg_version, _ = pkg.replace(',', '').split(' ')
|
|
||||||
else:
|
|
||||||
pkg_name, pkg_version = pkg.split(' ')
|
|
||||||
elif 'freeze' in pkg_command:
|
|
||||||
if '==' in pkg:
|
|
||||||
pkg_name, pkg_version = pkg.split('==')
|
|
||||||
else:
|
|
||||||
continue
|
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue