|
2 | 2 | from optparse import Values |
3 | 3 | from typing import Generator, Iterable, Iterator, List, NamedTuple, Optional |
4 | 4 |
|
| 5 | +from pip._vendor.packaging.requirements import InvalidRequirement |
5 | 6 | from pip._vendor.packaging.utils import canonicalize_name |
6 | 7 |
|
7 | 8 | from pip._internal.cli.base_command import Command |
@@ -100,12 +101,19 @@ def _get_requiring_packages(current_dist: BaseDistribution) -> Iterator[str]: |
100 | 101 | except KeyError: |
101 | 102 | continue |
102 | 103 |
|
103 | | - requires = sorted( |
104 | | - # Avoid duplicates in requirements (e.g. due to environment markers). |
105 | | - {req.name for req in dist.iter_dependencies()}, |
106 | | - key=str.lower, |
107 | | - ) |
108 | | - required_by = sorted(_get_requiring_packages(dist), key=str.lower) |
| 104 | + try: |
| 105 | + requires = sorted( |
| 106 | + # Avoid duplicates in requirements (e.g. due to environment markers). |
| 107 | + {req.name for req in dist.iter_dependencies()}, |
| 108 | + key=str.lower, |
| 109 | + ) |
| 110 | + except InvalidRequirement: |
| 111 | + requires = sorted(dist.iter_raw_dependencies(), key=str.lower) |
| 112 | + |
| 113 | + try: |
| 114 | + required_by = sorted(_get_requiring_packages(dist), key=str.lower) |
| 115 | + except InvalidRequirement: |
| 116 | + required_by = ["#N/A"] |
109 | 117 |
|
110 | 118 | try: |
111 | 119 | entry_points_text = dist.read_text("entry_points.txt") |
@@ -139,7 +147,7 @@ def _get_requiring_packages(current_dist: BaseDistribution) -> Iterator[str]: |
139 | 147 |
|
140 | 148 | yield _PackageInfo( |
141 | 149 | name=dist.raw_name, |
142 | | - version=str(dist.version), |
| 150 | + version=dist.raw_version, |
143 | 151 | location=dist.location or "", |
144 | 152 | editable_project_location=dist.editable_project_location, |
145 | 153 | requires=requires, |
|
0 commit comments