gem5-dev@gem5.org

The gem5 Developer List

View all threads

[S] Change in gem5/gem5[develop]: python: Remove Python 'pipes' module

BB
Bobby Bruce (Gerrit)
Thu, Jun 15, 2023 8:17 PM

Bobby Bruce has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/71740?usp=email )

Change subject: python: Remove Python 'pipes' module
......................................................................

python: Remove Python 'pipes' module

This is scheduled for removal from Python in 3.13:
https://docs.python.org/3/library/pipes.html.

The 'shlex.quote' function can replace the 'pipes.quote' function used
in "main.py". A special wrapper has been made to account for the Windows
case which 'shlex.quote' doesn't handle.

Change-Id: I9c84605f0ccd8468b9cab6cece6248ef8c2107f0
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/71678
Maintainer: Jason Lowe-Power power.jg@gmail.com
Tested-by: kokoro noreply+kokoro@google.com
Reviewed-by: Jason Lowe-Power power.jg@gmail.com
(cherry picked from commit a63d376ecd4debd60f89fa2e0592dac6f9addae2)

M src/python/m5/main.py
1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/python/m5/main.py b/src/python/m5/main.py
index 4701dfa..ddcb024 100644
--- a/src/python/m5/main.py
+++ b/src/python/m5/main.py
@@ -496,10 +496,23 @@
% (socket.gethostname(), os.getpid())
)

  •    # in Python 3 pipes.quote() is moved to shlex.quote()
    
  •    import pipes
    
  •    def quote(arg: str) -> str:
    
  •        """Quotes a string for printing in a shell. In addition to  
    

Unix,

  •        this is designed to handle the problematic Windows cases where
    
  •        'shlex.quote' doesn't work"""
    
  •    print("command line:", " ".join(map(pipes.quote, sys.argv)))
    
  •        if os.name == "nt" and os.sep == "\\":
    
  •            # If a Windows machine, we manually quote the string.
    
  •            arg = arg.replace('"', '\\"')
    
  •            if re.search("\s", args):
    
  •                # We quote args which have whitespace.
    
  •                arg = '"' + arg + '"'
    
  •            return arg
    
  •        import shlex
    
  •        return shlex.quote(arg)
    
  •    print("command line:", " ".join(map(quote, sys.argv)))
        print()
    
    # check to make sure we can find the listed script
    

--
To view, visit
https://gem5-review.googlesource.com/c/public/gem5/+/71740?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I9c84605f0ccd8468b9cab6cece6248ef8c2107f0
Gerrit-Change-Number: 71740
Gerrit-PatchSet: 1
Gerrit-Owner: Bobby Bruce bbruce@ucdavis.edu

Bobby Bruce has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/71740?usp=email ) Change subject: python: Remove Python 'pipes' module ...................................................................... python: Remove Python 'pipes' module This is scheduled for removal from Python in 3.13: https://docs.python.org/3/library/pipes.html. The 'shlex.quote' function can replace the 'pipes.quote' function used in "main.py". A special wrapper has been made to account for the Windows case which 'shlex.quote' doesn't handle. Change-Id: I9c84605f0ccd8468b9cab6cece6248ef8c2107f0 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/71678 Maintainer: Jason Lowe-Power <power.jg@gmail.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Jason Lowe-Power <power.jg@gmail.com> (cherry picked from commit a63d376ecd4debd60f89fa2e0592dac6f9addae2) --- M src/python/m5/main.py 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/python/m5/main.py b/src/python/m5/main.py index 4701dfa..ddcb024 100644 --- a/src/python/m5/main.py +++ b/src/python/m5/main.py @@ -496,10 +496,23 @@ % (socket.gethostname(), os.getpid()) ) - # in Python 3 pipes.quote() is moved to shlex.quote() - import pipes + def quote(arg: str) -> str: + """Quotes a string for printing in a shell. In addition to Unix, + this is designed to handle the problematic Windows cases where + 'shlex.quote' doesn't work""" - print("command line:", " ".join(map(pipes.quote, sys.argv))) + if os.name == "nt" and os.sep == "\\": + # If a Windows machine, we manually quote the string. + arg = arg.replace('"', '\\"') + if re.search("\s", args): + # We quote args which have whitespace. + arg = '"' + arg + '"' + return arg + import shlex + + return shlex.quote(arg) + + print("command line:", " ".join(map(quote, sys.argv))) print() # check to make sure we can find the listed script -- To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/71740?usp=email To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings?usp=email Gerrit-MessageType: newchange Gerrit-Project: public/gem5 Gerrit-Branch: develop Gerrit-Change-Id: I9c84605f0ccd8468b9cab6cece6248ef8c2107f0 Gerrit-Change-Number: 71740 Gerrit-PatchSet: 1 Gerrit-Owner: Bobby Bruce <bbruce@ucdavis.edu>