diff --git a/AUTHORS.txt b/AUTHORS.txt index 7859b7c31..a0c3d18bf 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -172,6 +172,7 @@ Lincoln de Sousa Lipis Ludovic Gasc Luke Macken +Luo Jiebin Marc Abramowitz Marc Tamlyn Marcus Smith diff --git a/news/979.feature b/news/979.feature new file mode 100644 index 000000000..825340daf --- /dev/null +++ b/news/979.feature @@ -0,0 +1 @@ +Show install locations when list command ran with "-v" option. diff --git a/pip/commands/list.py b/pip/commands/list.py index 9d31bb65b..0fe0b5bc1 100644 --- a/pip/commands/list.py +++ b/pip/commands/list.py @@ -209,8 +209,8 @@ class ListCommand(Command): dist.latest_filetype = typ yield dist - def output_legacy(self, dist): - if dist_is_editable(dist): + def output_legacy(self, dist, options): + if options.verbose >= 1 or dist_is_editable(dist): return '%s (%s, %s)' % ( dist.project_name, dist.version, @@ -219,9 +219,9 @@ class ListCommand(Command): else: return '%s (%s)' % (dist.project_name, dist.version) - def output_legacy_latest(self, dist): + def output_legacy_latest(self, dist, options): return '%s - Latest: %s [%s]' % ( - self.output_legacy(dist), + self.output_legacy(dist, options), dist.latest_version, dist.latest_filetype, ) @@ -236,15 +236,19 @@ class ListCommand(Command): self.output_package_listing_columns(data, header) elif options.list_format == 'freeze': for dist in packages: - logger.info("%s==%s", dist.project_name, dist.version) + if options.verbose >= 1: + 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': logger.info(format_for_json(packages, options)) elif options.list_format == "legacy": for dist in packages: if options.outdated: - logger.info(self.output_legacy_latest(dist)) + logger.info(self.output_legacy_latest(dist, options)) else: - logger.info(self.output_legacy(dist)) + logger.info(self.output_legacy(dist, options)) def output_package_listing_columns(self, data, header): # insert the header first: we need to know the size of column names @@ -292,7 +296,7 @@ def format_for_columns(pkgs, options): header = ["Package", "Version"] data = [] - if any(dist_is_editable(x) for x in pkgs): + if options.verbose >= 1 or any(dist_is_editable(x) for x in pkgs): header.append("Location") for proj in pkgs: @@ -304,7 +308,7 @@ def format_for_columns(pkgs, options): row.append(proj.latest_version) row.append(proj.latest_filetype) - if dist_is_editable(proj): + if options.verbose >= 1 or dist_is_editable(proj): row.append(proj.location) data.append(row) @@ -319,6 +323,8 @@ def format_for_json(packages, options): 'name': dist.project_name, 'version': six.text_type(dist.version), } + if options.verbose >= 1: + info['location'] = dist.location if options.outdated: info['latest_version'] = six.text_type(dist.latest_version) info['latest_filetype'] = dist.latest_filetype diff --git a/tests/functional/test_list.py b/tests/functional/test_list.py index 7b4169683..25b891d5c 100644 --- a/tests/functional/test_list.py +++ b/tests/functional/test_list.py @@ -17,6 +17,22 @@ def test_list_command(script, data): assert 'simple2 3.0' in result.stdout, str(result) +def test_verbose_flag(script, data): + """ + Test the list command with the '-v' option + """ + script.pip( + 'install', '-f', data.find_links, '--no-index', 'simple==1.0', + 'simple2==3.0', + ) + result = script.pip('list', '-v') + 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) + + def test_columns_flag(script, data): """ Test the list command with the '--format=columns' option