diff --git a/.flake8 b/.flake8 index fc0c765bd..0a219a4bb 100644 --- a/.flake8 +++ b/.flake8 @@ -10,32 +10,12 @@ per-file-ignores = git_status.py: IMR241, main.py: IMR241, manifest_xml.py: IMR241, - subcmds/abandon.py: IMR241, - subcmds/branches.py: IMR241, - subcmds/checkout.py: IMR241, - subcmds/cherry_pick.py: IMR241, - subcmds/diffmanifests.py: IMR241, - subcmds/diff.py: IMR241, - subcmds/download.py: IMR241, - subcmds/forall.py: IMR241, subcmds/gc.py: IMR241, - subcmds/grep.py: IMR241, - subcmds/help.py: IMR241, - subcmds/info.py: IMR241, - subcmds/init.py: IMR241, - subcmds/list.py: IMR241, - subcmds/manifest.py: IMR241, - subcmds/overview.py: IMR241, - subcmds/prune.py: IMR241, subcmds/rebase.py: IMR241, subcmds/selfupdate.py: IMR241, subcmds/smartsync.py: IMR241, - subcmds/stage.py: IMR241, - subcmds/start.py: IMR241, - subcmds/status.py: IMR241, subcmds/sync.py: IMR241, subcmds/upload.py: IMR241, - subcmds/version.py: IMR241, subcmds/wipe.py: IMR241, tests/e2e/test_failures.py: IMR241, tests/e2e/test_groups.py: IMR241, diff --git a/main.py b/main.py index e0ae8c5cf..2aa8ebe57 100755 --- a/main.py +++ b/main.py @@ -42,8 +42,7 @@ except ImportError: kerberos = None import color -from command import InteractiveCommand -from command import MirrorSafeCommand +import command import editor import error import event_log @@ -415,7 +414,10 @@ class _Repo: editor.Editor.globalConfig = cmd.client.globalConfig - if not isinstance(cmd, MirrorSafeCommand) and cmd.manifest.IsMirror: + if ( + not isinstance(cmd, command.MirrorSafeCommand) + and cmd.manifest.IsMirror + ): logger.error("fatal: '%s' requires a working directory", name) return 1 @@ -432,7 +434,9 @@ class _Repo: cmd.CommonValidateOptions(copts, cargs) git_trace2_event_log.verbose = copts.verbose - if gopts.pager is not False and not isinstance(cmd, InteractiveCommand): + if gopts.pager is not False and not isinstance( + cmd, command.InteractiveCommand + ): config = cmd.client.globalConfig if gopts.pager: use_pager = True diff --git a/subcmds/abandon.py b/subcmds/abandon.py index 74fdceb94..73162c676 100644 --- a/subcmds/abandon.py +++ b/subcmds/abandon.py @@ -16,8 +16,7 @@ import collections import functools import itertools -from command import Command -from command import DEFAULT_LOCAL_JOBS +import command import error import git_command import progress @@ -31,7 +30,7 @@ class AbandonError(error.RepoExitError): """Exit error when abandon command fails.""" -class Abandon(Command): +class Abandon(command.Command): COMMON = True helpSummary = "Permanently abandon a development branch" helpUsage = """ @@ -42,7 +41,7 @@ deleting it (and all its history) from your local repository. It is equivalent to "git branch -D ". """ - PARALLEL_JOBS = DEFAULT_LOCAL_JOBS + PARALLEL_JOBS = command.DEFAULT_LOCAL_JOBS def _Options(self, p): p.add_option( diff --git a/subcmds/branches.py b/subcmds/branches.py index bbc87b797..929e9b5d9 100644 --- a/subcmds/branches.py +++ b/subcmds/branches.py @@ -16,8 +16,7 @@ import itertools import sys import color -from command import Command -from command import DEFAULT_LOCAL_JOBS +import command class BranchColoring(color.Coloring): @@ -62,7 +61,7 @@ class BranchInfo: return self.published_equal == len(self.projects) -class Branches(Command): +class Branches(command.Command): COMMON = True helpSummary = "View current topic branches" helpUsage = """ @@ -96,7 +95,7 @@ the branch appears in, or does not appear in. If no project list is shown, then the branch appears in all projects. """ - PARALLEL_JOBS = DEFAULT_LOCAL_JOBS + PARALLEL_JOBS = command.DEFAULT_LOCAL_JOBS @classmethod def _ExpandProjectToBranches(cls, project_idx): diff --git a/subcmds/checkout.py b/subcmds/checkout.py index c2da8697c..218fcb11f 100644 --- a/subcmds/checkout.py +++ b/subcmds/checkout.py @@ -15,8 +15,7 @@ import functools from typing import NamedTuple -from command import Command -from command import DEFAULT_LOCAL_JOBS +import command import error import progress import repo_logging @@ -40,7 +39,7 @@ class MissingBranchError(error.RepoExitError): """Exception thrown when no project has specified branch.""" -class Checkout(Command): +class Checkout(command.Command): COMMON = True helpSummary = "Checkout a branch for development" helpUsage = """ @@ -54,7 +53,7 @@ The command is equivalent to: repo forall [...] -c git checkout """ - PARALLEL_JOBS = DEFAULT_LOCAL_JOBS + PARALLEL_JOBS = command.DEFAULT_LOCAL_JOBS def ValidateOptions(self, opt, args): if not args: diff --git a/subcmds/cherry_pick.py b/subcmds/cherry_pick.py index 9a1dfb941..9971a2773 100644 --- a/subcmds/cherry_pick.py +++ b/subcmds/cherry_pick.py @@ -16,7 +16,7 @@ import re import sys from typing import Tuple -from command import Command +import command import error import git_command import repo_logging @@ -26,7 +26,7 @@ CHANGE_ID_RE = re.compile(r"^\s*Change-Id: I([0-9a-f]{40})\s*$") logger = repo_logging.RepoLogger(__file__) -class CherryPick(Command): +class CherryPick(command.Command): COMMON = True helpSummary = "Cherry-pick a change." helpUsage = """ diff --git a/subcmds/diff.py b/subcmds/diff.py index fe1a51396..e5d5fab7e 100644 --- a/subcmds/diff.py +++ b/subcmds/diff.py @@ -15,11 +15,10 @@ import functools import io -from command import DEFAULT_LOCAL_JOBS -from command import PagedCommand +import command -class Diff(PagedCommand): +class Diff(command.PagedCommand): COMMON = True helpSummary = "Show changes between commit and working tree" helpUsage = """ @@ -29,7 +28,7 @@ The -u option causes '%prog' to generate diff output with file paths relative to the repository root, so the output can be applied to the Unix 'patch' command. """ - PARALLEL_JOBS = DEFAULT_LOCAL_JOBS + PARALLEL_JOBS = command.DEFAULT_LOCAL_JOBS def _Options(self, p): p.add_option( diff --git a/subcmds/diffmanifests.py b/subcmds/diffmanifests.py index 189c1697c..accf7f1ee 100644 --- a/subcmds/diffmanifests.py +++ b/subcmds/diffmanifests.py @@ -13,7 +13,7 @@ # limitations under the License. import color -from command import PagedCommand +import command import manifest_xml @@ -22,7 +22,7 @@ class _Coloring(color.Coloring): super().__init__(config, "status") -class Diffmanifests(PagedCommand): +class Diffmanifests(command.PagedCommand): """A command to see logs in projects represented by manifests This is used to see deeper differences between manifests. Where a simple diff --git a/subcmds/download.py b/subcmds/download.py index 50458efbd..aeb48261e 100644 --- a/subcmds/download.py +++ b/subcmds/download.py @@ -15,7 +15,7 @@ import re import sys -from command import Command +import command import error import repo_logging @@ -28,7 +28,7 @@ class DownloadCommandError(error.RepoExitError): """Error raised when download command fails.""" -class Download(Command): +class Download(command.Command): COMMON = True helpSummary = "Download and checkout a change" helpUsage = """ diff --git a/subcmds/forall.py b/subcmds/forall.py index a7913ae1e..135150c02 100644 --- a/subcmds/forall.py +++ b/subcmds/forall.py @@ -22,9 +22,7 @@ import subprocess import sys import color -from command import Command -from command import DEFAULT_LOCAL_JOBS -from command import MirrorSafeCommand +import command import repo_logging @@ -43,7 +41,7 @@ class ForallColoring(color.Coloring): self.project = self.printer("project", attr="bold") -class Forall(Command, MirrorSafeCommand): +class Forall(command.Command, command.MirrorSafeCommand): COMMON = False helpSummary = "Run a shell command in each project" helpUsage = """ @@ -136,7 +134,7 @@ terminal and are not redirected. If -e is used, when a command exits unsuccessfully, '%prog' will abort without iterating through the remaining projects. """ - PARALLEL_JOBS = DEFAULT_LOCAL_JOBS + PARALLEL_JOBS = command.DEFAULT_LOCAL_JOBS @staticmethod def _cmd_option(option, _opt_str, _value, parser): diff --git a/subcmds/gc.py b/subcmds/gc.py index 620e81a1e..e7df74540 100644 --- a/subcmds/gc.py +++ b/subcmds/gc.py @@ -15,14 +15,14 @@ import os from typing import List, Set -from command import Command +import command import git_command import platform_utils import progress from project import Project -class Gc(Command): +class Gc(command.Command): COMMON = True helpSummary = "Cleaning up internal repo and Git state." helpUsage = """ diff --git a/subcmds/grep.py b/subcmds/grep.py index f726cbe50..df6be2769 100644 --- a/subcmds/grep.py +++ b/subcmds/grep.py @@ -17,8 +17,7 @@ import sys from typing import NamedTuple import color -from command import DEFAULT_LOCAL_JOBS -from command import PagedCommand +import command import error import git_command import repo_logging @@ -50,7 +49,7 @@ class GrepCommandError(error.SilentRepoExitError): aggregate errors exit silently.""" -class Grep(PagedCommand): +class Grep(command.PagedCommand): COMMON = True helpSummary = "Print lines matching a pattern" helpUsage = """ @@ -84,7 +83,7 @@ contain a line that matches both expressions: repo grep --all-match -e NODE -e Unexpected """ - PARALLEL_JOBS = DEFAULT_LOCAL_JOBS + PARALLEL_JOBS = command.DEFAULT_LOCAL_JOBS @staticmethod def _carry_option(_option, opt_str, value, parser): diff --git a/subcmds/help.py b/subcmds/help.py index dfdce4eea..b7262bbc0 100644 --- a/subcmds/help.py +++ b/subcmds/help.py @@ -15,10 +15,10 @@ import re import sys import textwrap +from typing import Sequence import color -from command import MirrorSafeCommand -from command import PagedCommand +import command import error import subcmds import wrapper @@ -28,7 +28,7 @@ class InvalidHelpCommand(error.RepoExitError): """Invalid command passed into help.""" -class Help(PagedCommand, MirrorSafeCommand): +class Help(command.PagedCommand, command.MirrorSafeCommand): COMMON = False helpSummary = "Display detailed help on a command" helpUsage = """ @@ -38,17 +38,17 @@ class Help(PagedCommand, MirrorSafeCommand): Displays detailed usage information about a command. """ - def _PrintCommands(self, commandNames): - """Helper to display |commandNames| summaries.""" + def _PrintCommands(self, names: Sequence[str]) -> None: + """Helper to display |names| summaries.""" maxlen = 0 - for name in commandNames: + for name in names: maxlen = max(maxlen, len(name)) fmt = " %%-%ds %%s" % maxlen - for name in commandNames: - command = subcmds.all_commands[name]() + for name in names: + cmd = subcmds.all_commands[name]() try: - summary = command.helpSummary.strip() + summary = cmd.helpSummary.strip() except AttributeError: summary = "" print(fmt % (name, summary)) @@ -59,8 +59,8 @@ Displays detailed usage information about a command. def PrintAllCommandsBody(self): print("The complete list of recognized repo commands is:") - commandNames = sorted(subcmds.all_commands) - self._PrintCommands(commandNames) + names = sorted(subcmds.all_commands) + self._PrintCommands(names) print( "See 'repo help ' for more information on a " "specific command." @@ -74,10 +74,10 @@ Displays detailed usage information about a command. def PrintCommonCommandsBody(self): print("The most commonly used repo commands are:") - commandNames = sorted( + names = sorted( name for name, cmd in subcmds.all_commands.items() if cmd.COMMON ) - self._PrintCommands(commandNames) + self._PrintCommands(names) print( "See 'repo help ' for more information on a specific " diff --git a/subcmds/info.py b/subcmds/info.py index 0e0431727..bda4b3e99 100644 --- a/subcmds/info.py +++ b/subcmds/info.py @@ -21,8 +21,7 @@ import sys from typing import Any, Dict, List, NamedTuple, Optional, Tuple import color -from command import DEFAULT_LOCAL_JOBS -from command import PagedCommand +import command import git_refs @@ -51,9 +50,9 @@ class _Coloring(color.Coloring): super().__init__(config, "status") -class Info(PagedCommand): +class Info(command.PagedCommand): COMMON = True - PARALLEL_JOBS = DEFAULT_LOCAL_JOBS + PARALLEL_JOBS = command.DEFAULT_LOCAL_JOBS helpSummary = ( "Get info on the manifest branch, current branch or unmerged branches" ) diff --git a/subcmds/init.py b/subcmds/init.py index 617f03da2..b42355b56 100644 --- a/subcmds/init.py +++ b/subcmds/init.py @@ -16,8 +16,7 @@ import os import sys import color -from command import InteractiveCommand -from command import MirrorSafeCommand +import command import error import git_command import repo_logging @@ -29,7 +28,7 @@ logger = repo_logging.RepoLogger(__file__) _REPO_ALLOW_SHALLOW = os.environ.get("REPO_ALLOW_SHALLOW") -class Init(InteractiveCommand, MirrorSafeCommand): +class Init(command.InteractiveCommand, command.MirrorSafeCommand): COMMON = True RESPECT_SMART_SYNC_OVERRIDE = False MULTI_MANIFEST_SUPPORT = True diff --git a/subcmds/list.py b/subcmds/list.py index 3210ccded..44a5ba794 100644 --- a/subcmds/list.py +++ b/subcmds/list.py @@ -14,11 +14,10 @@ import os -from command import Command -from command import MirrorSafeCommand +import command -class List(Command, MirrorSafeCommand): +class List(command.Command, command.MirrorSafeCommand): COMMON = True helpSummary = "List projects and their associated directories" helpUsage = """ diff --git a/subcmds/manifest.py b/subcmds/manifest.py index 2c58f1b3e..daff5fe60 100644 --- a/subcmds/manifest.py +++ b/subcmds/manifest.py @@ -18,7 +18,7 @@ import optparse import os import sys -from command import PagedCommand +import command import repo_logging @@ -35,7 +35,7 @@ class OutputFormat(enum.Enum): JSON = enum.auto() -class Manifest(PagedCommand): +class Manifest(command.PagedCommand): COMMON = False helpSummary = "Manifest inspection utility" helpUsage = """ diff --git a/subcmds/overview.py b/subcmds/overview.py index e4b6a4072..0ff5ac3d8 100644 --- a/subcmds/overview.py +++ b/subcmds/overview.py @@ -15,10 +15,10 @@ import optparse import color -from command import PagedCommand +import command -class Overview(PagedCommand): +class Overview(command.PagedCommand): COMMON = True helpSummary = "Display overview of unmerged project branches" helpUsage = """ diff --git a/subcmds/prune.py b/subcmds/prune.py index 3bc0603fa..d059725a2 100644 --- a/subcmds/prune.py +++ b/subcmds/prune.py @@ -15,17 +15,16 @@ import itertools import color -from command import DEFAULT_LOCAL_JOBS -from command import PagedCommand +import command -class Prune(PagedCommand): +class Prune(command.PagedCommand): COMMON = True helpSummary = "Prune (delete) already merged topics" helpUsage = """ %prog [...] """ - PARALLEL_JOBS = DEFAULT_LOCAL_JOBS + PARALLEL_JOBS = command.DEFAULT_LOCAL_JOBS @classmethod def _ExecuteOne(cls, project_idx): diff --git a/subcmds/rebase.py b/subcmds/rebase.py index cbfaaaa8c..4b75550fb 100644 --- a/subcmds/rebase.py +++ b/subcmds/rebase.py @@ -15,7 +15,7 @@ import sys import color -from command import Command +import command import error import git_command from project import Project @@ -43,7 +43,7 @@ def _ResolveOntoManifest(project: Project) -> str: return project.revisionExpr -class Rebase(Command): +class Rebase(command.Command): COMMON = True helpSummary = "Rebase local branches on upstream branch" helpUsage = """ diff --git a/subcmds/selfupdate.py b/subcmds/selfupdate.py index 956ee85ad..5c819c529 100644 --- a/subcmds/selfupdate.py +++ b/subcmds/selfupdate.py @@ -14,8 +14,7 @@ import optparse -from command import Command -from command import MirrorSafeCommand +import command import error import repo_logging from subcmds.sync import _PostRepoFetch @@ -29,7 +28,7 @@ class SelfupdateError(error.RepoExitError): """Exit error for failed selfupdate command.""" -class Selfupdate(Command, MirrorSafeCommand): +class Selfupdate(command.Command, command.MirrorSafeCommand): COMMON = False helpSummary = "Update repo to the latest version" helpUsage = """ diff --git a/subcmds/stage.py b/subcmds/stage.py index 7d36e8570..3e2b7145d 100644 --- a/subcmds/stage.py +++ b/subcmds/stage.py @@ -15,7 +15,7 @@ import sys import color -from command import InteractiveCommand +import command import git_command import repo_logging @@ -31,7 +31,7 @@ class _ProjectList(color.Coloring): self.help = self.printer("help", fg="red", attr="bold") -class Stage(InteractiveCommand): +class Stage(command.InteractiveCommand): COMMON = True helpSummary = "Stage file(s) for commit" helpUsage = """ diff --git a/subcmds/start.py b/subcmds/start.py index ce2e31a8b..9b9800b6c 100644 --- a/subcmds/start.py +++ b/subcmds/start.py @@ -15,8 +15,7 @@ import functools from typing import NamedTuple -from command import Command -from command import DEFAULT_LOCAL_JOBS +import command import error import git_command import git_config @@ -36,7 +35,7 @@ class StartError(error.RepoExitError): """Exit error for failed start command.""" -class Start(Command): +class Start(command.Command): COMMON = True helpSummary = "Start a new branch for development" helpUsage = """ @@ -46,7 +45,7 @@ class Start(Command): '%prog' begins a new branch of development, starting from the revision specified in the manifest. """ - PARALLEL_JOBS = DEFAULT_LOCAL_JOBS + PARALLEL_JOBS = command.DEFAULT_LOCAL_JOBS def _Options(self, p): p.add_option( diff --git a/subcmds/status.py b/subcmds/status.py index 11deb61ab..526910c16 100644 --- a/subcmds/status.py +++ b/subcmds/status.py @@ -18,12 +18,11 @@ import io import os import color -from command import DEFAULT_LOCAL_JOBS -from command import PagedCommand +import command import platform_utils -class Status(PagedCommand): +class Status(command.PagedCommand): COMMON = True helpSummary = "Show the working tree status" helpUsage = """ @@ -82,7 +81,7 @@ the following meanings: d: deleted ( in index, not in work tree ) """ - PARALLEL_JOBS = DEFAULT_LOCAL_JOBS + PARALLEL_JOBS = command.DEFAULT_LOCAL_JOBS def _Options(self, p): p.add_option( diff --git a/subcmds/sync.py b/subcmds/sync.py index 7e4c1d8d5..4248a58d3 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -53,10 +53,7 @@ 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 +import command import error import event_log import git_command @@ -294,7 +291,7 @@ def _WithoutProjects( def _chunksize(projects: int, jobs: int) -> int: """Calculate chunk size for the given number of projects and jobs.""" - return min(max(1, projects // jobs), WORKER_BATCH_SIZE) + return min(max(1, projects // jobs), command.WORKER_BATCH_SIZE) class _FetchOneResult(NamedTuple): @@ -447,7 +444,7 @@ class TeeStringIO(io.StringIO): return ret -class Sync(Command, MirrorSafeCommand): +class Sync(command.Command, command.MirrorSafeCommand): COMMON = True RESPECT_SMART_SYNC_OVERRIDE = False MULTI_MANIFEST_SUPPORT = True @@ -592,7 +589,9 @@ later is required to fix a server side protocol bug. "--jobs or 1). Ignored unless --no-interleaved is set", ) - jobs_checkout_default = self._GetHelpForCpuJobCount(DEFAULT_LOCAL_JOBS) + jobs_checkout_default = self._GetHelpForCpuJobCount( + command.DEFAULT_LOCAL_JOBS + ) p.add_option( "--jobs-checkout", default=None, @@ -2389,7 +2388,7 @@ later is required to fix a server side protocol bug. if not opt.jobs_network: opt.jobs_network = 1 if not opt.jobs_checkout: - opt.jobs_checkout = DEFAULT_LOCAL_JOBS + opt.jobs_checkout = command.DEFAULT_LOCAL_JOBS opt.jobs = os.cpu_count() # Try to stay under user rlimit settings. diff --git a/subcmds/upload.py b/subcmds/upload.py index 55b073db5..f1866626e 100644 --- a/subcmds/upload.py +++ b/subcmds/upload.py @@ -19,8 +19,7 @@ import re import sys from typing import List -from command import DEFAULT_LOCAL_JOBS -from command import InteractiveCommand +import command import editor import error import git_refs @@ -104,7 +103,7 @@ def _SplitEmails(values): return result -class Upload(InteractiveCommand): +class Upload(command.InteractiveCommand): COMMON = True helpSummary = "Upload changes for code review" helpUsage = """ @@ -211,7 +210,7 @@ threshold to a different value. Gerrit Code Review: https://www.gerritcodereview.com/ """ - PARALLEL_JOBS = DEFAULT_LOCAL_JOBS + PARALLEL_JOBS = command.DEFAULT_LOCAL_JOBS def _Options(self, p): p.add_option( diff --git a/subcmds/version.py b/subcmds/version.py index db5eac689..c54ea31c6 100644 --- a/subcmds/version.py +++ b/subcmds/version.py @@ -16,14 +16,13 @@ import platform import sys from typing import Any, Tuple -from command import Command -from command import MirrorSafeCommand +import command import git_command import git_refs import wrapper -class Version(Command, MirrorSafeCommand): +class Version(command.Command, command.MirrorSafeCommand): wrapper_version = None wrapper_path = None diff --git a/subcmds/wipe.py b/subcmds/wipe.py index 2b5a9b22e..b55705d3a 100644 --- a/subcmds/wipe.py +++ b/subcmds/wipe.py @@ -16,7 +16,7 @@ import os import sys from typing import List -from command import Command +import command import error import platform_utils from project import DeleteWorktreeError @@ -26,7 +26,7 @@ class Error(error.RepoExitError): """Exit error when wipe command fails.""" -class Wipe(Command): +class Wipe(command.Command): """Delete projects from the worktree and .repo""" COMMON = True diff --git a/tests/test_subcmds_sync.py b/tests/test_subcmds_sync.py index 986420397..e007038c4 100644 --- a/tests/test_subcmds_sync.py +++ b/tests/test_subcmds_sync.py @@ -360,7 +360,7 @@ def test_jobs_checkout_help_default( expected_default: str, ) -> None: """Test checkout-jobs default help in interactive and manpage modes.""" - with mock.patch.object(sync, "DEFAULT_LOCAL_JOBS", 7), mock.patch.object( + with mock.patch.object(command, "DEFAULT_LOCAL_JOBS", 7), mock.patch.object( command, "GENERATE_MANPAGES", generate_manpages,