scons,stdlib: Remove deprecated 'distutils' module

The Python module 'distutils' will be removed in Python 3.12:
https://docs.python.org/3/library/distutils.html

This patch removed usage of 'distutils' in the gem5 code base.

Change-Id: I1e3a944446149f3cd6cbf4211a1565b5f74c85a0
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/71679
Tested-by: kokoro <noreply+kokoro@google.com>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
(cherry picked from commit b182b15f93)
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/71741
Maintainer: Bobby Bruce <bbruce@ucdavis.edu>
Reviewed-by: Bobby Bruce <bbruce@ucdavis.edu>
This commit is contained in:
Bobby R. Bruce
2023-06-13 18:14:38 -07:00
committed by Bobby Bruce
parent 7398e1e401
commit 29055a0a6a
2 changed files with 22 additions and 8 deletions

View File

@@ -27,8 +27,7 @@
from .jsonclient import JSONClient
from .atlasclient import AtlasClient
from _m5 import core
from typing import Optional, Dict, List
from distutils.version import StrictVersion
from typing import Optional, Dict, List, Tuple
import itertools
from m5.util import warn
@@ -191,12 +190,27 @@ class ClientWrapper:
:param resources: A list of resources to sort.
:return: A list of sorted resources.
"""
def sort_tuple(resource: Dict) -> Tuple:
"""This is used for sorting resources by ID and version. First
the ID is sorted, then the version. In cases where the version
contains periods, it's assumed this is to separate a
"major.minor.hotfix" style versioning system. In which case, the
value separated in the most-significant position is sorted before
those less significant. If the value is a digit it is cast as an
int, otherwise, it is cast as a string, to lower-case.
"""
to_return = (resource["id"].lower(),)
for val in resource["resource_version"].split("."):
if val.isdigit():
to_return += (int(val),)
else:
to_return += (str(val).lower(),)
return to_return
return sorted(
resources,
key=lambda resource: (
resource["id"].lower(),
StrictVersion(resource["resource_version"]),
),
key=lambda resource: sort_tuple(resource),
reverse=True,
)