Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
setuptools
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
setuptools
Commits
3d8a7a97
Commit
3d8a7a97
authored
May 04, 2014
by
Jason R. Coombs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sort _distmap entries on insert. Obviates need for a cache.
parent
cf1cb5ba
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
49 deletions
+3
-49
pkg_resources.py
pkg_resources.py
+3
-49
No files found.
pkg_resources.py
View file @
3d8a7a97
...
...
@@ -29,6 +29,7 @@ import token
import
symbol
import
operator
import
platform
import
bisect
from
pkgutil
import
get_importer
try
:
...
...
@@ -776,7 +777,6 @@ class Environment(object):
running platform or Python version.
"""
self._distmap = {}
self._cache = {}
self.platform = platform
self.python = python
self.scan(search_path)
...
...
@@ -819,46 +819,8 @@ class Environment(object):
lowercase as their key.
"""
# Result caching here serves two purposes:
# 1. Speed up the project_name --> distribution list lookup.
# 2. 'First access' flag indicating the distribution list requires
# sorting before it can be returned to the user.
#TODO: This caching smells like premature optimization. It could be
# that the distribution list lookup speed is not really affected by
# this, in which case the whole cache could be removed and replaced
# with a single 'dist_list_sorted' flag. This seems strongly indicated
# by the fact that this function does not really cache the distribution
# list under the given project name but only under its canonical
# distribution key variant. That means that repeated access using a non
# canonical project name does not get any speedup at all.
try:
return self._cache[project_name]
except KeyError:
pass
# We expect all distribution keys to contain lower-case characters
# only.
#TODO: See if this expectation can be implemented better, e.g. by using
# some sort of a name --> key conversion function on the Distribution
# class or something similar.
#TODO: This requires all classes derived from Distribution to use
# lower-case only keys even if they do not calculate them from the
# project's name. It might be better to make this function simpler by
# passing it the the exact distribution key as a parameter and have the
# caller convert a `project_name` to its corresponding distribution key
# as needed.
distribution_key = project_name.lower()
try:
dists = self._distmap[distribution_key]
except KeyError:
return []
# Sort the project's distribution list lazily on first access.
if distribution_key not in self._cache:
self._cache[distribution_key] = dists
_sort_dists(dists)
return dists
return self._distmap.get(distribution_key, [])
def add(self, dist):
"""Add `dist` if we ``can_add()`` it and it has not already been added
...
...
@@ -866,15 +828,7 @@ class Environment(object):
if self.can_add(dist) and dist.has_version():
dists = self._distmap.setdefault(dist.key, [])
if dist not in dists:
dists.append(dist)
cached_dists = self._cache.get(dist.key)
if cached_dists:
# The distribution list has been cached on first access,
# therefore we know it has already been sorted lazily and
# we are expected to keep it in sorted order.
_sort_dists(dists)
assert cached_dists is dists,
\
"
Distribution
list
cache
corrupt
.
"
bisect.insort(dists, dist)
def best_match(self, req, working_set, installer=None):
"""Find distribution best matching `req` and usable on `working_set`
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment