|
5 | 5 | from typing import TYPE_CHECKING, Generator, List, Optional, Sequence, Tuple, cast |
6 | 6 |
|
7 | 7 | from pip._vendor.packaging.utils import canonicalize_name |
8 | | -from pip._vendor.packaging.version import Version |
| 8 | +from pip._vendor.packaging.version import InvalidVersion, Version |
9 | 9 |
|
10 | 10 | from pip._internal.cli import cmdoptions |
11 | 11 | from pip._internal.cli.index_command import IndexGroupCommand |
@@ -285,12 +285,14 @@ def output_package_listing( |
285 | 285 | self.output_package_listing_columns(data, header) |
286 | 286 | elif options.list_format == "freeze": |
287 | 287 | for dist in packages: |
| 288 | + try: |
| 289 | + req_string = f"{dist.raw_name}=={dist.version}" |
| 290 | + except InvalidVersion: |
| 291 | + req_string = f"{dist.raw_name}==={dist.raw_version}" |
288 | 292 | if options.verbose >= 1: |
289 | | - write_output( |
290 | | - "%s==%s (%s)", dist.raw_name, dist.version, dist.location |
291 | | - ) |
| 293 | + write_output("%s (%s)", req_string, dist.location) |
292 | 294 | else: |
293 | | - write_output("%s==%s", dist.raw_name, dist.version) |
| 295 | + write_output(req_string) |
294 | 296 | elif options.list_format == "json": |
295 | 297 | write_output(format_for_json(packages, options)) |
296 | 298 |
|
@@ -374,9 +376,13 @@ def wheel_build_tag(dist: BaseDistribution) -> Optional[str]: |
374 | 376 | def format_for_json(packages: "_ProcessedDists", options: Values) -> str: |
375 | 377 | data = [] |
376 | 378 | for dist in packages: |
| 379 | + try: |
| 380 | + version = str(dist.version) |
| 381 | + except InvalidVersion: |
| 382 | + version = dist.raw_version |
377 | 383 | info = { |
378 | 384 | "name": dist.raw_name, |
379 | | - "version": str(dist.version), |
| 385 | + "version": version, |
380 | 386 | } |
381 | 387 | if options.verbose >= 1: |
382 | 388 | info["location"] = dist.location or "" |
|
0 commit comments