From 3e7fa5c9faf966db63465eecfc2da7f307597c25 Mon Sep 17 00:00:00 2001 From: Wolfgang Maier Date: Mon, 11 Apr 2016 17:12:36 +0200 Subject: [PATCH 1/3] report successfully installed versions of requirements even if existing installations have been ignored --- pip/commands/install.py | 23 +++++++++++++++++++---- pip/utils/__init__.py | 7 +++++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/pip/commands/install.py b/pip/commands/install.py index 7ddde93c255..676716341ea 100644 --- a/pip/commands/install.py +++ b/pip/commands/install.py @@ -18,7 +18,7 @@ InstallationError, CommandError, PreviousBuildDirError, ) from pip import cmdoptions -from pip.utils import ensure_dir +from pip.utils import ensure_dir, get_installed_version from pip.utils.build import BuildDirectory from pip.utils.deprecation import RemovedInPip10Warning from pip.utils.filesystem import check_path_owner @@ -316,6 +316,12 @@ def run(self, options, args): root=options.root_path, prefix=options.prefix_path, ) + + possible_lib_locations = get_lib_location_guesses( + user=options.use_user_site, + home=temp_target_dir, + prefix=options.prefix_path + ) reqs = sorted( requirement_set.successfully_installed, key=operator.attrgetter('name')) @@ -323,9 +329,11 @@ def run(self, options, args): for req in reqs: item = req.name try: - if hasattr(req, 'installed_version'): - if req.installed_version: - item += '-' + req.installed_version + installed_version = get_installed_version( + req.name, possible_lib_locations + ) + if installed_version: + item += '-' + installed_version except Exception: pass items.append(item) @@ -384,3 +392,10 @@ def run(self, options, args): ) shutil.rmtree(temp_target_dir) return requirement_set + + +def get_lib_location_guesses(user=False, home=None, root=None, prefix=None): + scheme = distutils_scheme( + '', user=user, home=home, root=root, prefix=prefix + ) + return [scheme['purelib'], scheme['platlib']] diff --git a/pip/utils/__init__.py b/pip/utils/__init__.py index b5d01cde61f..feecf3e5132 100644 --- a/pip/utils/__init__.py +++ b/pip/utils/__init__.py @@ -838,14 +838,17 @@ def __get__(self, obj, cls): return value -def get_installed_version(dist_name): +def get_installed_version(dist_name, lookup_dirs=None): """Get the installed version of dist_name avoiding pkg_resources cache""" # Create a requirement that we'll look for inside of setuptools. req = pkg_resources.Requirement.parse(dist_name) # We want to avoid having this cached, so we need to construct a new # working set each time. - working_set = pkg_resources.WorkingSet() + if lookup_dirs is None: + working_set = pkg_resources.WorkingSet() + else: + working_set = pkg_resources.WorkingSet(lookup_dirs) # Get the installed distribution from our working set dist = working_set.find(req) From 69dd4aefdfae644b7ba1bfe0d45a80165ccc702c Mon Sep 17 00:00:00 2001 From: Wolfgang Maier Date: Tue, 12 Apr 2016 10:29:32 +0200 Subject: [PATCH 2/3] respect isolated mode when looking for installed versions --- pip/commands/install.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pip/commands/install.py b/pip/commands/install.py index 676716341ea..b9bf5ba56ee 100644 --- a/pip/commands/install.py +++ b/pip/commands/install.py @@ -320,7 +320,8 @@ def run(self, options, args): possible_lib_locations = get_lib_location_guesses( user=options.use_user_site, home=temp_target_dir, - prefix=options.prefix_path + prefix=options.prefix_path, + isolated=options.isolated_mode, ) reqs = sorted( requirement_set.successfully_installed, @@ -394,8 +395,6 @@ def run(self, options, args): return requirement_set -def get_lib_location_guesses(user=False, home=None, root=None, prefix=None): - scheme = distutils_scheme( - '', user=user, home=home, root=root, prefix=prefix - ) +def get_lib_location_guesses(*args, **kwargs): + scheme = distutils_scheme('', *args, **kwargs) return [scheme['purelib'], scheme['platlib']] From e568adc41ca71a46d9240e88dc97ca8a9fed169a Mon Sep 17 00:00:00 2001 From: Wolfgang Maier Date: Mon, 30 May 2016 11:33:25 +0200 Subject: [PATCH 3/3] consider root path when looking for installed versions --- pip/commands/install.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pip/commands/install.py b/pip/commands/install.py index b9bf5ba56ee..b63361090c5 100644 --- a/pip/commands/install.py +++ b/pip/commands/install.py @@ -320,6 +320,7 @@ def run(self, options, args): possible_lib_locations = get_lib_location_guesses( user=options.use_user_site, home=temp_target_dir, + root=options.root_path, prefix=options.prefix_path, isolated=options.isolated_mode, )