Skip to content

Commit

Permalink
Merge pull request #3723 from wm75/mimodd_master
Browse files Browse the repository at this point in the history
Report successfully installed versions of requirements
even if existing installations have been ignored
  • Loading branch information
xavfernandez authored Oct 27, 2016
2 parents 8df742e + e568adc commit 1aa5e6a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
23 changes: 19 additions & 4 deletions pip/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -341,16 +341,26 @@ 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,
root=options.root_path,
prefix=options.prefix_path,
isolated=options.isolated_mode,
)
reqs = sorted(
requirement_set.successfully_installed,
key=operator.attrgetter('name'))
items = []
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)
Expand Down Expand Up @@ -420,3 +430,8 @@ def run(self, options, args):
)
shutil.rmtree(temp_target_dir)
return requirement_set


def get_lib_location_guesses(*args, **kwargs):
scheme = distutils_scheme('', *args, **kwargs)
return [scheme['purelib'], scheme['platlib']]
7 changes: 5 additions & 2 deletions pip/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1aa5e6a

Please sign in to comment.