isort: format codebase

Change-Id: I6f11d123b68fd077f558d3c21349c55c5f251019
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/383715
Reviewed-by: Gavin Mak <gavinmak@google.com>
Tested-by: Mike Frysinger <vapier@google.com>
Commit-Queue: Mike Frysinger <vapier@google.com>
This commit is contained in:
Mike Frysinger 2023-08-21 21:20:32 -04:00 committed by LUCI
parent 06ddc8c50a
commit 6447733eb2
52 changed files with 281 additions and 144 deletions

41
.isort.cfg Normal file
View File

@ -0,0 +1,41 @@
# Copyright 2023 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Config file for the isort python module.
# This is used to enforce import sorting standards.
#
# https://pycqa.github.io/isort/docs/configuration/options.html
[settings]
# Be compatible with `black` since it also matches what we want.
profile = black
line_length = 80
length_sort = false
force_single_line = true
lines_after_imports = 2
from_first = false
case_sensitive = false
force_sort_within_sections = true
order_by_type = false
# Ignore generated files.
extend_skip_glob = *_pb2.py
# Allow importing multiple classes on a single line from these modules.
# https://google.github.io/styleguide/pyguide#s2.2-imports
single_line_exclusions =
abc,
collections.abc,
typing,

View File

@ -17,6 +17,7 @@ import sys
import pager
COLORS = {
None: -1,
"normal": -1,

View File

@ -13,14 +13,14 @@
# limitations under the License.
import multiprocessing
import os
import optparse
import os
import re
from event_log import EventLog
from error import NoSuchProjectError
from error import InvalidProjectGroupsError
from error import NoSuchProjectError
from error import RepoExitError
from event_log import EventLog
import progress

View File

@ -14,8 +14,8 @@
import os
import re
import sys
import subprocess
import sys
import tempfile
from error import EditorError

View File

@ -15,6 +15,7 @@
import json
import multiprocessing
TASK_COMMAND = "command"
TASK_SYNC_NETWORK = "sync-network"
TASK_SYNC_LOCAL = "sync-local"

View File

@ -18,6 +18,7 @@ import subprocess
import sys
from urllib.parse import urlparse
from urllib.request import urlopen
from error import RepoExitError

View File

@ -14,17 +14,20 @@
import functools
import os
import sys
import subprocess
import sys
from typing import Any, Optional
from error import GitError
from error import RepoExitError
from git_refs import HEAD
import platform_utils
from repo_trace import REPO_TRACE, IsTrace, Trace
from repo_trace import IsTrace
from repo_trace import REPO_TRACE
from repo_trace import Trace
from wrapper import Wrapper
GIT = "git"
# NB: These do not need to be kept in sync with the repo launcher script.
# These may be much newer as it allows the repo launcher to roll between

View File

@ -26,11 +26,15 @@ from typing import Union
import urllib.error
import urllib.request
from error import GitError, UploadError
from error import GitError
from error import UploadError
from git_command import GitCommand
from git_refs import R_CHANGES
from git_refs import R_HEADS
from git_refs import R_TAGS
import platform_utils
from repo_trace import Trace
from git_command import GitCommand
from git_refs import R_CHANGES, R_HEADS, R_TAGS
# Prefix that is prepended to all the keys of SyncAnalysisState's data
# that is saved in the config.

View File

@ -13,8 +13,10 @@
# limitations under the License.
import os
from repo_trace import Trace
import platform_utils
from repo_trace import Trace
HEAD = "HEAD"
R_CHANGES = "refs/changes/"

View File

@ -22,17 +22,19 @@ Examples:
UpdateProjectsResult = superproject.UpdateProjectsRevisionId(projects)
"""
import hashlib
import functools
import hashlib
import os
import sys
import time
from typing import NamedTuple
from git_command import git_require, GitCommand
from git_command import git_require
from git_command import GitCommand
from git_config import RepoConfig
from git_refs import GitRefs
_SUPERPROJECT_GIT_NAME = "superproject.git"
_SUPERPROJECT_MANIFEST_NAME = "superproject_override.xml"

View File

@ -37,7 +37,8 @@ import sys
import tempfile
import threading
from git_command import GitCommand, RepoSourceVersion
from git_command import GitCommand
from git_command import RepoSourceVersion
class EventLog(object):

28
main.py
View File

@ -21,6 +21,7 @@ which takes care of execing this entry point.
"""
import getpass
import json
import netrc
import optparse
import os
@ -30,7 +31,7 @@ import sys
import textwrap
import time
import urllib.request
import json
try:
import kerberos
@ -38,31 +39,34 @@ except ImportError:
kerberos = None
from color import SetDefaultColoring
import event_log
from repo_trace import SetTrace, Trace, SetTraceToStderr
from git_command import user_agent
from git_config import RepoConfig
from git_trace2_event_log import EventLog
from command import InteractiveCommand
from command import MirrorSafeCommand
from subcmds.version import Version
from editor import Editor
from error import DownloadError
from error import GitcUnsupportedError
from error import InvalidProjectGroupsError
from error import ManifestInvalidRevisionError
from error import NoManifestException
from error import NoSuchProjectError
from error import RepoChangedException
from error import RepoError
from error import RepoExitError
from error import RepoUnhandledExceptionError
from error import RepoError
from error import SilentRepoExitError
from error import GitcUnsupportedError
import event_log
from git_command import user_agent
from git_config import RepoConfig
from git_trace2_event_log import EventLog
from manifest_xml import RepoClient
from pager import RunPager, TerminatePager
from wrapper import WrapperPath, Wrapper
from pager import RunPager
from pager import TerminatePager
from repo_trace import SetTrace
from repo_trace import SetTraceToStderr
from repo_trace import Trace
from subcmds import all_commands
from subcmds.version import Version
from wrapper import Wrapper
from wrapper import WrapperPath
# NB: These do not need to be kept in sync with the repo launcher script.

View File

@ -18,27 +18,25 @@ import os
import platform
import re
import sys
import xml.dom.minidom
import urllib.parse
import xml.dom.minidom
from error import ManifestInvalidPathError
from error import ManifestInvalidRevisionError
from error import ManifestParseError
from git_config import GitConfig
from git_refs import R_HEADS, HEAD
from git_refs import HEAD
from git_refs import R_HEADS
from git_superproject import Superproject
import platform_utils
from project import (
Annotation,
RemoteSpec,
Project,
RepoProject,
ManifestProject,
)
from error import (
ManifestParseError,
ManifestInvalidPathError,
ManifestInvalidRevisionError,
)
from project import Annotation
from project import ManifestProject
from project import Project
from project import RemoteSpec
from project import RepoProject
from wrapper import Wrapper
MANIFEST_FILE_NAME = "manifest.xml"
LOCAL_MANIFEST_NAME = "local_manifest.xml"
LOCAL_MANIFESTS_DIR_NAME = "local_manifests"

View File

@ -19,6 +19,7 @@ import sys
import platform_utils
active = False
pager_process = None
old_stdout = None

View File

@ -12,12 +12,28 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from ctypes import addressof
from ctypes import byref
from ctypes import c_buffer
from ctypes import c_ubyte
from ctypes import FormatError
from ctypes import get_last_error
from ctypes import Structure
from ctypes import Union
from ctypes import WinDLL
from ctypes import WinError
from ctypes.wintypes import BOOL
from ctypes.wintypes import BOOLEAN
from ctypes.wintypes import DWORD
from ctypes.wintypes import HANDLE
from ctypes.wintypes import LPCWSTR
from ctypes.wintypes import LPDWORD
from ctypes.wintypes import LPVOID
from ctypes.wintypes import ULONG
from ctypes.wintypes import USHORT
from ctypes.wintypes import WCHAR
import errno
from ctypes import WinDLL, get_last_error, FormatError, WinError, addressof
from ctypes import c_buffer, c_ubyte, Structure, Union, byref
from ctypes.wintypes import BOOL, BOOLEAN, LPCWSTR, DWORD, HANDLE
from ctypes.wintypes import WCHAR, USHORT, LPVOID, ULONG, LPDWORD
kernel32 = WinDLL("kernel32", use_last_error=True)

View File

@ -16,6 +16,7 @@ import os
import sys
import time
try:
import threading as _threading
except ImportError:
@ -23,6 +24,7 @@ except ImportError:
from repo_trace import IsTraceToStderr
_TTY = sys.stderr.isatty()
# This will erase all content in the current line (wherever the cursor is).

View File

@ -26,35 +26,39 @@ import sys
import tarfile
import tempfile
import time
from typing import NamedTuple, List
from typing import List, NamedTuple
import urllib.parse
from color import Coloring
from error import DownloadError
from error import GitError
from error import ManifestInvalidPathError
from error import ManifestInvalidRevisionError
from error import ManifestParseError
from error import NoManifestException
from error import RepoError
from error import UploadError
import fetch
from git_command import GitCommand, git_require
from git_config import (
GitConfig,
IsId,
GetSchemeFromUrl,
GetUrlCookieFile,
ID_RE,
)
from git_command import git_require
from git_command import GitCommand
from git_config import GetSchemeFromUrl
from git_config import GetUrlCookieFile
from git_config import GitConfig
from git_config import ID_RE
from git_config import IsId
from git_refs import GitRefs
from git_refs import HEAD
from git_refs import R_HEADS
from git_refs import R_M
from git_refs import R_PUB
from git_refs import R_TAGS
from git_refs import R_WORKTREE_M
import git_superproject
from git_trace2_event_log import EventLog
from error import (
GitError,
UploadError,
DownloadError,
RepoError,
)
from error import ManifestInvalidRevisionError, ManifestInvalidPathError
from error import NoManifestException, ManifestParseError
import platform_utils
import progress
from repo_trace import Trace
from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M, R_WORKTREE_M
class SyncNetworkHalfResult(NamedTuple):
"""Sync_NetworkHalf return value."""

View File

@ -22,4 +22,5 @@ import sys
import update_manpages
sys.exit(update_manpages.main(sys.argv[1:]))

View File

@ -17,17 +17,18 @@
Most code lives in this module so it can be unittested.
"""
from pathlib import Path
import argparse
import functools
import multiprocessing
import os
from pathlib import Path
import re
import shutil
import subprocess
import sys
import tempfile
TOPDIR = Path(__file__).resolve().parent.parent
MANDIR = TOPDIR.joinpath("man")

4
repo
View File

@ -254,11 +254,13 @@ import re
import shutil
import stat
if sys.version_info[0] == 3:
import urllib.request
import urllib.error
import urllib.request
else:
import imp
import urllib2
urllib = imp.new_module('urllib')
urllib.request = urllib2

View File

@ -19,6 +19,7 @@ import multiprocessing
from color import Coloring
SEPARATOR = "=" * 80

View File

@ -21,13 +21,14 @@ To also include trace outputs in stderr do `repo --trace_to_stderr ...`
"""
import contextlib
import sys
import os
import time
import sys
import tempfile
import time
import platform_utils
# Env var to implicitly turn on tracing.
REPO_TRACE = "REPO_TRACE"

View File

@ -18,6 +18,7 @@
import os
import subprocess
import sys
import pytest
@ -38,12 +39,20 @@ def run_flake8():
).returncode
def run_isort():
"""Returns the exit code from isort."""
return subprocess.run(
[sys.executable, "-m", "isort", "--check", ROOT_DIR], check=False
).returncode
def main(argv):
"""The main entry."""
checks = (
lambda: pytest.main(argv),
run_black,
run_flake8,
run_isort,
)
return 0 if all(not c() for c in checks) else 1

