Drop py2 support in various files
python3 is the only supported version of python in depot_tools.
Remove py2 support from files including:
* cpplint.py
* subprocess2.py
* many tests and testing_support files
Bug: 1475402
Change-Id: I67a98188bc13c4dc119e6158a37bd236bfd6ea70
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4824474
Commit-Queue: Gavin Mak <gavinmak@google.com>
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Reviewed-by: Scott Lee <ddoman@chromium.org>
diff --git a/fix_encoding.py b/fix_encoding.py
index b14494f..e97ea05 100644
--- a/fix_encoding.py
+++ b/fix_encoding.py
@@ -14,10 +14,6 @@
import sys
-# Prevents initializing multiple times.
-_SYS_ARGV_PROCESSED = False
-
-
def complain(message):
"""If any exception occurs in this file, we'll probably try to print it
on stderr, which makes for frustrating debugging if stderr is directed
@@ -72,63 +68,6 @@
###############################
# Windows specific
-
-def fix_win_sys_argv(encoding):
- """Converts sys.argv to 'encoding' encoded string.
-
- utf-8 is recommended.
-
- Works around <http://bugs.python.org/issue2128>.
- """
- global _SYS_ARGV_PROCESSED
- if _SYS_ARGV_PROCESSED:
- return False
-
- if sys.version_info.major == 3:
- _SYS_ARGV_PROCESSED = True
- return True
-
- # These types are available on linux but not Mac.
- # pylint: disable=no-name-in-module,F0401
- from ctypes import byref, c_int, POINTER, windll, WINFUNCTYPE
- from ctypes.wintypes import LPCWSTR, LPWSTR
-
- # <http://msdn.microsoft.com/en-us/library/ms683156.aspx>
- GetCommandLineW = WINFUNCTYPE(LPWSTR)(('GetCommandLineW', windll.kernel32))
- # <http://msdn.microsoft.com/en-us/library/bb776391.aspx>
- CommandLineToArgvW = WINFUNCTYPE(POINTER(LPWSTR), LPCWSTR, POINTER(c_int))(
- ('CommandLineToArgvW', windll.shell32))
-
- argc = c_int(0)
- argv_unicode = CommandLineToArgvW(GetCommandLineW(), byref(argc))
- argv = [
- argv_unicode[i].encode(encoding, 'replace') for i in range(0, argc.value)
- ]
-
- if not hasattr(sys, 'frozen'):
- # If this is an executable produced by py2exe or bbfreeze, then it
- # will have been invoked directly. Otherwise, unicode_argv[0] is the
- # Python interpreter, so skip that.
- argv = argv[1:]
-
- # Also skip option arguments to the Python interpreter.
- while len(argv) > 0:
- arg = argv[0]
- if not arg.startswith(b'-') or arg == b'-':
- break
- argv = argv[1:]
- if arg == u'-m':
- # sys.argv[0] should really be the absolute path of the
- # module source, but never mind.
- break
- if arg == u'-c':
- argv[0] = u'-c'
- break
- sys.argv = argv
- _SYS_ARGV_PROCESSED = True
- return True
-
-
def fix_win_codec():
"""Works around <http://bugs.python.org/issue6058>."""
# <http://msdn.microsoft.com/en-us/library/dd317756.aspx>
@@ -216,10 +155,7 @@
def write(self, text):
try:
- if sys.version_info.major == 2 and not isinstance(text, unicode):
- # Convert to unicode.
- text = str(text).decode(self.encoding, 'replace')
- elif sys.version_info.major == 3 and isinstance(text, bytes):
+ if isinstance(text, bytes):
# Bytestrings need to be decoded to a string before being passed to
# Windows.
text = text.decode(self.encoding, 'replace')
@@ -270,10 +206,7 @@
def write(self, text):
try:
- if sys.version_info.major == 2 and isinstance(text, unicode):
- # Replace characters that cannot be printed instead of failing.
- text = text.encode(self.encoding, 'replace')
- if sys.version_info.major == 3 and isinstance(text, bytes):
+ if isinstance(text, bytes):
# Replace characters that cannot be printed instead of failing.
text = text.decode(self.encoding, 'replace')
# When redirecting to a file or process any \n characters will be replaced
@@ -385,6 +318,5 @@
if sys.platform == 'win32':
encoding = sys.getdefaultencoding()
- ret &= fix_win_sys_argv(encoding)
ret &= fix_win_console(encoding)
return ret