From 7092e275f70ee051e84aab384978a98e22cff626 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Tue, 17 Dec 2024 09:52:24 -0700 Subject: [PATCH 1/2] remove remaining distutils references --- CIME/Tools/code_checker | 4 ++-- .../xmlconvertors/config_pes_converter.py | 4 ++-- .../Tools/xmlconvertors/grid_xml_converter.py | 19 +++++++++---------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/CIME/Tools/code_checker b/CIME/Tools/code_checker index 85de0fcfd17..6bc74266cff 100755 --- a/CIME/Tools/code_checker +++ b/CIME/Tools/code_checker @@ -12,7 +12,7 @@ from CIME.code_checker import check_code, expect import argparse, sys, os # pylint: disable=import-error -from distutils.spawn import find_executable +from shutils import which logger = logging.getLogger(__name__) @@ -62,7 +62,7 @@ OR ############################################################################### def _main_func(description): ############################################################################### - pylint = find_executable("pylint") + pylint = which("pylint") expect(pylint is not None, "pylint not found") num_procs, files = parse_command_line(sys.argv, description) diff --git a/CIME/Tools/xmlconvertors/config_pes_converter.py b/CIME/Tools/xmlconvertors/config_pes_converter.py index d1926ab7e9b..a2d1b63d23e 100755 --- a/CIME/Tools/xmlconvertors/config_pes_converter.py +++ b/CIME/Tools/xmlconvertors/config_pes_converter.py @@ -17,7 +17,7 @@ from CIME import utils from CIME.Tools.standard_script_setup import * from CIME.utils import run_cmd -from distutils.spawn import find_executable +from shutils import which import xml.etree.ElementTree as ET import grid_xml_converter @@ -242,7 +242,7 @@ def writexml(self, addlist, newfilename): root.append(ET.Element("WITH")) if a is not None: root.append(a.to_cime5()) - xmllint = find_executable("xmllint") + xmllint = which("xmllint") if xmllint is not None: run_cmd( "{} --format --output {} -".format(xmllint, newfilename), diff --git a/CIME/Tools/xmlconvertors/grid_xml_converter.py b/CIME/Tools/xmlconvertors/grid_xml_converter.py index 009cbf03add..75e9645bb8f 100755 --- a/CIME/Tools/xmlconvertors/grid_xml_converter.py +++ b/CIME/Tools/xmlconvertors/grid_xml_converter.py @@ -25,7 +25,7 @@ from CIME import utils from CIME.Tools.standard_script_setup import * from CIME.utils import run_cmd_no_fail -from distutils.spawn import find_executable +from shutils import which import xml.etree.ElementTree as ET import operator @@ -307,6 +307,7 @@ def __init__(self, xmlfilename): self.n = 0 self.nodes = [] self.populate() + self._xmllint = which(xmllint) def next(self): if self.index >= len(self.nodes): @@ -358,10 +359,9 @@ def writexml(self, addlist, newfilename): if a is not None: grids.append(a.to_cime5()) - xmllint = find_executable("xmllint") - if xmllint is not None: + if self._xmllint is not None: run_cmd_no_fail( - "{} --format --output {} -".format(xmllint, newfilename), + "{} --format --output {} -".format(self._xmllint, newfilename), input_str=ET.tostring(root), ) @@ -392,10 +392,10 @@ def writexml(self, addlist, newfilename): domains.append(ET.Element("WITH")) if a is not None: domains.append(a.to_cime5()) - xmllint = find_executable("xmllint") - if xmllint is not None: + + if self._xmllint is not None: run_cmd_no_fail( - "{} --format --output {} -".format(xmllint, newfilename), + "{} --format --output {} -".format(self._xmllint, newfilename), input_str=ET.tostring(root), ) @@ -422,10 +422,9 @@ def writexml(self, addlist, newfilename): gridmaps.append(ET.Element("WITH")) if a is not None: gridmaps.append(a.to_cime5()) - xmllint = find_executable("xmllint") - if xmllint is not None: + if self._xmllint is not None: run_cmd_no_fail( - "{} --format --output {} -".format(xmllint, newfilename), + "{} --format --output {} -".format(self._xmllint, newfilename), input_str=ET.tostring(root), ) From 380a9304e7705901ad4475e1be60aaba359b0626 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Tue, 17 Dec 2024 11:34:53 -0700 Subject: [PATCH 2/2] shutils should be shutil --- CIME/Tools/code_checker | 2 +- CIME/Tools/xmlconvertors/config_pes_converter.py | 2 +- CIME/Tools/xmlconvertors/grid_xml_converter.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CIME/Tools/code_checker b/CIME/Tools/code_checker index 6bc74266cff..6f7510337ab 100755 --- a/CIME/Tools/code_checker +++ b/CIME/Tools/code_checker @@ -12,7 +12,7 @@ from CIME.code_checker import check_code, expect import argparse, sys, os # pylint: disable=import-error -from shutils import which +from shutil import which logger = logging.getLogger(__name__) diff --git a/CIME/Tools/xmlconvertors/config_pes_converter.py b/CIME/Tools/xmlconvertors/config_pes_converter.py index a2d1b63d23e..cf57c21fb9b 100755 --- a/CIME/Tools/xmlconvertors/config_pes_converter.py +++ b/CIME/Tools/xmlconvertors/config_pes_converter.py @@ -17,7 +17,7 @@ from CIME import utils from CIME.Tools.standard_script_setup import * from CIME.utils import run_cmd -from shutils import which +from shutil import which import xml.etree.ElementTree as ET import grid_xml_converter diff --git a/CIME/Tools/xmlconvertors/grid_xml_converter.py b/CIME/Tools/xmlconvertors/grid_xml_converter.py index 75e9645bb8f..01de9ddcf9f 100755 --- a/CIME/Tools/xmlconvertors/grid_xml_converter.py +++ b/CIME/Tools/xmlconvertors/grid_xml_converter.py @@ -25,7 +25,7 @@ from CIME import utils from CIME.Tools.standard_script_setup import * from CIME.utils import run_cmd_no_fail -from shutils import which +from shutil import which import xml.etree.ElementTree as ET import operator