|
18 | 18 | from collections import deque
|
19 | 19 |
|
20 | 20 | from pip._vendor import pkg_resources
|
21 |
| -from pip._vendor.packaging.utils import canonicalize_name |
22 | 21 | # NOTE: retrying is not annotated in typeshed as on 2017-07-17, which is
|
23 | 22 | # why we ignore the type on this import.
|
24 | 23 | from pip._vendor.retrying import retry # type: ignore
|
|
34 | 33 | site_packages,
|
35 | 34 | user_site,
|
36 | 35 | )
|
| 36 | +from pip._internal.metadata import get_environment |
37 | 37 | from pip._internal.utils.compat import (
|
38 | 38 | WINDOWS,
|
39 | 39 | expanduser,
|
@@ -441,78 +441,11 @@ def get_installed_distributions(
|
441 | 441 | If ``paths`` is set, only report the distributions present at the
|
442 | 442 | specified list of locations.
|
443 | 443 | """
|
444 |
| - if paths: |
445 |
| - working_set = pkg_resources.WorkingSet(paths) |
446 |
| - else: |
447 |
| - working_set = pkg_resources.working_set |
448 |
| - |
449 |
| - if local_only: |
450 |
| - local_test = dist_is_local |
451 |
| - else: |
452 |
| - def local_test(d): |
453 |
| - return True |
454 |
| - |
455 |
| - if include_editables: |
456 |
| - def editable_test(d): |
457 |
| - return True |
458 |
| - else: |
459 |
| - def editable_test(d): |
460 |
| - return not dist_is_editable(d) |
461 |
| - |
462 |
| - if editables_only: |
463 |
| - def editables_only_test(d): |
464 |
| - return dist_is_editable(d) |
465 |
| - else: |
466 |
| - def editables_only_test(d): |
467 |
| - return True |
468 |
| - |
469 |
| - if user_only: |
470 |
| - user_test = dist_in_usersite |
471 |
| - else: |
472 |
| - def user_test(d): |
473 |
| - return True |
474 |
| - |
475 |
| - return [d for d in working_set |
476 |
| - if local_test(d) and |
477 |
| - d.key not in skip and |
478 |
| - editable_test(d) and |
479 |
| - editables_only_test(d) and |
480 |
| - user_test(d) |
481 |
| - ] |
482 |
| - |
483 |
| - |
484 |
| -def search_distribution(req_name): |
485 |
| - |
486 |
| - # Canonicalize the name before searching in the list of |
487 |
| - # installed distributions and also while creating the package |
488 |
| - # dictionary to get the Distribution object |
489 |
| - req_name = canonicalize_name(req_name) |
490 |
| - packages = get_installed_distributions(skip=()) |
491 |
| - pkg_dict = {canonicalize_name(p.key): p for p in packages} |
492 |
| - return pkg_dict.get(req_name) |
| 444 | + return list(get_environment(paths).iter_installed_distributions()) |
493 | 445 |
|
494 | 446 |
|
495 | 447 | def get_distribution(req_name):
|
496 |
| - """Given a requirement name, return the installed Distribution object""" |
497 |
| - |
498 |
| - # Search the distribution by looking through the working set |
499 |
| - dist = search_distribution(req_name) |
500 |
| - |
501 |
| - # If distribution could not be found, call working_set.require |
502 |
| - # to update the working set, and try to find the distribution |
503 |
| - # again. |
504 |
| - # This might happen for e.g. when you install a package |
505 |
| - # twice, once using setup.py develop and again using setup.py install. |
506 |
| - # Now when run pip uninstall twice, the package gets removed |
507 |
| - # from the working set in the first uninstall, so we have to populate |
508 |
| - # the working set again so that pip knows about it and the packages |
509 |
| - # gets picked up and is successfully uninstalled the second time too. |
510 |
| - if not dist: |
511 |
| - try: |
512 |
| - pkg_resources.working_set.require(req_name) |
513 |
| - except pkg_resources.DistributionNotFound: |
514 |
| - return None |
515 |
| - return search_distribution(req_name) |
| 448 | + return get_environment().get_installed_distribution(req_name) |
516 | 449 |
|
517 | 450 |
|
518 | 451 | def egg_link_path(dist):
|
|
0 commit comments