|
83 | 83 | __import__('pkg_resources.extern.packaging.specifiers')
|
84 | 84 | __import__('pkg_resources.extern.packaging.requirements')
|
85 | 85 | __import__('pkg_resources.extern.packaging.markers')
|
| 86 | +__import__('pkg_resources.extern.packaging.utils') |
86 | 87 |
|
87 | 88 | if sys.version_info < (3, 5):
|
88 | 89 | raise RuntimeError("Python 3.5 or later is required")
|
@@ -554,6 +555,7 @@ def __init__(self, entries=None):
|
554 | 555 | self.entries = []
|
555 | 556 | self.entry_keys = {}
|
556 | 557 | self.by_key = {}
|
| 558 | + self.normalized_to_canonical_keys = {} |
557 | 559 | self.callbacks = []
|
558 | 560 |
|
559 | 561 | if entries is None:
|
@@ -634,6 +636,14 @@ def find(self, req):
|
634 | 636 | is returned.
|
635 | 637 | """
|
636 | 638 | dist = self.by_key.get(req.key)
|
| 639 | + |
| 640 | + if dist is None: |
| 641 | + canonical_key = self.normalized_to_canonical_keys.get(req.key) |
| 642 | + |
| 643 | + if canonical_key is not None: |
| 644 | + req.key = canonical_key |
| 645 | + dist = self.by_key.get(canonical_key) |
| 646 | + |
637 | 647 | if dist is not None and dist not in req:
|
638 | 648 | # XXX add more info
|
639 | 649 | raise VersionConflict(dist, req)
|
@@ -702,6 +712,8 @@ def add(self, dist, entry=None, insert=True, replace=False):
|
702 | 712 | return
|
703 | 713 |
|
704 | 714 | self.by_key[dist.key] = dist
|
| 715 | + normalized_name = packaging.utils.canonicalize_name(dist.key) |
| 716 | + self.normalized_to_canonical_keys[normalized_name] = dist.key |
705 | 717 | if dist.key not in keys:
|
706 | 718 | keys.append(dist.key)
|
707 | 719 | if dist.key not in keys2:
|
@@ -922,14 +934,15 @@ def _added_new(self, dist):
|
922 | 934 | def __getstate__(self):
|
923 | 935 | return (
|
924 | 936 | self.entries[:], self.entry_keys.copy(), self.by_key.copy(),
|
925 |
| - self.callbacks[:] |
| 937 | + self.normalized_to_canonical_keys.copy(), self.callbacks[:] |
926 | 938 | )
|
927 | 939 |
|
928 |
| - def __setstate__(self, e_k_b_c): |
929 |
| - entries, keys, by_key, callbacks = e_k_b_c |
| 940 | + def __setstate__(self, e_k_b_n_c): |
| 941 | + entries, keys, by_key, normalized_to_canonical_keys, callbacks = e_k_b_n_c |
930 | 942 | self.entries = entries[:]
|
931 | 943 | self.entry_keys = keys.copy()
|
932 | 944 | self.by_key = by_key.copy()
|
| 945 | + self.normalized_to_canonical_keys = normalized_to_canonical_keys.copy() |
933 | 946 | self.callbacks = callbacks[:]
|
934 | 947 |
|
935 | 948 |
|
|
0 commit comments