easybuild-framework icon indicating copy to clipboard operation
easybuild-framework copied to clipboard

add easybuild.tools.LooseVersion (since distutils is deprecated in Python 3.10)

Open Flamefire opened this issue 4 years ago • 3 comments

Port/Copy of distutils.version.LooseVersion as distutils will be deprecated and eventually removed from Python 3.10+

Slightly simplified and with tests Also includes the fix from https://bugs.python.org/issue14894 to compare any LooseVersion instance in Python 3

BTW: There is a major pitfall we might actually run into at some points:

        # Careful here: 1.0 > 1 !!!
        self.assertGreater(LooseVersion('1.0'), LooseVersion('1'))
        self.assertLess(LooseVersion('1'), LooseVersion('1.0'))

With the included fix we could actually fix that such that missing components are considered equal. So the above would return equal which IMO is more sane for our usages This is how e.g. CMake does its if(ver VERSION_GREATER ver2)

Flamefire avatar Aug 03 '21 09:08 Flamefire

@boegel Updated this. As this is required for #3963 I'd like to get this in. IMO having this class is very good, especially as we now have full control over it. This means:

  • Fix the bug when sorting
  • Drop-in replacement
  • Easy use in comparisons e.g. version = LooseVersion(self.version) and later if version > '1.4' and version < '1.6' reads very nice.

Flamefire avatar Jul 26 '22 14:07 Flamefire

Another (short-term) option here could be to keep using LooseVersion for Python versions where it is available, and fall back to the looseversion Python package that is available via PyPI for Python > = v3.12 .

Longer-term (EasyBuild v5.0?) we should probably fully take matters into our own hands, to avoid a required dependency outside of the Python standard library going forward...

boegel avatar Oct 14 '22 14:10 boegel

Why wait and use different versions on different Pythons creating possible hard-to-recreate bugs?

So why not just use this everywhere now? Is there any downside?

Flamefire avatar Oct 17 '22 08:10 Flamefire