Skip to content

Commit f46f93b

Browse files
AZero13ldionne
authored andcommitted
[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
1 parent 4a0af82 commit f46f93b

File tree

4 files changed

+8
-37
lines changed

4 files changed

+8
-37
lines changed

libcxx/CMakeLists.txt

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,7 @@ endif()
4646
if (LIBCXX_STANDALONE_BUILD)
4747
find_package(Python3 COMPONENTS Interpreter)
4848
if(NOT Python3_Interpreter_FOUND)
49-
message(WARNING "Python3 not found, using python2 as a fallback")
50-
find_package(Python2 COMPONENTS Interpreter REQUIRED)
51-
if(Python2_VERSION VERSION_LESS 2.7)
52-
message(SEND_ERROR "Python 2.7 or newer is required")
53-
endif()
54-
55-
# Treat python2 as python3
56-
add_executable(Python3::Interpreter IMPORTED)
57-
set_target_properties(Python3::Interpreter PROPERTIES
58-
IMPORTED_LOCATION ${Python2_EXECUTABLE})
59-
set(Python3_EXECUTABLE ${Python2_EXECUTABLE})
49+
message(SEND_ERROR "Python3 not found. Python3 is required")
6050
endif()
6151
endif()
6252

libcxx/utils/gdb/libcxx/printers.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,6 @@ def __next__(self):
147147
self.count += 1
148148
return ("[%d]" % self.count, child)
149149

150-
# TODO Delete when we drop Python 2.
151-
def next(self):
152-
return self.__next__()
153-
154150
def __init__(self, val):
155151
self.val = val
156152

@@ -370,10 +366,6 @@ def __next__(self):
370366
self.offset = 0
371367
return ("[%d]" % self.count, outbit)
372368

373-
# TODO Delete when we drop Python 2.
374-
def next(self):
375-
return self.__next__()
376-
377369
class _VectorIterator(object):
378370
"""Class to iterate over the non-bool vector's children."""
379371

@@ -393,10 +385,6 @@ def __next__(self):
393385
self.item += 1
394386
return ("[%d]" % self.count, entry)
395387

396-
# TODO Delete when we drop Python 2.
397-
def next(self):
398-
return self.__next__()
399-
400388
def __init__(self, val):
401389
"""Set val, length, capacity, and iterator for bool and normal vectors."""
402390
self.val = val

libcxx/utils/libcxx/util.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def which(command, paths = None):
102102
(or the PATH environment variable, if unspecified)."""
103103

104104
if paths is None:
105-
paths = os.environ.get('PATH','')
105+
paths = os.environ.get('PATH', '')
106106

107107
# Check for absolute match first.
108108
if os.path.isfile(command):
@@ -202,23 +202,20 @@ def executeCommand(command, cwd=None, env=None, input=None, timeout=0):
202202
stderr=subprocess.PIPE,
203203
env=env, close_fds=kUseCloseFDs)
204204
timerObject = None
205-
# FIXME: Because of the way nested function scopes work in Python 2.x we
206-
# need to use a reference to a mutable object rather than a plain
207-
# bool. In Python 3 we could use the "nonlocal" keyword but we need
208-
# to support Python 2 as well.
209-
hitTimeOut = [False]
205+
hitTimeOut = False
210206
try:
211207
if timeout > 0:
212208
def killProcess():
213209
# We may be invoking a shell so we need to kill the
214210
# process and all its children.
215-
hitTimeOut[0] = True
211+
nonlocal hitTimeOut
212+
hitTimeOut = True
216213
killProcessAndChildren(p.pid)
217214

218215
timerObject = threading.Timer(timeout, killProcess)
219216
timerObject.start()
220217

221-
out,err = p.communicate(input=input)
218+
out, err = p.communicate(input=input)
222219
exitCode = p.wait()
223220
finally:
224221
if timerObject != None:
@@ -228,7 +225,7 @@ def killProcess():
228225
out = convert_string(out)
229226
err = convert_string(err)
230227

231-
if hitTimeOut[0]:
228+
if hitTimeOut:
232229
raise ExecuteCommandTimeoutException(
233230
msg='Reached timeout of {} seconds'.format(timeout),
234231
out=out,

libcxx/utils/ssh.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@
2323
import tarfile
2424
import tempfile
2525

26-
try:
27-
from shlex import quote as cmd_quote
28-
except ImportError:
29-
# for Python 2 compatibility
30-
from pipes import quote as cmd_quote
26+
from shlex import quote as cmd_quote
3127

3228
def ssh(args, command):
3329
cmd = ['ssh', '-oBatchMode=yes']

0 commit comments

Comments
 (0)