[libcxx-commits] [libcxx] f46f93b - [libc++][NFC] Resolve Python 2 FIXME

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Nov 12 10:55:26 PST 2021


Author: Alfsonso Gregory
Date: 2021-11-12T13:55:22-05:00
New Revision: f46f93b4786377dd7ee704ef2beedadfe4f05adf

URL: https://github.com/llvm/llvm-project/commit/f46f93b4786377dd7ee704ef2beedadfe4f05adf
DIFF: https://github.com/llvm/llvm-project/commit/f46f93b4786377dd7ee704ef2beedadfe4f05adf.diff

LOG: [libc++][NFC] Resolve Python 2 FIXME

We don't use Python 2 anymore, so let us do the recommended fix instead
of using the workaround made for Python 2.

Differential Revision: https://reviews.llvm.org/D107715

Added: 
    

Modified: 
    libcxx/CMakeLists.txt
    libcxx/utils/gdb/libcxx/printers.py
    libcxx/utils/libcxx/util.py
    libcxx/utils/ssh.py

Removed: 
    


################################################################################
diff  --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 657714fb00945..5ab8a30d57e96 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -46,17 +46,7 @@ endif()
 if (LIBCXX_STANDALONE_BUILD)
   find_package(Python3 COMPONENTS Interpreter)
   if(NOT Python3_Interpreter_FOUND)
-    message(WARNING "Python3 not found, using python2 as a fallback")
-    find_package(Python2 COMPONENTS Interpreter REQUIRED)
-    if(Python2_VERSION VERSION_LESS 2.7)
-      message(SEND_ERROR "Python 2.7 or newer is required")
-    endif()
-
-    # Treat python2 as python3
-    add_executable(Python3::Interpreter IMPORTED)
-    set_target_properties(Python3::Interpreter PROPERTIES
-      IMPORTED_LOCATION ${Python2_EXECUTABLE})
-    set(Python3_EXECUTABLE ${Python2_EXECUTABLE})
+    message(SEND_ERROR "Python3 not found. Python3 is required")
   endif()
 endif()
 

diff  --git a/libcxx/utils/gdb/libcxx/printers.py b/libcxx/utils/gdb/libcxx/printers.py
index 9805ae9cb840d..1b728a461f52b 100644
--- a/libcxx/utils/gdb/libcxx/printers.py
+++ b/libcxx/utils/gdb/libcxx/printers.py
@@ -147,10 +147,6 @@ def __next__(self):
             self.count += 1
             return ("[%d]" % self.count, child)
 
-        # TODO Delete when we drop Python 2.
-        def next(self):
-            return self.__next__()
-
     def __init__(self, val):
         self.val = val
 
@@ -370,10 +366,6 @@ def __next__(self):
                 self.offset = 0
             return ("[%d]" % self.count, outbit)
 
-        # TODO Delete when we drop Python 2.
-        def next(self):
-            return self.__next__()
-
     class _VectorIterator(object):
         """Class to iterate over the non-bool vector's children."""
 
@@ -393,10 +385,6 @@ def __next__(self):
             self.item += 1
             return ("[%d]" % self.count, entry)
 
-        # TODO Delete when we drop Python 2.
-        def next(self):
-            return self.__next__()
-
     def __init__(self, val):
         """Set val, length, capacity, and iterator for bool and normal vectors."""
         self.val = val

diff  --git a/libcxx/utils/libcxx/util.py b/libcxx/utils/libcxx/util.py
index 8c93f392ed32d..d9440f624acae 100644
--- a/libcxx/utils/libcxx/util.py
+++ b/libcxx/utils/libcxx/util.py
@@ -102,7 +102,7 @@ def which(command, paths = None):
     (or the PATH environment variable, if unspecified)."""
 
     if paths is None:
-        paths = os.environ.get('PATH','')
+        paths = os.environ.get('PATH', '')
 
     # Check for absolute match first.
     if os.path.isfile(command):
@@ -202,23 +202,20 @@ def executeCommand(command, cwd=None, env=None, input=None, timeout=0):
                          stderr=subprocess.PIPE,
                          env=env, close_fds=kUseCloseFDs)
     timerObject = None
-    # FIXME: Because of the way nested function scopes work in Python 2.x we
-    # need to use a reference to a mutable object rather than a plain
-    # bool. In Python 3 we could use the "nonlocal" keyword but we need
-    # to support Python 2 as well.
-    hitTimeOut = [False]
+    hitTimeOut = False
     try:
         if timeout > 0:
             def killProcess():
                 # We may be invoking a shell so we need to kill the
                 # process and all its children.
-                hitTimeOut[0] = True
+                nonlocal hitTimeOut
+                hitTimeOut = True
                 killProcessAndChildren(p.pid)
 
             timerObject = threading.Timer(timeout, killProcess)
             timerObject.start()
 
-        out,err = p.communicate(input=input)
+        out, err = p.communicate(input=input)
         exitCode = p.wait()
     finally:
         if timerObject != None:
@@ -228,7 +225,7 @@ def killProcess():
     out = convert_string(out)
     err = convert_string(err)
 
-    if hitTimeOut[0]:
+    if hitTimeOut:
         raise ExecuteCommandTimeoutException(
             msg='Reached timeout of {} seconds'.format(timeout),
             out=out,

diff  --git a/libcxx/utils/ssh.py b/libcxx/utils/ssh.py
index d6346fcb20be9..6c1d706984dd8 100755
--- a/libcxx/utils/ssh.py
+++ b/libcxx/utils/ssh.py
@@ -23,11 +23,7 @@
 import tarfile
 import tempfile
 
-try:
-   from shlex import quote as cmd_quote
-except ImportError:
-   # for Python 2 compatibility
-   from pipes import quote as cmd_quote
+from shlex import quote as cmd_quote
 
 def ssh(args, command):
     cmd = ['ssh', '-oBatchMode=yes']


        


More information about the libcxx-commits mailing list