From 233c54c135542178703aa700a2dddadc895fedb0 Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Tue, 14 Nov 2023 16:24:10 +0100 Subject: [PATCH] Fix Python DeprecationWarning: 'pipes' Starting from Python 3.11, the pipes module produces this warning: DeprecationWarning: 'pipes' is deprecated and slated for removal in Python 3.13 Turns out that in this repo the pipes module is only used for the "quote" function which is turn directly taken from the shlex module [1]. The shlex module is not deprecated as of today and is already used in other places in this repo. The function shlex.quote has been around since the ancient Python 3.3. [1] https://github.com/python/cpython/blob/3.11/Lib/pipes.py#L64-L66 --- tools/run_tests/run_performance_tests.py | 10 +++++----- tools/run_tests/run_tests.py | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/run_tests/run_performance_tests.py b/tools/run_tests/run_performance_tests.py index 808bc0a30bf..064dbf3328d 100755 --- a/tools/run_tests/run_performance_tests.py +++ b/tools/run_tests/run_performance_tests.py @@ -21,8 +21,8 @@ import collections import itertools import json import os -import pipes import re +import shlex import sys import time @@ -121,7 +121,7 @@ def create_scenario_jobspec( if bq_result_table: cmd += 'BQ_RESULT_TABLE="%s" ' % bq_result_table cmd += "tools/run_tests/performance/run_qps_driver.sh " - cmd += "--scenarios_json=%s " % pipes.quote( + cmd += "--scenarios_json=%s " % shlex.quote( json.dumps({"scenarios": [scenario_json]}) ) cmd += "--scenario_result_file=scenario_result.json " @@ -135,7 +135,7 @@ def create_scenario_jobspec( user_at_host = "%s@%s" % (_REMOTE_HOST_USERNAME, remote_host) cmd = 'ssh %s "cd ~/performance_workspace/grpc/ && "%s' % ( user_at_host, - pipes.quote(cmd), + shlex.quote(cmd), ) return jobset.JobSpec( @@ -157,7 +157,7 @@ def create_quit_jobspec(workers, remote_host=None): user_at_host = "%s@%s" % (_REMOTE_HOST_USERNAME, remote_host) cmd = 'ssh %s "cd ~/performance_workspace/grpc/ && "%s' % ( user_at_host, - pipes.quote(cmd), + shlex.quote(cmd), ) return jobset.JobSpec( @@ -192,7 +192,7 @@ def create_netperf_jobspec( user_at_host = "%s@%s" % (_REMOTE_HOST_USERNAME, client_host) cmd = 'ssh %s "cd ~/performance_workspace/grpc/ && "%s' % ( user_at_host, - pipes.quote(cmd), + shlex.quote(cmd), ) return jobset.JobSpec( diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py index 64d2cfcbeb0..9c3c7fbf519 100755 --- a/tools/run_tests/run_tests.py +++ b/tools/run_tests/run_tests.py @@ -26,10 +26,10 @@ import logging import multiprocessing import os import os.path -import pipes import platform import random import re +import shlex import socket import subprocess import sys @@ -479,7 +479,7 @@ class CLanguage(object): cmdline = [binary] + target["args"] shortname = target.get( "shortname", - " ".join(pipes.quote(arg) for arg in cmdline), + " ".join(shlex.quote(arg) for arg in cmdline), ) shortname += shortname_ext out.append(