changeset 52106:a26a05199070 stable

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.
author Mads Kiilerich <mads@kiilerich.com>
date Thu, 29 Jun 2023 20:02:27 +0200
parents f38be04f9616
children 4fbee56e854a
files tests/hghave.py
diffstat 1 files changed, 11 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/tests/hghave.py	Mon Jun 26 15:16:51 2023 +0200
+++ b/tests/hghave.py	Thu Jun 29 20:02:27 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('20.8b1')
+    if not version:
+        return False
+    return Version(_bytes2sys(version.group(1))) >= Version('20.8b1')
 
 
 @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-2021-11-02")