tests: use packaging from setuptools instead of deprecated distutils
authorMads Kiilerich <mads@kiilerich.com>
Mon, 26 Jun 2023 21:31:41 +0200
changeset 51745 e679697a6ca4
parent 51744 be227c60a3e0
child 51746 4f0fad8da04c
tests: use packaging from setuptools instead of deprecated distutils When invoking StrictVersion in 3.12 we got: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead. distutils is dead in the standard library, and we have to move towards using `setuptools` as general extern dependency. Instead of also requiring the extern `packaging`, we will just use the packaging that is vendored in setuptools.
tests/hghave.py
--- a/tests/hghave.py	Mon Jun 26 15:16:51 2023 +0200
+++ b/tests/hghave.py	Mon Jun 26 21:31:41 2023 +0200
@@ -1,4 +1,3 @@
-import distutils.version
 import os
 import re
 import socket
@@ -7,6 +6,11 @@
 import sys
 import tempfile
 
+try:
+    from setuptools.extern.packaging.version import Version
+except ImportError:
+    from distutils.version import StrictVersion as Version
+
 tempprefix = 'hg-hghave-'
 
 checks = {
@@ -1118,16 +1122,18 @@
     blackcmd = 'black --version'
     version_regex = b'black, (?:version )?([0-9a-b.]+)'
     version = matchoutput(blackcmd, version_regex)
-    sv = distutils.version.StrictVersion
-    return version and sv(_bytes2sys(version.group(1))) >= sv('23.3.0')
+    if not version:
+        return False
+    return Version(_bytes2sys(version.group(1))) >= Version('23.3.0')
 
 
 @check('pytype', 'the pytype type checker')
 def has_pytype():
     pytypecmd = 'pytype --version'
     version = matchoutput(pytypecmd, b'[0-9a-b.]+')
-    sv = distutils.version.StrictVersion
-    return version and sv(_bytes2sys(version.group(0))) >= sv('2019.10.17')
+    if not version:
+        return False
+    return Version(_bytes2sys(version.group(0))) >= Version('2019.10.17')
 
 
 @check("rustfmt", "rustfmt tool at version nightly-2024-07-16")