tweak stdlib imports to follow Google style guide

Google Python style guide says to import modules.
Clean up all our stdlib imports.  Leave the repo ones alone
for now as that's a much bigger shave.

Change-Id: Ida42fc2ae78b86e6b7a6cbc98f94ca04b295f8cc
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/383714
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Mike Frysinger <vapier@google.com>
Tested-by: Mike Frysinger <vapier@google.com>
This commit is contained in:
Mike Frysinger 2023-08-21 21:26:51 -04:00 committed by LUCI
parent 16109a66b7
commit 06ddc8c50a
8 changed files with 24 additions and 20 deletions

View File

@ -15,7 +15,7 @@
import contextlib import contextlib
import datetime import datetime
import errno import errno
from http.client import HTTPException import http.client
import json import json
import os import os
import re import re
@ -650,7 +650,7 @@ class Remote(object):
raise UploadError("%s: %s" % (self.review, str(e))) raise UploadError("%s: %s" % (self.review, str(e)))
except urllib.error.URLError as e: except urllib.error.URLError as e:
raise UploadError("%s: %s" % (self.review, str(e))) raise UploadError("%s: %s" % (self.review, str(e)))
except HTTPException as e: except http.client.HTTPException as e:
raise UploadError( raise UploadError(
"%s: %s" % (self.review, e.__class__.__name__) "%s: %s" % (self.review, e.__class__.__name__)
) )

View File

@ -18,8 +18,8 @@ Most code lives in this module so it can be unittested.
""" """
from pathlib import Path from pathlib import Path
from functools import partial
import argparse import argparse
import functools
import multiprocessing import multiprocessing
import os import os
import re import re
@ -112,7 +112,9 @@ def main(argv):
# Run all cmd in parallel, and wait for them to finish. # Run all cmd in parallel, and wait for them to finish.
with multiprocessing.Pool() as pool: with multiprocessing.Pool() as pool:
pool.map(partial(worker, cwd=tempdir, check=True), cmdlist) pool.map(
functools.partial(worker, cwd=tempdir, check=True), cmdlist
)
for tmp_path in MANDIR.glob("*.1.tmp"): for tmp_path in MANDIR.glob("*.1.tmp"):
path = tmp_path.parent / tmp_path.stem path = tmp_path.parent / tmp_path.stem

View File

@ -20,11 +20,11 @@ Temporary: Tracing is always on. Set `REPO_TRACE=0` to turn off.
To also include trace outputs in stderr do `repo --trace_to_stderr ...` To also include trace outputs in stderr do `repo --trace_to_stderr ...`
""" """
import contextlib
import sys import sys
import os import os
import time import time
import tempfile import tempfile
from contextlib import ContextDecorator
import platform_utils import platform_utils
@ -68,7 +68,7 @@ def _SetTraceFile(quiet):
_TRACE_FILE = _GetTraceFile(quiet) _TRACE_FILE = _GetTraceFile(quiet)
class Trace(ContextDecorator): class Trace(contextlib.ContextDecorator):
"""Used to capture and save git traces.""" """Used to capture and save git traces."""
def _time(self): def _time(self):

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from collections import defaultdict import collections
import functools import functools
import itertools import itertools
import sys import sys
@ -88,8 +88,8 @@ It is equivalent to "git branch -D <branchname>".
def Execute(self, opt, args): def Execute(self, opt, args):
nb = args[0].split() nb = args[0].split()
err = defaultdict(list) err = collections.defaultdict(list)
success = defaultdict(list) success = collections.defaultdict(list)
aggregate_errors = [] aggregate_errors = []
all_projects = self.GetProjects( all_projects = self.GetProjects(
args[1:], all_manifests=not opt.this_manifest_only args[1:], all_manifests=not opt.this_manifest_only

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from optparse import SUPPRESS_HELP import optparse
import sys import sys
from command import Command, MirrorSafeCommand from command import Command, MirrorSafeCommand
@ -52,7 +52,7 @@ need to be performed by an end-user.
"--repo-upgraded", "--repo-upgraded",
dest="repo_upgraded", dest="repo_upgraded",
action="store_true", action="store_true",
help=SUPPRESS_HELP, help=optparse.SUPPRESS_HELP,
) )
def Execute(self, opt, args): def Execute(self, opt, args):

View File

@ -19,7 +19,7 @@ import io
import json import json
import multiprocessing import multiprocessing
import netrc import netrc
from optparse import SUPPRESS_HELP import optparse
import os import os
import socket import socket
import sys import sys
@ -481,7 +481,7 @@ later is required to fix a server side protocol bug.
"--repo-upgraded", "--repo-upgraded",
dest="repo_upgraded", dest="repo_upgraded",
action="store_true", action="store_true",
help=SUPPRESS_HELP, help=optparse.SUPPRESS_HELP,
) )
def _GetBranch(self, manifest_project): def _GetBranch(self, manifest_project):

View File

@ -14,7 +14,7 @@
"""Unit test for repo_logging module.""" """Unit test for repo_logging module."""
import unittest import unittest
from unittest.mock import MagicMock from unittest import mock
from repo_logging import RepoLogger from repo_logging import RepoLogger
@ -30,7 +30,7 @@ class TestRepoLogger(unittest.TestCase):
nonlocal result nonlocal result
result = log.getMessage() result = log.getMessage()
mock_out = MagicMock() mock_out = mock.MagicMock()
mock_out.level = 0 mock_out.level = 0
mock_out.handle = mock_handler mock_out.handle = mock_handler
logger.addHandler(mock_out) logger.addHandler(mock_out)
@ -49,7 +49,7 @@ class TestRepoLogger(unittest.TestCase):
nonlocal result nonlocal result
result = log.getMessage() result = log.getMessage()
mock_out = MagicMock() mock_out = mock.MagicMock()
mock_out.level = 0 mock_out.level = 0
mock_out.handle = mock_handler mock_out.handle = mock_handler
logger.addHandler(mock_out) logger.addHandler(mock_out)
@ -88,7 +88,7 @@ class TestRepoLogger(unittest.TestCase):
nonlocal result nonlocal result
result.append(log.getMessage()) result.append(log.getMessage())
mock_out = MagicMock() mock_out = mock.MagicMock()
mock_out.level = 0 mock_out.level = 0
mock_out.handle = mock_handler mock_out.handle = mock_handler
logger.addHandler(mock_out) logger.addHandler(mock_out)

View File

@ -14,7 +14,7 @@
"""Unittests for the wrapper.py module.""" """Unittests for the wrapper.py module."""
from io import StringIO import io
import os import os
import re import re
import sys import sys
@ -47,8 +47,10 @@ class RepoWrapperUnitTest(RepoWrapperTestCase):
def test_version(self): def test_version(self):
"""Make sure _Version works.""" """Make sure _Version works."""
with self.assertRaises(SystemExit) as e: with self.assertRaises(SystemExit) as e:
with mock.patch("sys.stdout", new_callable=StringIO) as stdout: with mock.patch("sys.stdout", new_callable=io.StringIO) as stdout:
with mock.patch("sys.stderr", new_callable=StringIO) as stderr: with mock.patch(
"sys.stderr", new_callable=io.StringIO
) as stderr:
self.wrapper._Version() self.wrapper._Version()
self.assertEqual(0, e.exception.code) self.assertEqual(0, e.exception.code)
self.assertEqual("", stderr.getvalue()) self.assertEqual("", stderr.getvalue())