|
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 |
|
@@ -376,7 +378,7 @@ def format_for_json(packages: "_ProcessedDists", options: Values) -> str:
|
376 | 378 | for dist in packages:
|
377 | 379 | info = {
|
378 | 380 | "name": dist.raw_name,
|
379 |
| - "version": str(dist.version), |
| 381 | + "version": dist.raw_version, |
380 | 382 | }
|
381 | 383 | if options.verbose >= 1:
|
382 | 384 | info["location"] = dist.location or ""
|
|
0 commit comments