Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speedup printing of installed package versions #5127

Merged
merged 1 commit into from
Jun 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/5127.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Speed up printing of newly installed package versions
8 changes: 6 additions & 2 deletions src/pip/_internal/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import shutil
from optparse import SUPPRESS_HELP

from pip._vendor import pkg_resources

from pip._internal import cmdoptions
from pip._internal.basecommand import RequirementCommand
from pip._internal.cache import WheelCache
Expand Down Expand Up @@ -343,20 +345,22 @@ def run(self, options, args):
use_user_site=options.use_user_site,
)

possible_lib_locations = get_lib_location_guesses(
lib_locations = get_lib_location_guesses(
user=options.use_user_site,
home=target_temp_dir.path,
root=options.root_path,
prefix=options.prefix_path,
isolated=options.isolated_mode,
)
working_set = pkg_resources.WorkingSet(lib_locations)

reqs = sorted(installed, key=operator.attrgetter('name'))
items = []
for req in reqs:
item = req.name
try:
installed_version = get_installed_version(
req.name, possible_lib_locations
req.name, working_set=working_set
)
if installed_version:
item += '-' + installed_version
Expand Down
10 changes: 4 additions & 6 deletions src/pip/_internal/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,17 +821,15 @@ def __get__(self, obj, cls):
return value


def get_installed_version(dist_name, lookup_dirs=None):
def get_installed_version(dist_name, working_set=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.
if lookup_dirs is None:
if working_set is None:
# We want to avoid having this cached, so we need to construct a new
# working set each time.
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