Skip to content

Commit

Permalink
chore: remove py2 compatibility code (#40375)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsanders11 committed Nov 1, 2023
1 parent bc1ba1f commit 425efb5
Show file tree
Hide file tree
Showing 22 changed files with 15 additions and 54 deletions.
2 changes: 1 addition & 1 deletion build/dump_syms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import print_function
#!/usr/bin/env python3

import collections
import os
Expand Down
2 changes: 1 addition & 1 deletion build/npm-run.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
from __future__ import print_function

import os
import subprocess
import sys
Expand Down
2 changes: 1 addition & 1 deletion build/profile_toolchain.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import unicode_literals
#!/usr/bin/env python3

import contextlib
import sys
Expand Down
2 changes: 1 addition & 1 deletion build/zip.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
from __future__ import print_function

import os
import subprocess
import sys
Expand Down
2 changes: 1 addition & 1 deletion build/zip_libcxx.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
from __future__ import print_function

import os
import subprocess
import sys
Expand Down
2 changes: 1 addition & 1 deletion script/add-debug-link.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
from __future__ import print_function

import argparse
import os
import sys
Expand Down
2 changes: 1 addition & 1 deletion script/copy-debug-symbols.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
from __future__ import print_function

import argparse
import os
import sys
Expand Down
1 change: 0 additions & 1 deletion script/generate-config-gypi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3

from __future__ import print_function
import ast
import os
import pprint
Expand Down
1 change: 0 additions & 1 deletion script/lib/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3

from __future__ import print_function
import os
import sys

Expand Down
12 changes: 1 addition & 11 deletions script/lib/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
structure, or make assumptions about the passed arguments or calls' outcomes.
"""

from __future__ import unicode_literals

import io
import os
import posixpath
Expand Down Expand Up @@ -229,14 +227,6 @@ def remove_patch_filename(patch):
force_keep_next_line = l.startswith('Subject: ')


def to_utf8(patch):
"""Python 2/3 compatibility: unicode has been renamed to str in Python3"""
if sys.version_info[0] >= 3:
return str(patch, "utf-8")

return unicode(patch, "utf-8")


def export_patches(repo, out_dir, patch_range=None, dry_run=False):
if not os.path.exists(repo):
sys.stderr.write(
Expand All @@ -263,7 +253,7 @@ def export_patches(repo, out_dir, patch_range=None, dry_run=False):
for patch in patches:
filename = get_file_name(patch)
filepath = posixpath.join(out_dir, filename)
existing_patch = to_utf8(io.open(filepath, 'rb').read())
existing_patch = str(io.open(filepath, 'rb').read(), 'utf-8')
formatted_patch = join_patch(patch)
if formatted_patch != existing_patch:
bad_patches.append(filename)
Expand Down
9 changes: 2 additions & 7 deletions script/lib/native_tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import print_function
#!/usr/bin/env python3

import os
import subprocess
Expand All @@ -10,11 +10,6 @@
sys.path.append(PYYAML_LIB_DIR)
import yaml #pylint: disable=wrong-import-position,wrong-import-order

try:
basestring # Python 2
except NameError: # Python 3
basestring = str # pylint: disable=redefined-builtin


class Verbosity:
CHATTY = 'chatty' # stdout and stderr
Expand Down Expand Up @@ -148,7 +143,7 @@ def __expand_shorthand(value):
if isinstance(value, dict):
return value

if isinstance(value, basestring):
if isinstance(value, str):
return {value: None}

raise AssertionError("unexpected shorthand type: {}".format(type(value)))
Expand Down
7 changes: 1 addition & 6 deletions script/lib/util.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
#!/usr/bin/env python3

from __future__ import print_function
import contextlib
import errno
import json
import os
import shutil
import subprocess
import sys
# Python 3 / 2 compat import
try:
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen
from urllib.request import urlopen
import zipfile

# from lib.config import is_verbose_mode
Expand Down
2 changes: 0 additions & 2 deletions script/native-tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env python3

from __future__ import print_function

import argparse
import os
import sys
Expand Down
10 changes: 1 addition & 9 deletions script/patches-mtime-cache.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env python3

from __future__ import print_function

import argparse
import hashlib
import json
Expand Down Expand Up @@ -168,13 +166,7 @@ def main():
traceback.print_exc(file=sys.stderr)
return 0
elif args.operation == "set":
# Python 2/3 compatibility
try:
user_input = raw_input
except NameError:
user_input = input

answer = user_input(
answer = input(
"WARNING: Manually setting mtimes could mess up your build. "
"If you're sure, type yes: "
)
Expand Down
1 change: 0 additions & 1 deletion script/release/uploaders/upload-index-json.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3

from __future__ import print_function
import json
import os
import sys
Expand Down
1 change: 0 additions & 1 deletion script/release/uploaders/upload.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3

from __future__ import print_function
import argparse
import datetime
import hashlib
Expand Down
2 changes: 0 additions & 2 deletions script/run-clang-format.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
A diff output is produced and a sensible exit code is returned.
"""

from __future__ import print_function, unicode_literals

import argparse
import codecs
import difflib
Expand Down
2 changes: 1 addition & 1 deletion script/strip-binaries.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
from __future__ import print_function

import argparse
import os
import sys
Expand Down
2 changes: 0 additions & 2 deletions script/verify-chromedriver.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env python3

from __future__ import print_function

import argparse
import os
import re
Expand Down
2 changes: 1 addition & 1 deletion script/verify-ffmpeg.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
from __future__ import print_function

import argparse
import os
import platform
Expand Down
2 changes: 1 addition & 1 deletion script/verify-mksnapshot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
from __future__ import print_function

import argparse
import glob
import os
Expand Down
1 change: 0 additions & 1 deletion script/zip-symbols.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3

from __future__ import print_function
import argparse
import glob
import os
Expand Down

0 comments on commit 425efb5

Please sign in to comment.