|
73 | 73 | logger = logging.getLogger(__name__)
|
74 | 74 |
|
75 | 75 |
|
| 76 | +def _get_dist(metadata_directory): |
| 77 | + # type: (str) -> Distribution |
| 78 | + """Return a pkg_resources.Distribution for the provided |
| 79 | + metadata directory. |
| 80 | + """ |
| 81 | + dist_dir = metadata_directory.rstrip(os.sep) |
| 82 | + |
| 83 | + # Determine the correct Distribution object type. |
| 84 | + if dist_dir.endswith(".egg-info"): |
| 85 | + dist_cls = pkg_resources.Distribution |
| 86 | + else: |
| 87 | + assert dist_dir.endswith(".dist-info") |
| 88 | + dist_cls = pkg_resources.DistInfoDistribution |
| 89 | + |
| 90 | + # Build a PathMetadata object, from path to metadata. :wink: |
| 91 | + base_dir, dist_dir_name = os.path.split(dist_dir) |
| 92 | + dist_name = os.path.splitext(dist_dir_name)[0] |
| 93 | + metadata = pkg_resources.PathMetadata(base_dir, dist_dir) |
| 94 | + |
| 95 | + return dist_cls( |
| 96 | + base_dir, |
| 97 | + project_name=dist_name, |
| 98 | + metadata=metadata, |
| 99 | + ) |
| 100 | + |
| 101 | + |
76 | 102 | class InstallRequirement(object):
|
77 | 103 | """
|
78 | 104 | Represents something that may be installed later on, may have information
|
@@ -619,26 +645,7 @@ def metadata(self):
|
619 | 645 |
|
620 | 646 | def get_dist(self):
|
621 | 647 | # type: () -> Distribution
|
622 |
| - """Return a pkg_resources.Distribution for this requirement""" |
623 |
| - dist_dir = self.metadata_directory.rstrip(os.sep) |
624 |
| - |
625 |
| - # Determine the correct Distribution object type. |
626 |
| - if dist_dir.endswith(".egg-info"): |
627 |
| - dist_cls = pkg_resources.Distribution |
628 |
| - else: |
629 |
| - assert dist_dir.endswith(".dist-info") |
630 |
| - dist_cls = pkg_resources.DistInfoDistribution |
631 |
| - |
632 |
| - # Build a PathMetadata object, from path to metadata. :wink: |
633 |
| - base_dir, dist_dir_name = os.path.split(dist_dir) |
634 |
| - dist_name = os.path.splitext(dist_dir_name)[0] |
635 |
| - metadata = pkg_resources.PathMetadata(base_dir, dist_dir) |
636 |
| - |
637 |
| - return dist_cls( |
638 |
| - base_dir, |
639 |
| - project_name=dist_name, |
640 |
| - metadata=metadata, |
641 |
| - ) |
| 648 | + return _get_dist(self.metadata_directory) |
642 | 649 |
|
643 | 650 | def assert_source_matches_version(self):
|
644 | 651 | # type: () -> None
|
|
0 commit comments