barman
barman copied to clipboard
Migrate from distutils
The distutils module is deprecated and will be removed in Python 3.12
.
The only things we use from distutils in Barman are distutils.version.Version
and distutils.version.LooseVersion
so in theory we can follow the migration advice provided by the Python Packaging Authority and use packaging.version
instead.
For many uses of distutils.version
that's sensible advice, however:
- In Barman we are using
LooseVersion
to handle version strings from PostgreSQL and its related utilities. - The replacement in
packaging.version
removes any support for version strings which aren't compliant with PEP 440. - The version srings for PostgreSQL and related utilities cannot be expected to conform to PEP 440.
So migrating to packaging.version
does not (necessarily) solve our problem. We may instead need to find a replacement for LooseVersion
.
The following plan is suggested:
- Determine whether we still need the functionality provided by
LooseVersion
. The versions of PostgreSQL and utilities we support have changed significantly sinceLooseVersion
was added to Barman so it is possible that all currently supported versions can be handled bypackaging.version
. If that's the case we can use the official migration advice and move on with life. Note: We also need to consider version strings from some propriertary PostgreSQL-compatible products here. - If we can demonstrate we really do need
LooseVersion
with the current set of supported versions, we must find or make a suitable replacement forLooseVersion
. One possibility is https://pypi.org/project/looseversion/ which aims to be a drop-in replacement, however we would need to check whether the package is available through OS package managers on supported Linux systems.
The main issue comes from get_version_info
when creating a Version from raw version that can include devel, alpha...
But we could just convert the version to the proper version that meet PEP440 requirements. Looking at the actual validation, it should be possible (regex that raw version must match in barman r"(\d+)(\.(\d+)|devel|beta|alpha|rc).*"
A test suite should be created to validate this change properly.
Also Version
cannot be compared to string directly so comparisons must be fixed (not a problem)