Refs #32074 -- Removed usage of Python's deprecated distutils.version package.

The distutils package was formally deprecated in Python 3.10 and will
be removed in Python 3.12.
This commit is contained in:
Mariusz Felisiak 2021-04-09 12:56:27 +02:00 committed by GitHub
parent fc268c8648
commit b8c9e9fae1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 6 deletions

View File

@ -3,7 +3,8 @@ import functools
import os
import subprocess
import sys
from distutils.version import LooseVersion
from django.utils.regex_helper import _lazy_re_compile
# Private, stable API for detecting the Python version. PYXY means "Python X.Y
# or later". So that third-party apps can use these values, each constant
@ -95,15 +96,21 @@ def get_git_changeset():
return timestamp.strftime('%Y%m%d%H%M%S')
version_component_re = _lazy_re_compile(r'(\d+|[a-z]+|\.)')
def get_version_tuple(version):
"""
Return a tuple of version numbers (e.g. (1, 2, 3)) from the version
string (e.g. '1.2.3').
"""
loose_version = LooseVersion(version)
version_numbers = []
for item in loose_version.version:
if not isinstance(item, int):
break
version_numbers.append(item)
for item in version_component_re.split(version):
if item and item != '.':
try:
component = int(item)
except ValueError:
break
else:
version_numbers.append(component)
return tuple(version_numbers)