From 60d7295ae4878ea8fb917bdfa2e971a6e7436eee Mon Sep 17 00:00:00 2001 From: Luo Jiebin Date: Tue, 4 Apr 2017 15:48:07 +0800 Subject: [PATCH 1/5] Showed installers when list command runs with -vv option --- pip/commands/list.py | 18 +++++++++++++++++- tests/functional/test_list.py | 10 +++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/pip/commands/list.py b/pip/commands/list.py index 0fe0b5bc1cd..070d624c3fb 100644 --- a/pip/commands/list.py +++ b/pip/commands/list.py @@ -210,7 +210,14 @@ def iter_packages_latest_infos(self, packages, options): yield dist def output_legacy(self, dist, options): - if options.verbose >= 1 or dist_is_editable(dist): + if options.verbose >= 2: + return '%s (%s, %s, %s)' % ( + dist.project_name, + dist.version, + dist.location, + dist.installer, + ) + elif options.verbose >= 1 or dist_is_editable(dist): return '%s (%s, %s)' % ( dist.project_name, dist.version, @@ -236,6 +243,9 @@ def output_package_listing(self, packages, options): self.output_package_listing_columns(data, header) elif options.list_format == 'freeze': for dist in packages: + if options.verbose >= 2: + logger.info("%s==%s (%s) (%s)", dist.project_name, + dist.version, dist.location, dist.installer) if options.verbose >= 1: logger.info("%s==%s (%s)", dist.project_name, dist.version, dist.location) @@ -298,6 +308,8 @@ def format_for_columns(pkgs, options): data = [] if options.verbose >= 1 or any(dist_is_editable(x) for x in pkgs): header.append("Location") + if options.verbose >= 2: + header.append("Installer") for proj in pkgs: # if we're working on the 'outdated' list, separate out the @@ -310,6 +322,8 @@ def format_for_columns(pkgs, options): if options.verbose >= 1 or dist_is_editable(proj): row.append(proj.location) + if options.verbose >= 2: + row.append(proj.installer) data.append(row) @@ -323,6 +337,8 @@ def format_for_json(packages, options): 'name': dist.project_name, 'version': six.text_type(dist.version), } + if options.verbose >= 2: + info['installer'] = dist.installer if options.verbose >= 1: info['location'] = dist.location if options.outdated: diff --git a/tests/functional/test_list.py b/tests/functional/test_list.py index 25b891d5c4c..834dd1275c6 100644 --- a/tests/functional/test_list.py +++ b/tests/functional/test_list.py @@ -25,13 +25,21 @@ def test_verbose_flag(script, data): 'install', '-f', data.find_links, '--no-index', 'simple==1.0', 'simple2==3.0', ) - result = script.pip('list', '-v') + result = script.pip('list', '-v', '--format=columns') assert 'Package' in result.stdout, str(result) assert 'Version' in result.stdout, str(result) assert 'Location' in result.stdout, str(result) assert 'simple 1.0' in result.stdout, str(result) assert 'simple2 3.0' in result.stdout, str(result) + result = script.pip('list', '-vv', '--format=columns') + assert 'Package' in result.stdout, str(result) + assert 'Version' in result.stdout, str(result) + assert 'Location' in result.stdout, str(result) + assert 'Installer' in result.stdout, str(result) + assert 'simple 1.0' in result.stdout, str(result) + assert 'simple2 3.0' in result.stdout, str(result) + def test_columns_flag(script, data): """ From 2384ce1b98536f66bd847553d099f80279b6f4be Mon Sep 17 00:00:00 2001 From: Luo Jiebin Date: Tue, 4 Apr 2017 15:48:57 +0800 Subject: [PATCH 2/5] Added news entry --- news/949.feature | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 news/949.feature diff --git a/news/949.feature b/news/949.feature new file mode 100644 index 00000000000..5530ff9f9cf --- /dev/null +++ b/news/949.feature @@ -0,0 +1,3 @@ +Added a way to distinguish between pip installed packages and those from +the system package manager in 'pip list'. Specifically, 'pip list -vv' also +shows the installer of package. From d7e213201bd5d2ff6107ff055c5223ad3070a32f Mon Sep 17 00:00:00 2001 From: Luo Jiebin Date: Wed, 5 Apr 2017 19:06:33 +0800 Subject: [PATCH 3/5] Updated code to show both location and installer of a package when '-v' is used --- news/949.feature | 4 ++-- pip/commands/list.py | 31 ++++++++++++++++++------------- tests/functional/test_list.py | 7 ------- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/news/949.feature b/news/949.feature index 5530ff9f9cf..e33819b881e 100644 --- a/news/949.feature +++ b/news/949.feature @@ -1,3 +1,3 @@ Added a way to distinguish between pip installed packages and those from -the system package manager in 'pip list'. Specifically, 'pip list -vv' also -shows the installer of package. +the system package manager in 'pip list'. Specifically, 'pip list -v' also +shows the installer of package if it has that meta data. diff --git a/pip/commands/list.py b/pip/commands/list.py index 070d624c3fb..a3a65816db0 100644 --- a/pip/commands/list.py +++ b/pip/commands/list.py @@ -210,14 +210,14 @@ def iter_packages_latest_infos(self, packages, options): yield dist def output_legacy(self, dist, options): - if options.verbose >= 2: + if options.verbose >= 1: return '%s (%s, %s, %s)' % ( dist.project_name, dist.version, dist.location, - dist.installer, + get_installer(dist), ) - elif options.verbose >= 1 or dist_is_editable(dist): + elif dist_is_editable(dist): return '%s (%s, %s)' % ( dist.project_name, dist.version, @@ -243,12 +243,10 @@ def output_package_listing(self, packages, options): self.output_package_listing_columns(data, header) elif options.list_format == 'freeze': for dist in packages: - if options.verbose >= 2: - logger.info("%s==%s (%s) (%s)", dist.project_name, - dist.version, dist.location, dist.installer) if options.verbose >= 1: - logger.info("%s==%s (%s)", dist.project_name, - dist.version, dist.location) + logger.info("%s==%s (%s) (%s)", dist.project_name, + dist.version, dist.location, + get_installer(dist)) else: logger.info("%s==%s", dist.project_name, dist.version) elif options.list_format == 'json': @@ -308,7 +306,7 @@ def format_for_columns(pkgs, options): data = [] if options.verbose >= 1 or any(dist_is_editable(x) for x in pkgs): header.append("Location") - if options.verbose >= 2: + if options.verbose >= 1: header.append("Installer") for proj in pkgs: @@ -322,8 +320,8 @@ def format_for_columns(pkgs, options): if options.verbose >= 1 or dist_is_editable(proj): row.append(proj.location) - if options.verbose >= 2: - row.append(proj.installer) + if options.verbose >= 1: + row.append(get_installer(proj)) data.append(row) @@ -337,12 +335,19 @@ def format_for_json(packages, options): 'name': dist.project_name, 'version': six.text_type(dist.version), } - if options.verbose >= 2: - info['installer'] = dist.installer if options.verbose >= 1: info['location'] = dist.location + info['installer'] = get_installer(dist) if options.outdated: info['latest_version'] = six.text_type(dist.latest_version) info['latest_filetype'] = dist.latest_filetype data.append(info) return json.dumps(data) + + +def get_installer(dist): + if dist.has_metadata('INSTALLER'): + for line in dist.get_metadata_lines('INSTALLER'): + if line.strip(): + return line.strip() + return '' diff --git a/tests/functional/test_list.py b/tests/functional/test_list.py index 834dd1275c6..e3ddc69936f 100644 --- a/tests/functional/test_list.py +++ b/tests/functional/test_list.py @@ -29,13 +29,6 @@ def test_verbose_flag(script, data): assert 'Package' in result.stdout, str(result) assert 'Version' in result.stdout, str(result) assert 'Location' in result.stdout, str(result) - assert 'simple 1.0' in result.stdout, str(result) - assert 'simple2 3.0' in result.stdout, str(result) - - result = script.pip('list', '-vv', '--format=columns') - assert 'Package' in result.stdout, str(result) - assert 'Version' in result.stdout, str(result) - assert 'Location' in result.stdout, str(result) assert 'Installer' in result.stdout, str(result) assert 'simple 1.0' in result.stdout, str(result) assert 'simple2 3.0' in result.stdout, str(result) From 976ed00e073da5de50a79c311f609c38f44308f5 Mon Sep 17 00:00:00 2001 From: Luo Jiebin Date: Thu, 6 Apr 2017 17:51:26 +0800 Subject: [PATCH 4/5] Removed installer from freeze format --- pip/commands/list.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pip/commands/list.py b/pip/commands/list.py index a3a65816db0..62e20e4fafb 100644 --- a/pip/commands/list.py +++ b/pip/commands/list.py @@ -244,9 +244,8 @@ def output_package_listing(self, packages, options): elif options.list_format == 'freeze': for dist in packages: if options.verbose >= 1: - logger.info("%s==%s (%s) (%s)", dist.project_name, - dist.version, dist.location, - get_installer(dist)) + logger.info("%s==%s (%s)", dist.project_name, + dist.version, dist.location) else: logger.info("%s==%s", dist.project_name, dist.version) elif options.list_format == 'json': From 9a467947dce716a33b478ab8c97e266a8bf89ba4 Mon Sep 17 00:00:00 2001 From: Luo Jiebin Date: Thu, 6 Apr 2017 17:53:03 +0800 Subject: [PATCH 5/5] Moved get_installer function to pip.utils.packaging --- pip/commands/list.py | 9 +-------- pip/utils/packaging.py | 8 ++++++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/pip/commands/list.py b/pip/commands/list.py index 62e20e4fafb..2758626e04f 100644 --- a/pip/commands/list.py +++ b/pip/commands/list.py @@ -16,6 +16,7 @@ from pip.utils import ( get_installed_distributions, dist_is_editable) from pip.utils.deprecation import RemovedInPip11Warning +from pip.utils.packaging import get_installer from pip.cmdoptions import make_option_group, index_group logger = logging.getLogger(__name__) @@ -342,11 +343,3 @@ def format_for_json(packages, options): info['latest_filetype'] = dist.latest_filetype data.append(info) return json.dumps(data) - - -def get_installer(dist): - if dist.has_metadata('INSTALLER'): - for line in dist.get_metadata_lines('INSTALLER'): - if line.strip(): - return line.strip() - return '' diff --git a/pip/utils/packaging.py b/pip/utils/packaging.py index e93b20d158d..5464dd13336 100644 --- a/pip/utils/packaging.py +++ b/pip/utils/packaging.py @@ -61,3 +61,11 @@ def check_dist_requires_python(dist): "Package %s has an invalid Requires-Python entry %s - %s" % ( dist.project_name, requires_python, e)) return + + +def get_installer(dist): + if dist.has_metadata('INSTALLER'): + for line in dist.get_metadata_lines('INSTALLER'): + if line.strip(): + return line.strip() + return ''