Packaging Legacy

23.0.post0 · active · verified Thu Apr 16

Packaging-legacy is a Python library, currently at version 23.0.post0, that provides support for 'legacy' Python packaging functionality. It restores features, primarily related to version parsing, that were removed from the official `packaging` library. Its main utility is the `packaging_legacy.version.parse` function, which can handle version strings that the modern `packaging` library would deem invalid. The library has an infrequent release cadence, with only two releases to date, both in late 2023.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to parse a 'legacy' version string using `packaging_legacy.version.parse`. It highlights that such a version will be represented by a `LegacyVersion` object, which is distinct from the standard `Version` object used for PEP 440 compliant versions. The example also implicitly contrasts this behavior with the modern `packaging` library, which would raise an `InvalidVersion` error for such a string.

from packaging_legacy.version import parse, LegacyVersion

# Example of parsing a legacy version string
legacy_version_string = "1.0.0.alpha0"
version = parse(legacy_version_string)

print(f"Parsed version: {version}")
print(f"Is it a LegacyVersion? {isinstance(version, LegacyVersion)}")

# Compare with a standard version
standard_version = parse("1.0.0a0")
print(f"Comparing {version} and {standard_version}: {version == standard_version}")

# The modern 'packaging' library would raise InvalidVersion for '1.0.0.alpha0'
# To demonstrate, one would typically use a try-except block here
# import packaging.version
# try:
#     packaging.version.parse("1.0.0.alpha0")
# except packaging.version.InvalidVersion as e:
#     print(f"Modern packaging error: {e}")

view raw JSON →