View File

@ -123,3 +123,8 @@ wheel: <
name: "infra/python/wheels/pycodestyle-py2_py3"
version: "version:2.10.0"
>
wheel: <
name: "infra/python/wheels/isort-py3"
version: "version:5.10.1"
>

View File

@ -16,6 +16,7 @@
"""Python packaging for repo."""
import os
import setuptools

View File

@ -14,6 +14,7 @@
import os
# A mapping of the subcommand name to the class that implements it.
all_commands = {}
all_modules = []

View File

@ -17,10 +17,12 @@ import functools
import itertools
import sys
from command import Command, DEFAULT_LOCAL_JOBS
from command import Command
from command import DEFAULT_LOCAL_JOBS
from error import RepoError
from error import RepoExitError
from git_command import git
from progress import Progress
from error import RepoError, RepoExitError
class AbandonError(RepoExitError):

View File

@ -16,7 +16,8 @@ import itertools
import sys
from color import Coloring
from command import Command, DEFAULT_LOCAL_JOBS
from command import Command
from command import DEFAULT_LOCAL_JOBS
class BranchColoring(Coloring):

View File

@ -14,12 +14,14 @@
import functools
import sys
from typing import NamedTuple
from command import Command, DEFAULT_LOCAL_JOBS
from command import Command
from command import DEFAULT_LOCAL_JOBS
from error import GitError
from error import RepoExitError
from progress import Progress
from project import Project
from error import GitError, RepoExitError
class CheckoutBranchResult(NamedTuple):

