Version._parse_version_str(version) fails if version is a packaging.version.LegacyVersion #9
Description
Description
PyUpdater 4.0 fails due to dsdev-utils.helpers.Version._parse_version_str()
with an AttributeError: 'LegacyVersion' object has no attribute 'major'
if version string is not PEP440 compliant.
Cause
This line assumes version
is a packaging.version.Version
, so packaging.version.LegacyVersion is not handled.
The problem is introduced in pr #8 (issue #7).
How to reproduce
Using dsdev-utils 1.3.0 on python 3.9.7:
from dsdev_utils.helpers import Version
version_str = '1.18.0-64-g987cb3c' # e.g. git describe output
Version(version_str)._parse_version_str(version_str)
Notes
The LegacyVersion
is deprecated, although it is still used by packaging.version.parse().
I think it would be nice to handle e.g. output of git describe
gracefully, if it starts with a valid PEP440 version, such as '1.18.0-64-g987cb3c'
. Could treat this as a dev release with local identifier, for example doing something along the lines of:
version_str = '1.18.0-64-g987cb3c'
version_str.replace('-', '.dev0+', 1)
On the other hand, perhaps it makes more sense just to require PEP440 compliance and let the user handle this...
Anyway, even if PEP440 compliance is required, I think the non-compliant (LegacyVersion
) case should still be handled gracefully by _parse_version_str()
.