diff options
author | Mike Frysinger <vapier@google.com> | 2019-06-13 02:24:21 -0400 |
---|---|---|
committer | Mike Frysinger <vapier@google.com> | 2021-01-06 18:53:58 +0000 |
commit | acf63b28928b33d1335dfed1af7e2d8fc6bb5fc4 (patch) | |
tree | e7b65524857d00cec6b36c989659afd1132d15ce | |
parent | 784ccfc040dc8efa1a64d3c7d4070b66beb15d08 (diff) | |
download | git-repo-acf63b28928b33d1335dfed1af7e2d8fc6bb5fc4.tar.gz |
drop pyversion & is_python3 checking
We're committed to Python 3 at this point, so purge all the
is_python3 related dynamic checks.
Bug: https://crbug.com/gerrit/10418
Change-Id: I4c8b405d6de359b8b83223c9f4b9c8ffa18ea1a2
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/292383
Reviewed-by: Chris Mcdonald <cjmcdonald@google.com>
Tested-by: Mike Frysinger <vapier@google.com>
-rw-r--r-- | git_config.py | 20 | ||||
-rw-r--r-- | hooks.py | 11 | ||||
-rwxr-xr-x | main.py | 12 | ||||
-rw-r--r-- | manifest_xml.py | 10 | ||||
-rw-r--r-- | platform_utils.py | 8 | ||||
-rw-r--r-- | platform_utils_win32.py | 27 | ||||
-rw-r--r-- | project.py | 11 | ||||
-rw-r--r-- | pyversion.py | 19 | ||||
-rw-r--r-- | subcmds/gitc_delete.py | 4 | ||||
-rw-r--r-- | subcmds/init.py | 10 | ||||
-rw-r--r-- | subcmds/sync.py | 25 | ||||
-rw-r--r-- | subcmds/upload.py | 5 | ||||
-rw-r--r-- | tests/test_wrapper.py | 14 |
13 files changed, 20 insertions, 156 deletions
diff --git a/git_config.py b/git_config.py index fd8e9268..2fa43a1e 100644 --- a/git_config.py +++ b/git_config.py | |||
@@ -14,6 +14,7 @@ | |||
14 | 14 | ||
15 | import contextlib | 15 | import contextlib |
16 | import errno | 16 | import errno |
17 | from http.client import HTTPException | ||
17 | import json | 18 | import json |
18 | import os | 19 | import os |
19 | import re | 20 | import re |
@@ -26,25 +27,12 @@ try: | |||
26 | except ImportError: | 27 | except ImportError: |
27 | import dummy_threading as _threading | 28 | import dummy_threading as _threading |
28 | import time | 29 | import time |
29 | 30 | import urllib.error | |
30 | from pyversion import is_python3 | 31 | import urllib.request |
31 | if is_python3(): | ||
32 | import urllib.request | ||
33 | import urllib.error | ||
34 | else: | ||
35 | import urllib2 | ||
36 | import imp | ||
37 | urllib = imp.new_module('urllib') | ||
38 | urllib.request = urllib2 | ||
39 | urllib.error = urllib2 | ||
40 | 32 | ||
41 | from error import GitError, UploadError | 33 | from error import GitError, UploadError |
42 | import platform_utils | 34 | import platform_utils |
43 | from repo_trace import Trace | 35 | from repo_trace import Trace |
44 | if is_python3(): | ||
45 | from http.client import HTTPException | ||
46 | else: | ||
47 | from httplib import HTTPException | ||
48 | 36 | ||
49 | from git_command import GitCommand | 37 | from git_command import GitCommand |
50 | from git_command import ssh_sock | 38 | from git_command import ssh_sock |
@@ -341,8 +329,6 @@ class GitConfig(object): | |||
341 | d = self._do('--null', '--list') | 329 | d = self._do('--null', '--list') |
342 | if d is None: | 330 | if d is None: |
343 | return c | 331 | return c |
344 | if not is_python3(): | ||
345 | d = d.decode('utf-8') | ||
346 | for line in d.rstrip('\0').split('\0'): | 332 | for line in d.rstrip('\0').split('\0'): |
347 | if '\n' in line: | 333 | if '\n' in line: |
348 | key, val = line.split('\n', 1) | 334 | key, val = line.split('\n', 1) |
@@ -19,20 +19,11 @@ import re | |||
19 | import subprocess | 19 | import subprocess |
20 | import sys | 20 | import sys |
21 | import traceback | 21 | import traceback |
22 | import urllib.parse | ||
22 | 23 | ||
23 | from error import HookError | 24 | from error import HookError |
24 | from git_refs import HEAD | 25 | from git_refs import HEAD |
25 | 26 | ||
26 | from pyversion import is_python3 | ||
27 | if is_python3(): | ||
28 | import urllib.parse | ||
29 | else: | ||
30 | import imp | ||
31 | import urlparse | ||
32 | urllib = imp.new_module('urllib') | ||
33 | urllib.parse = urlparse | ||
34 | input = raw_input # noqa: F821 | ||
35 | |||
36 | 27 | ||
37 | class RepoHook(object): | 28 | class RepoHook(object): |
38 | """A RepoHook contains information about a script to run as a hook. | 29 | """A RepoHook contains information about a script to run as a hook. |
@@ -28,15 +28,7 @@ import shlex | |||
28 | import sys | 28 | import sys |
29 | import textwrap | 29 | import textwrap |
30 | import time | 30 | import time |
31 | 31 | import urllib.request | |
32 | from pyversion import is_python3 | ||
33 | if is_python3(): | ||
34 | import urllib.request | ||
35 | else: | ||
36 | import imp | ||
37 | import urllib2 | ||
38 | urllib = imp.new_module('urllib') | ||
39 | urllib.request = urllib2 | ||
40 | 32 | ||
41 | try: | 33 | try: |
42 | import kerberos | 34 | import kerberos |
@@ -68,8 +60,6 @@ from wrapper import WrapperPath, Wrapper | |||
68 | 60 | ||
69 | from subcmds import all_commands | 61 | from subcmds import all_commands |
70 | 62 | ||
71 | if not is_python3(): | ||
72 | input = raw_input # noqa: F821 | ||
73 | 63 | ||
74 | # NB: These do not need to be kept in sync with the repo launcher script. | 64 | # NB: These do not need to be kept in sync with the repo launcher script. |
75 | # These may be much newer as it allows the repo launcher to roll between | 65 | # These may be much newer as it allows the repo launcher to roll between |
diff --git a/manifest_xml.py b/manifest_xml.py index bbecb934..9b7a81b3 100644 --- a/manifest_xml.py +++ b/manifest_xml.py | |||
@@ -17,15 +17,7 @@ import os | |||
17 | import re | 17 | import re |
18 | import sys | 18 | import sys |
19 | import xml.dom.minidom | 19 | import xml.dom.minidom |
20 | 20 | import urllib.parse | |
21 | from pyversion import is_python3 | ||
22 | if is_python3(): | ||
23 | import urllib.parse | ||
24 | else: | ||
25 | import imp | ||
26 | import urlparse | ||
27 | urllib = imp.new_module('urllib') | ||
28 | urllib.parse = urlparse | ||
29 | 21 | ||
30 | import gitc_utils | 22 | import gitc_utils |
31 | from git_config import GitConfig, IsId | 23 | from git_config import GitConfig, IsId |
diff --git a/platform_utils.py b/platform_utils.py index 6dd3385d..a280982a 100644 --- a/platform_utils.py +++ b/platform_utils.py | |||
@@ -15,16 +15,10 @@ | |||
15 | import errno | 15 | import errno |
16 | import os | 16 | import os |
17 | import platform | 17 | import platform |
18 | from queue import Queue | ||
18 | import select | 19 | import select |
19 | import shutil | 20 | import shutil |
20 | import stat | 21 | import stat |
21 | |||
22 | from pyversion import is_python3 | ||
23 | if is_python3(): | ||
24 | from queue import Queue | ||
25 | else: | ||
26 | from Queue import Queue | ||
27 | |||
28 | from threading import Thread | 22 | from threading import Thread |
29 | 23 | ||
30 | 24 | ||
diff --git a/platform_utils_win32.py b/platform_utils_win32.py index 26c8ad42..bf916d47 100644 --- a/platform_utils_win32.py +++ b/platform_utils_win32.py | |||
@@ -14,18 +14,10 @@ | |||
14 | 14 | ||
15 | import errno | 15 | import errno |
16 | 16 | ||
17 | from pyversion import is_python3 | ||
18 | from ctypes import WinDLL, get_last_error, FormatError, WinError, addressof | 17 | from ctypes import WinDLL, get_last_error, FormatError, WinError, addressof |
19 | from ctypes import c_buffer | 18 | from ctypes import c_buffer, c_ubyte, Structure, Union, byref |
20 | from ctypes.wintypes import BOOL, BOOLEAN, LPCWSTR, DWORD, HANDLE | 19 | from ctypes.wintypes import BOOL, BOOLEAN, LPCWSTR, DWORD, HANDLE |
21 | from ctypes.wintypes import WCHAR, USHORT, LPVOID, ULONG | 20 | from ctypes.wintypes import WCHAR, USHORT, LPVOID, ULONG, LPDWORD |
22 | if is_python3(): | ||
23 | from ctypes import c_ubyte, Structure, Union, byref | ||
24 | from ctypes.wintypes import LPDWORD | ||
25 | else: | ||
26 | # For legacy Python2 different imports are needed. | ||
27 | from ctypes.wintypes import POINTER, c_ubyte, Structure, Union, byref | ||
28 | LPDWORD = POINTER(DWORD) | ||
29 | 21 | ||
30 | kernel32 = WinDLL('kernel32', use_last_error=True) | 22 | kernel32 = WinDLL('kernel32', use_last_error=True) |
31 | 23 | ||
@@ -202,26 +194,15 @@ def readlink(path): | |||
202 | 'Error reading symbolic link \"%s\"'.format(path)) | 194 | 'Error reading symbolic link \"%s\"'.format(path)) |
203 | rdb = REPARSE_DATA_BUFFER.from_buffer(target_buffer) | 195 | rdb = REPARSE_DATA_BUFFER.from_buffer(target_buffer) |
204 | if rdb.ReparseTag == IO_REPARSE_TAG_SYMLINK: | 196 | if rdb.ReparseTag == IO_REPARSE_TAG_SYMLINK: |
205 | return _preserve_encoding(path, rdb.SymbolicLinkReparseBuffer.PrintName) | 197 | return rdb.SymbolicLinkReparseBuffer.PrintName |
206 | elif rdb.ReparseTag == IO_REPARSE_TAG_MOUNT_POINT: | 198 | elif rdb.ReparseTag == IO_REPARSE_TAG_MOUNT_POINT: |
207 | return _preserve_encoding(path, rdb.MountPointReparseBuffer.PrintName) | 199 | return rdb.MountPointReparseBuffer.PrintName |
208 | # Unsupported reparse point type | 200 | # Unsupported reparse point type |
209 | _raise_winerror( | 201 | _raise_winerror( |
210 | ERROR_NOT_SUPPORTED, | 202 | ERROR_NOT_SUPPORTED, |
211 | 'Error reading symbolic link \"%s\"'.format(path)) | 203 | 'Error reading symbolic link \"%s\"'.format(path)) |
212 | 204 | ||
213 | 205 | ||
214 | def _preserve_encoding(source, target): | ||
215 | """Ensures target is the same string type (i.e. unicode or str) as source.""" | ||
216 | |||
217 | if is_python3(): | ||
218 | return target | ||
219 | |||
220 | if isinstance(source, unicode): # noqa: F821 | ||
221 | return unicode(target) # noqa: F821 | ||
222 | return str(target) | ||
223 | |||
224 | |||
225 | def _raise_winerror(code, error_desc): | 206 | def _raise_winerror(code, error_desc): |
226 | win_error_desc = FormatError(code).strip() | 207 | win_error_desc = FormatError(code).strip() |
227 | error_desc = "%s: %s".format(error_desc, win_error_desc) | 208 | error_desc = "%s: %s".format(error_desc, win_error_desc) |
@@ -25,6 +25,7 @@ import sys | |||
25 | import tarfile | 25 | import tarfile |
26 | import tempfile | 26 | import tempfile |
27 | import time | 27 | import time |
28 | import urllib.parse | ||
28 | 29 | ||
29 | from color import Coloring | 30 | from color import Coloring |
30 | from git_command import GitCommand, git_require | 31 | from git_command import GitCommand, git_require |
@@ -39,16 +40,6 @@ from repo_trace import IsTrace, Trace | |||
39 | 40 | ||
40 | from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M, R_WORKTREE_M | 41 | from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M, R_WORKTREE_M |
41 | 42 | ||
42 | from pyversion import is_python3 | ||
43 | if is_python3(): | ||
44 | import urllib.parse | ||
45 | else: | ||
46 | import imp | ||
47 | import urlparse | ||
48 | urllib = imp.new_module('urllib') | ||
49 | urllib.parse = urlparse | ||
50 | input = raw_input # noqa: F821 | ||
51 | |||
52 | 43 | ||
53 | # Maximum sleep time allowed during retries. | 44 | # Maximum sleep time allowed during retries. |
54 | MAXIMUM_RETRY_SLEEP_SEC = 3600.0 | 45 | MAXIMUM_RETRY_SLEEP_SEC = 3600.0 |
diff --git a/pyversion.py b/pyversion.py deleted file mode 100644 index a0cbf777..00000000 --- a/pyversion.py +++ /dev/null | |||
@@ -1,19 +0,0 @@ | |||
1 | # Copyright (C) 2013 The Android Open Source Project | ||
2 | # | ||
3 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||
4 | # you may not use this file except in compliance with the License. | ||
5 | # You may obtain a copy of the License at | ||
6 | # | ||
7 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
8 | # | ||
9 | # Unless required by applicable law or agreed to in writing, software | ||
10 | # distributed under the License is distributed on an "AS IS" BASIS, | ||
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
12 | # See the License for the specific language governing permissions and | ||
13 | # limitations under the License. | ||
14 | |||
15 | import sys | ||
16 | |||
17 | |||
18 | def is_python3(): | ||
19 | return sys.version_info[0] == 3 | ||
diff --git a/subcmds/gitc_delete.py b/subcmds/gitc_delete.py index c6f02607..56e0eaba 100644 --- a/subcmds/gitc_delete.py +++ b/subcmds/gitc_delete.py | |||
@@ -17,10 +17,6 @@ import sys | |||
17 | from command import Command, GitcClientCommand | 17 | from command import Command, GitcClientCommand |
18 | import platform_utils | 18 | import platform_utils |
19 | 19 | ||
20 | from pyversion import is_python3 | ||
21 | if not is_python3(): | ||
22 | input = raw_input # noqa: F821 | ||
23 | |||
24 | 20 | ||
25 | class GitcDelete(Command, GitcClientCommand): | 21 | class GitcDelete(Command, GitcClientCommand): |
26 | common = True | 22 | common = True |
diff --git a/subcmds/init.py b/subcmds/init.py index e078fcbe..1bcf5463 100644 --- a/subcmds/init.py +++ b/subcmds/init.py | |||
@@ -17,15 +17,7 @@ import os | |||
17 | import platform | 17 | import platform |
18 | import re | 18 | import re |
19 | import sys | 19 | import sys |
20 | 20 | import urllib.parse | |
21 | from pyversion import is_python3 | ||
22 | if is_python3(): | ||
23 | import urllib.parse | ||
24 | else: | ||
25 | import imp | ||
26 | import urlparse | ||
27 | urllib = imp.new_module('urllib') | ||
28 | urllib.parse = urlparse | ||
29 | 21 | ||
30 | from color import Coloring | 22 | from color import Coloring |
31 | from command import InteractiveCommand, MirrorSafeCommand | 23 | from command import InteractiveCommand, MirrorSafeCommand |
diff --git a/subcmds/sync.py b/subcmds/sync.py index 1e1f2fc1..3482946d 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py | |||
@@ -12,6 +12,7 @@ | |||
12 | # See the License for the specific language governing permissions and | 12 | # See the License for the specific language governing permissions and |
13 | # limitations under the License. | 13 | # limitations under the License. |
14 | 14 | ||
15 | import http.cookiejar as cookielib | ||
15 | import json | 16 | import json |
16 | import netrc | 17 | import netrc |
17 | from optparse import SUPPRESS_HELP | 18 | from optparse import SUPPRESS_HELP |
@@ -22,26 +23,10 @@ import subprocess | |||
22 | import sys | 23 | import sys |
23 | import tempfile | 24 | import tempfile |
24 | import time | 25 | import time |
25 | 26 | import urllib.error | |
26 | from pyversion import is_python3 | 27 | import urllib.parse |
27 | if is_python3(): | 28 | import urllib.request |
28 | import http.cookiejar as cookielib | 29 | import xmlrpc.client |
29 | import urllib.error | ||
30 | import urllib.parse | ||
31 | import urllib.request | ||
32 | import xmlrpc.client | ||
33 | else: | ||
34 | import cookielib | ||
35 | import imp | ||
36 | import urllib2 | ||
37 | import urlparse | ||
38 | import xmlrpclib | ||
39 | urllib = imp.new_module('urllib') | ||
40 | urllib.error = urllib2 | ||
41 | urllib.parse = urlparse | ||
42 | urllib.request = urllib2 | ||
43 | xmlrpc = imp.new_module('xmlrpc') | ||
44 | xmlrpc.client = xmlrpclib | ||
45 | 30 | ||
46 | try: | 31 | try: |
47 | import threading as _threading | 32 | import threading as _threading |
diff --git a/subcmds/upload.py b/subcmds/upload.py index c189e65f..50dccc52 100644 --- a/subcmds/upload.py +++ b/subcmds/upload.py | |||
@@ -23,11 +23,6 @@ from git_command import GitCommand | |||
23 | from git_refs import R_HEADS | 23 | from git_refs import R_HEADS |
24 | from hooks import RepoHook | 24 | from hooks import RepoHook |
25 | 25 | ||
26 | from pyversion import is_python3 | ||
27 | if not is_python3(): | ||
28 | input = raw_input # noqa: F821 | ||
29 | else: | ||
30 | unicode = str | ||
31 | 26 | ||
32 | UNUSUAL_COMMIT_THRESHOLD = 5 | 27 | UNUSUAL_COMMIT_THRESHOLD = 5 |
33 | 28 | ||
diff --git a/tests/test_wrapper.py b/tests/test_wrapper.py index 5e2cfa57..d8713738 100644 --- a/tests/test_wrapper.py +++ b/tests/test_wrapper.py | |||
@@ -15,27 +15,20 @@ | |||
15 | """Unittests for the wrapper.py module.""" | 15 | """Unittests for the wrapper.py module.""" |
16 | 16 | ||
17 | import contextlib | 17 | import contextlib |
18 | from io import StringIO | ||
18 | import os | 19 | import os |
19 | import re | 20 | import re |
20 | import shutil | 21 | import shutil |
21 | import tempfile | 22 | import tempfile |
22 | import unittest | 23 | import unittest |
24 | from unittest import mock | ||
23 | 25 | ||
24 | import git_command | 26 | import git_command |
25 | import main | 27 | import main |
26 | import platform_utils | 28 | import platform_utils |
27 | from pyversion import is_python3 | ||
28 | import wrapper | 29 | import wrapper |
29 | 30 | ||
30 | 31 | ||
31 | if is_python3(): | ||
32 | from unittest import mock | ||
33 | from io import StringIO | ||
34 | else: | ||
35 | import mock | ||
36 | from StringIO import StringIO | ||
37 | |||
38 | |||
39 | @contextlib.contextmanager | 32 | @contextlib.contextmanager |
40 | def TemporaryDirectory(): | 33 | def TemporaryDirectory(): |
41 | """Create a new empty git checkout for testing.""" | 34 | """Create a new empty git checkout for testing.""" |
@@ -62,9 +55,6 @@ class RepoWrapperTestCase(unittest.TestCase): | |||
62 | wrapper._wrapper_module = None | 55 | wrapper._wrapper_module = None |
63 | self.wrapper = wrapper.Wrapper() | 56 | self.wrapper = wrapper.Wrapper() |
64 | 57 | ||
65 | if not is_python3(): | ||
66 | self.assertRegex = self.assertRegexpMatches | ||
67 | |||
68 | 58 | ||
69 | class RepoWrapperUnitTest(RepoWrapperTestCase): | 59 | class RepoWrapperUnitTest(RepoWrapperTestCase): |
70 | """Tests helper functions in the repo wrapper | 60 | """Tests helper functions in the repo wrapper |