View File

@ -14,9 +14,11 @@
import re
import sys
from command import Command
from git_command import GitCommand
from error import GitError
from git_command import GitCommand
CHANGE_ID_RE = re.compile(r"^\s*Change-Id: I([0-9a-f]{40})\s*$")

View File

@ -15,7 +15,8 @@
import functools
import io
from command import DEFAULT_LOCAL_JOBS, PagedCommand
from command import DEFAULT_LOCAL_JOBS
from command import PagedCommand
class Diff(PagedCommand):

View File

@ -16,7 +16,10 @@ import re
import sys
from command import Command
from error import GitError, NoSuchProjectError, RepoExitError
from error import GitError
from error import NoSuchProjectError
from error import RepoExitError
CHANGE_RE = re.compile(r"^([1-9][0-9]*)(?:[/\.-]([1-9][0-9]*))?$")

View File

@ -16,21 +16,20 @@ import errno
import functools
import io
import multiprocessing
import re
import os
import re
import signal
import sys
import subprocess
import sys
from color import Coloring
from command import (
DEFAULT_LOCAL_JOBS,
Command,
MirrorSafeCommand,
WORKER_BATCH_SIZE,
)
from command import Command
from command import DEFAULT_LOCAL_JOBS
from command import MirrorSafeCommand
from command import WORKER_BATCH_SIZE
from error import ManifestInvalidRevisionError
_CAN_COLOR = [
"branch",
"diff",

View File

@ -14,12 +14,15 @@
import functools
import sys
from typing import NamedTuple
from color import Coloring
from command import DEFAULT_LOCAL_JOBS, PagedCommand
from error import GitError, InvalidArgumentsError, SilentRepoExitError
from command import DEFAULT_LOCAL_JOBS
from command import PagedCommand
from error import GitError
from error import InvalidArgumentsError
from error import SilentRepoExitError
from git_command import GitCommand
from typing import NamedTuple
from project import Project

View File

@ -16,14 +16,12 @@ import re
import sys
import textwrap
from subcmds import all_commands
from color import Coloring
from command import (
PagedCommand,
MirrorSafeCommand,
)
from wrapper import Wrapper
from command import MirrorSafeCommand
from command import PagedCommand
from error import RepoExitError
from subcmds import all_commands
from wrapper import Wrapper
class InvalidHelpCommand(RepoExitError):

View File

@ -14,9 +14,10 @@
import optparse
from command import PagedCommand
from color import Coloring
from git_refs import R_M, R_HEADS
from command import PagedCommand
from git_refs import R_HEADS
from git_refs import R_M
class _Coloring(Coloring):

View File

@ -16,11 +16,15 @@ import os
import sys
from color import Coloring
from command import InteractiveCommand, MirrorSafeCommand
from git_command import git_require, MIN_GIT_VERSION_SOFT, MIN_GIT_VERSION_HARD
from wrapper import Wrapper
from error import UpdateManifestError
from command import InteractiveCommand
from command import MirrorSafeCommand
from error import RepoUnhandledExceptionError
from error import UpdateManifestError
from git_command import git_require
from git_command import MIN_GIT_VERSION_HARD
from git_command import MIN_GIT_VERSION_SOFT
from wrapper import Wrapper
_REPO_ALLOW_SHALLOW = os.environ.get("REPO_ALLOW_SHALLOW")

View File

@ -14,7 +14,8 @@
import os
from command import Command, MirrorSafeCommand
from command import Command
from command import MirrorSafeCommand
class List(Command, MirrorSafeCommand):

View File

@ -15,7 +15,8 @@
import itertools
from color import Coloring
from command import DEFAULT_LOCAL_JOBS, PagedCommand
from command import DEFAULT_LOCAL_JOBS
from command import PagedCommand
class Prune(PagedCommand):

View File

@ -15,10 +15,11 @@
import optparse
import sys
from command import Command, MirrorSafeCommand
from subcmds.sync import _PostRepoUpgrade
from subcmds.sync import _PostRepoFetch
from command import Command
from command import MirrorSafeCommand
from error import RepoExitError
from subcmds.sync import _PostRepoFetch
from subcmds.sync import _PostRepoUpgrade
class SelfupdateError(RepoExitError):

View File

@ -14,14 +14,15 @@
import functools
import sys
from typing import NamedTuple
from command import Command, DEFAULT_LOCAL_JOBS
from git_config import IsImmutable
from command import Command
from command import DEFAULT_LOCAL_JOBS
from error import RepoExitError
from git_command import git
from git_config import IsImmutable
from progress import Progress
from project import Project
from typing import NamedTuple
from error import RepoExitError
class ExecuteOneResult(NamedTuple):

View File

@ -17,9 +17,9 @@ import glob
import io
import os
from command import DEFAULT_LOCAL_JOBS, PagedCommand
from color import Coloring
from command import DEFAULT_LOCAL_JOBS
from command import PagedCommand
import platform_utils

View File

@ -25,13 +25,14 @@ import socket
import sys
import tempfile
import time
from typing import NamedTuple, List, Set
from typing import List, NamedTuple, Set
import urllib.error
import urllib.parse
import urllib.request
import xml.parsers.expat
import xmlrpc.client
try:
import threading as _threading
except ImportError:
@ -49,34 +50,35 @@ except ImportError:
return (256, 256)
from command import Command
from command import DEFAULT_LOCAL_JOBS
from command import MirrorSafeCommand
from command import WORKER_BATCH_SIZE
from error import GitError
from error import RepoChangedException
from error import RepoExitError
from error import RepoUnhandledExceptionError
from error import SyncError
from error import UpdateManifestError
import event_log
from git_command import git_require
from git_config import GetUrlCookieFile
from git_refs import R_HEADS, HEAD
from git_refs import HEAD
from git_refs import R_HEADS
import git_superproject
import platform_utils
from progress import elapsed_str
from progress import jobs_str
from progress import Progress
from project import DeleteWorktreeError
from project import Project
from project import RemoteSpec
from command import (
Command,
DEFAULT_LOCAL_JOBS,
MirrorSafeCommand,
WORKER_BATCH_SIZE,
)
from error import (
RepoChangedException,
GitError,
RepoExitError,
SyncError,
UpdateManifestError,
RepoUnhandledExceptionError,
)
import platform_utils
from project import SyncBuffer, DeleteWorktreeError
from progress import Progress, elapsed_str, jobs_str
from project import SyncBuffer
from repo_trace import Trace
import ssh
from wrapper import Wrapper
_ONE_DAY_S = 24 * 60 * 60
# Env var to implicitly turn auto-gc back on. This was added to allow a user to

View File

@ -19,9 +19,12 @@ import re
import sys
from typing import List
from command import DEFAULT_LOCAL_JOBS, InteractiveCommand
from command import DEFAULT_LOCAL_JOBS
from command import InteractiveCommand
from editor import Editor
from error import UploadError, SilentRepoExitError, GitError
from error import GitError
from error import SilentRepoExitError
from error import UploadError
from git_command import GitCommand
from git_refs import R_HEADS
from hooks import RepoHook

View File

@ -15,8 +15,11 @@
import platform
import sys
from command import Command, MirrorSafeCommand
from git_command import git, RepoSourceVersion, user_agent
from command import Command
from command import MirrorSafeCommand
from git_command import git
from git_command import RepoSourceVersion
from git_command import user_agent
from git_refs import HEAD
from wrapper import Wrapper

View File

@ -18,13 +18,14 @@ import inspect
import pickle
import unittest
import error
import project
import git_command
import fetch
import command
import error
import fetch
import git_command
import project
from subcmds import all_modules
imports = all_modules + [
error,
project,

View File

@ -14,11 +14,12 @@
"""Unittests for the git_command.py module."""
import re
import os
import re
import subprocess
import unittest
try:
from unittest import mock
except ImportError:

View File

@ -21,10 +21,11 @@ import tempfile
import unittest
from unittest import mock
from test_manifest_xml import sort_attributes
import git_superproject
import git_trace2_event_log
import manifest_xml
from test_manifest_xml import sort_attributes
class SuperprojectTestCase(unittest.TestCase):

View File

@ -14,9 +14,10 @@
"""Unittests for the hooks.py module."""
import hooks
import unittest
import hooks
class RepoHookShebang(unittest.TestCase):
"""Check shebang parsing in RepoHook."""

View File

@ -22,9 +22,9 @@ import tempfile
import unittest
import error
import manifest_xml
import git_command
import git_config
import manifest_xml
import platform_utils
import project

View File

@ -16,16 +16,17 @@
import os
import shutil
import tempfile
import unittest
import time
import unittest
from unittest import mock
import pytest
import command
from subcmds import sync
from error import GitError
from error import RepoExitError
from project import SyncNetworkHalfResult
from error import GitError, RepoExitError
from subcmds import sync
@pytest.mark.parametrize(

View File

@ -17,8 +17,9 @@
import unittest
from unittest import mock
from error import GitError
from error import UploadError
from subcmds import upload
from error import UploadError, GitError
class UnexpectedError(Exception):