summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2019-06-13 02:24:21 -0400
committerMike Frysinger <vapier@google.com>2021-01-06 18:53:58 +0000
commitacf63b28928b33d1335dfed1af7e2d8fc6bb5fc4 (patch)
treee7b65524857d00cec6b36c989659afd1132d15ce
parent784ccfc040dc8efa1a64d3c7d4070b66beb15d08 (diff)
downloadgit-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.py20
-rw-r--r--hooks.py11
-rwxr-xr-xmain.py12
-rw-r--r--manifest_xml.py10
-rw-r--r--platform_utils.py8
-rw-r--r--platform_utils_win32.py27
-rw-r--r--project.py11
-rw-r--r--pyversion.py19
-rw-r--r--subcmds/gitc_delete.py4
-rw-r--r--subcmds/init.py10
-rw-r--r--subcmds/sync.py25
-rw-r--r--subcmds/upload.py5
-rw-r--r--tests/test_wrapper.py14
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
15import contextlib 15import contextlib
16import errno 16import errno
17from http.client import HTTPException
17import json 18import json
18import os 19import os
19import re 20import re
@@ -26,25 +27,12 @@ try:
26except ImportError: 27except ImportError:
27 import dummy_threading as _threading 28 import dummy_threading as _threading
28import time 29import time
29 30import urllib.error
30from pyversion import is_python3 31import urllib.request
31if is_python3():
32 import urllib.request
33 import urllib.error
34else:
35 import urllib2
36 import imp
37 urllib = imp.new_module('urllib')
38 urllib.request = urllib2
39 urllib.error = urllib2
40 32
41from error import GitError, UploadError 33from error import GitError, UploadError
42import platform_utils 34import platform_utils
43from repo_trace import Trace 35from repo_trace import Trace
44if is_python3():
45 from http.client import HTTPException
46else:
47 from httplib import HTTPException
48 36
49from git_command import GitCommand 37from git_command import GitCommand
50from git_command import ssh_sock 38from 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)
diff --git a/hooks.py b/hooks.py
index f805de6b..67c21a25 100644
--- a/hooks.py
+++ b/hooks.py
@@ -19,20 +19,11 @@ import re
19import subprocess 19import subprocess
20import sys 20import sys
21import traceback 21import traceback
22import urllib.parse
22 23
23from error import HookError 24from error import HookError
24from git_refs import HEAD 25from git_refs import HEAD
25 26
26from pyversion import is_python3
27if is_python3():
28 import urllib.parse
29else:
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
37class RepoHook(object): 28class 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.
diff --git a/main.py b/main.py
index cd0b8620..f638a677 100755
--- a/main.py
+++ b/main.py
@@ -28,15 +28,7 @@ import shlex
28import sys 28import sys
29import textwrap 29import textwrap
30import time 30import time
31 31import urllib.request
32from pyversion import is_python3
33if is_python3():
34 import urllib.request
35else:
36 import imp
37 import urllib2
38 urllib = imp.new_module('urllib')
39 urllib.request = urllib2
40 32
41try: 33try:
42 import kerberos 34 import kerberos
@@ -68,8 +60,6 @@ from wrapper import WrapperPath, Wrapper
68 60
69from subcmds import all_commands 61from subcmds import all_commands
70 62
71if 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
17import re 17import re
18import sys 18import sys
19import xml.dom.minidom 19import xml.dom.minidom
20 20import urllib.parse
21from pyversion import is_python3
22if is_python3():
23 import urllib.parse
24else:
25 import imp
26 import urlparse
27 urllib = imp.new_module('urllib')
28 urllib.parse = urlparse
29 21
30import gitc_utils 22import gitc_utils
31from git_config import GitConfig, IsId 23from 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 @@
15import errno 15import errno
16import os 16import os
17import platform 17import platform
18from queue import Queue
18import select 19import select
19import shutil 20import shutil
20import stat 21import stat
21
22from pyversion import is_python3
23if is_python3():
24 from queue import Queue
25else:
26 from Queue import Queue
27
28from threading import Thread 22from 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
15import errno 15import errno
16 16
17from pyversion import is_python3
18from ctypes import WinDLL, get_last_error, FormatError, WinError, addressof 17from ctypes import WinDLL, get_last_error, FormatError, WinError, addressof
19from ctypes import c_buffer 18from ctypes import c_buffer, c_ubyte, Structure, Union, byref
20from ctypes.wintypes import BOOL, BOOLEAN, LPCWSTR, DWORD, HANDLE 19from ctypes.wintypes import BOOL, BOOLEAN, LPCWSTR, DWORD, HANDLE
21from ctypes.wintypes import WCHAR, USHORT, LPVOID, ULONG 20from ctypes.wintypes import WCHAR, USHORT, LPVOID, ULONG, LPDWORD
22if is_python3():
23 from ctypes import c_ubyte, Structure, Union, byref
24 from ctypes.wintypes import LPDWORD
25else:
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
30kernel32 = WinDLL('kernel32', use_last_error=True) 22kernel32 = 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
214def _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
225def _raise_winerror(code, error_desc): 206def _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)
diff --git a/project.py b/project.py
index a9bca6db..6c6534d8 100644
--- a/project.py
+++ b/project.py
@@ -25,6 +25,7 @@ import sys
25import tarfile 25import tarfile
26import tempfile 26import tempfile
27import time 27import time
28import urllib.parse
28 29
29from color import Coloring 30from color import Coloring
30from git_command import GitCommand, git_require 31from git_command import GitCommand, git_require
@@ -39,16 +40,6 @@ from repo_trace import IsTrace, Trace
39 40
40from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M, R_WORKTREE_M 41from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M, R_WORKTREE_M
41 42
42from pyversion import is_python3
43if is_python3():
44 import urllib.parse
45else:
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.
54MAXIMUM_RETRY_SLEEP_SEC = 3600.0 45MAXIMUM_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
15import sys
16
17
18def 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
17from command import Command, GitcClientCommand 17from command import Command, GitcClientCommand
18import platform_utils 18import platform_utils
19 19
20from pyversion import is_python3
21if not is_python3():
22 input = raw_input # noqa: F821
23
24 20
25class GitcDelete(Command, GitcClientCommand): 21class 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
17import platform 17import platform
18import re 18import re
19import sys 19import sys
20 20import urllib.parse
21from pyversion import is_python3
22if is_python3():
23 import urllib.parse
24else:
25 import imp
26 import urlparse
27 urllib = imp.new_module('urllib')
28 urllib.parse = urlparse
29 21
30from color import Coloring 22from color import Coloring
31from command import InteractiveCommand, MirrorSafeCommand 23from 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
15import http.cookiejar as cookielib
15import json 16import json
16import netrc 17import netrc
17from optparse import SUPPRESS_HELP 18from optparse import SUPPRESS_HELP
@@ -22,26 +23,10 @@ import subprocess
22import sys 23import sys
23import tempfile 24import tempfile
24import time 25import time
25 26import urllib.error
26from pyversion import is_python3 27import urllib.parse
27if is_python3(): 28import urllib.request
28 import http.cookiejar as cookielib 29import xmlrpc.client
29 import urllib.error
30 import urllib.parse
31 import urllib.request
32 import xmlrpc.client
33else:
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
46try: 31try:
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
23from git_refs import R_HEADS 23from git_refs import R_HEADS
24from hooks import RepoHook 24from hooks import RepoHook
25 25
26from pyversion import is_python3
27if not is_python3():
28 input = raw_input # noqa: F821
29else:
30 unicode = str
31 26
32UNUSUAL_COMMIT_THRESHOLD = 5 27UNUSUAL_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
17import contextlib 17import contextlib
18from io import StringIO
18import os 19import os
19import re 20import re
20import shutil 21import shutil
21import tempfile 22import tempfile
22import unittest 23import unittest
24from unittest import mock
23 25
24import git_command 26import git_command
25import main 27import main
26import platform_utils 28import platform_utils
27from pyversion import is_python3
28import wrapper 29import wrapper
29 30
30 31
31if is_python3():
32 from unittest import mock
33 from io import StringIO
34else:
35 import mock
36 from StringIO import StringIO
37
38
39@contextlib.contextmanager 32@contextlib.contextmanager
40def TemporaryDirectory(): 33def 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
69class RepoWrapperUnitTest(RepoWrapperTestCase): 59class RepoWrapperUnitTest(RepoWrapperTestCase):
70 """Tests helper functions in the repo wrapper 60 """Tests helper functions in the repo wrapper