Created
August 21, 2014 19:48
-
-
Save pfmoore/eb1e9c23364af58d110a to your computer and use it in GitHub Desktop.
pip list command patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/pip/commands/list.py b/pip/commands/list.py | |
index 3a0330a..3e4fcc7 100644 | |
--- a/pip/commands/list.py | |
+++ b/pip/commands/list.py | |
@@ -45,6 +45,12 @@ class ListCommand(Command): | |
help=('If in a virtualenv that has global access, do not list ' | |
'globally-installed packages.'), | |
) | |
+ cmd_opts.add_option( | |
+ '-L', '--location', | |
+ action='store_true', | |
+ default=False, | |
+ help=('Display package locations.'), | |
+ ) | |
cmd_opts.add_option( | |
'--pre', | |
@@ -81,7 +87,7 @@ class ListCommand(Command): | |
elif options.editable: | |
self.run_editables(options) | |
else: | |
- self.run_listing(options) | |
+ self.run_listing(options, args) | |
def run_outdated(self, options): | |
for dist, remote_version_raw, remote_version_parsed in \ | |
@@ -145,26 +151,30 @@ class ListCommand(Command): | |
remote_version_parsed = remote_version[0] | |
yield dist, remote_version_raw, remote_version_parsed | |
- def run_listing(self, options): | |
+ def run_listing(self, options, args): | |
installed_packages = get_installed_distributions( | |
local_only=options.local, | |
) | |
- self.output_package_listing(installed_packages) | |
+ if args: | |
+ installed_packages = [p for p in installed_packages if p.project_name in args] | |
+ self.output_package_listing(installed_packages, options) | |
def run_editables(self, options): | |
installed_packages = get_installed_distributions( | |
local_only=options.local, | |
editables_only=True, | |
) | |
- self.output_package_listing(installed_packages) | |
+ self.output_package_listing(installed_packages, options) | |
- def output_package_listing(self, installed_packages): | |
+ def output_package_listing(self, installed_packages, options): | |
installed_packages = sorted( | |
installed_packages, | |
key=lambda dist: dist.project_name.lower(), | |
) | |
for dist in installed_packages: | |
- if dist_is_editable(dist): | |
+ if options.location: | |
+ line = dist.location | |
+ elif dist_is_editable(dist): | |
line = '%s (%s, %s)' % ( | |
dist.project_name, | |
dist.version, | |
@@ -180,4 +190,4 @@ class ListCommand(Command): | |
self.find_packages_latests_versions(options): | |
if dist.parsed_version == remote_version_parsed: | |
uptodate.append(dist) | |
- self.output_package_listing(uptodate) | |
+ self.output_package_listing(uptodate, options) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment