From d711ecda04debf61127f31bc46f88ddfd861d786 Mon Sep 17 00:00:00 2001 From: skshetry <18718008+skshetry@users.noreply.github.com> Date: Thu, 11 Jan 2024 15:54:44 +0545 Subject: [PATCH] cli: remove fix_subparsers (#10229) It does not look like we need this. --- dvc/cli/parser.py | 5 +---- dvc/cli/utils.py | 12 ------------ dvc/commands/artifacts.py | 4 ++-- dvc/commands/cache.py | 5 ++--- dvc/commands/daemon.py | 4 +--- dvc/commands/data.py | 4 ++-- dvc/commands/experiments/__init__.py | 4 ++-- dvc/commands/git_hook.py | 4 +--- dvc/commands/metrics.py | 5 ++--- dvc/commands/params.py | 5 ++--- dvc/commands/plots.py | 5 ++--- dvc/commands/queue/__init__.py | 4 ++-- dvc/commands/remote.py | 5 ++--- dvc/commands/stage.py | 5 ++--- dvc/commands/studio.py | 4 ++-- 15 files changed, 25 insertions(+), 50 deletions(-) diff --git a/dvc/cli/parser.py b/dvc/cli/parser.py index 915fb28633..90ef6aab0c 100644 --- a/dvc/cli/parser.py +++ b/dvc/cli/parser.py @@ -203,12 +203,9 @@ def get_main_parser(): metavar="command", dest="cmd", help="Use `dvc command --help` for command-specific help.", + required=True, ) - from .utils import fix_subparsers - - fix_subparsers(subparsers) - for cmd in COMMANDS: cmd.add_parser(subparsers, parent_parser) diff --git a/dvc/cli/utils.py b/dvc/cli/utils.py index 406d3ca922..e1a3cbf498 100644 --- a/dvc/cli/utils.py +++ b/dvc/cli/utils.py @@ -26,18 +26,6 @@ def __call__(self, parser, args, values, option_string=None): # noqa: ARG002 setattr(args, self.dest, d) -def fix_subparsers(subparsers): - """Workaround for bug in Python 3. See more info at: - https://bugs.python.org/issue16308 - https://github.com/iterative/dvc/issues/769 - - Args: - subparsers: subparsers to fix. - """ - subparsers.required = True - subparsers.dest = "cmd" - - def append_doc_link(help_message, path): from dvc.utils import format_link diff --git a/dvc/commands/artifacts.py b/dvc/commands/artifacts.py index 68cf1ea4fe..fc96c14eac 100644 --- a/dvc/commands/artifacts.py +++ b/dvc/commands/artifacts.py @@ -1,6 +1,6 @@ from dvc.cli import completion, formatter from dvc.cli.command import CmdBaseNoRepo -from dvc.cli.utils import DictAction, append_doc_link, fix_subparsers +from dvc.cli.utils import DictAction, append_doc_link from dvc.exceptions import DvcException from dvc.log import logger @@ -50,8 +50,8 @@ def add_parser(subparsers, parent_parser): artifacts_subparsers = artifacts_parser.add_subparsers( dest="cmd", help="Use `dvc artifacts CMD --help` to display command-specific help.", + required=True, ) - fix_subparsers(artifacts_subparsers) ARTIFACTS_GET_HELP = "Download an artifact from a DVC project." get_parser = artifacts_subparsers.add_parser( diff --git a/dvc/commands/cache.py b/dvc/commands/cache.py index b77449d108..9497d85164 100644 --- a/dvc/commands/cache.py +++ b/dvc/commands/cache.py @@ -3,7 +3,7 @@ from dvc.cli import completion, formatter from dvc.cli.command import CmdBase -from dvc.cli.utils import append_doc_link, fix_subparsers +from dvc.cli.utils import append_doc_link from dvc.commands.config import CmdConfig from dvc.ui import ui @@ -64,6 +64,7 @@ def add_parser(subparsers, parent_parser): cache_subparsers = cache_parser.add_subparsers( dest="cmd", help="Use `dvc cache CMD --help` for command-specific help.", + required=True, ) parent_cache_config_parser = argparse.ArgumentParser( @@ -122,5 +123,3 @@ def add_parser(subparsers, parent_parser): action="store_true", ) cache_migrate_parser.set_defaults(func=CmdCacheMigrate) - - fix_subparsers(cache_subparsers) diff --git a/dvc/commands/daemon.py b/dvc/commands/daemon.py index 9875d61888..c9ed065bf1 100644 --- a/dvc/commands/daemon.py +++ b/dvc/commands/daemon.py @@ -1,6 +1,5 @@ from dvc.cli import completion from dvc.cli.command import CmdBaseNoRepo -from dvc.cli.utils import fix_subparsers from dvc.log import logger logger = logger.getChild(__name__) @@ -53,10 +52,9 @@ def add_parser(subparsers, parent_parser): daemon_subparsers = daemon_parser.add_subparsers( dest="cmd", help="Use `dvc daemon CMD --help` for command-specific help.", + required=True, ) - fix_subparsers(daemon_subparsers) - DAEMON_UPDATER_HELP = "Fetch latest available version." daemon_updater_parser = daemon_subparsers.add_parser( "updater", diff --git a/dvc/commands/data.py b/dvc/commands/data.py index a77cf0eca6..82976d5274 100644 --- a/dvc/commands/data.py +++ b/dvc/commands/data.py @@ -4,7 +4,7 @@ from dvc.cli import formatter from dvc.cli.command import CmdBase -from dvc.cli.utils import append_doc_link, fix_subparsers +from dvc.cli.utils import append_doc_link from dvc.log import logger from dvc.ui import ui from dvc.utils import colorize @@ -134,8 +134,8 @@ def add_parser(subparsers, parent_parser): data_subparsers = data_parser.add_subparsers( dest="cmd", help="Use `dvc data CMD --help` to display command-specific help.", + required=True, ) - fix_subparsers(data_subparsers) DATA_STATUS_HELP = ( "Show changes between the last git commit, the dvcfiles and the workspace." diff --git a/dvc/commands/experiments/__init__.py b/dvc/commands/experiments/__init__.py index b2417d1d45..6b29bfacb5 100644 --- a/dvc/commands/experiments/__init__.py +++ b/dvc/commands/experiments/__init__.py @@ -1,5 +1,5 @@ from dvc.cli import formatter -from dvc.cli.utils import append_doc_link, fix_subparsers, hide_subparsers_from_help +from dvc.cli.utils import append_doc_link, hide_subparsers_from_help from dvc.commands.experiments import ( apply, branch, @@ -50,9 +50,9 @@ def add_parser(subparsers, parent_parser): experiments_subparsers = experiments_parser.add_subparsers( dest="cmd", help="Use `dvc experiments CMD --help` to display command-specific help.", + required=True, ) - fix_subparsers(experiments_subparsers) for cmd in SUB_COMMANDS: cmd.add_parser(experiments_subparsers, parent_parser) hide_subparsers_from_help(experiments_subparsers) diff --git a/dvc/commands/git_hook.py b/dvc/commands/git_hook.py index 838979e02a..2f0b7813a4 100644 --- a/dvc/commands/git_hook.py +++ b/dvc/commands/git_hook.py @@ -2,7 +2,6 @@ from dvc.cli import formatter from dvc.cli.command import CmdBaseNoRepo -from dvc.cli.utils import fix_subparsers from dvc.exceptions import NotDvcRepoError from dvc.log import logger @@ -95,10 +94,9 @@ def add_parser(subparsers, parent_parser): git_hook_subparsers = git_hook_parser.add_subparsers( dest="cmd", help="Use `dvc daemon CMD --help` for command-specific help.", + required=True, ) - fix_subparsers(git_hook_subparsers) - PRE_COMMIT_HELP = "Run pre-commit GIT hook." pre_commit_parser = git_hook_subparsers.add_parser( "pre-commit", diff --git a/dvc/commands/metrics.py b/dvc/commands/metrics.py index b472115b91..4eb56b99dc 100644 --- a/dvc/commands/metrics.py +++ b/dvc/commands/metrics.py @@ -1,6 +1,6 @@ from dvc.cli import completion, formatter from dvc.cli.command import CmdBase -from dvc.cli.utils import append_doc_link, fix_subparsers +from dvc.cli.utils import append_doc_link from dvc.log import logger from dvc.ui import ui from dvc.utils.serialize import encode_exception @@ -111,10 +111,9 @@ def add_parser(subparsers, parent_parser): metrics_subparsers = metrics_parser.add_subparsers( dest="cmd", help="Use `dvc metrics CMD --help` to display command-specific help.", + required=True, ) - fix_subparsers(metrics_subparsers) - METRICS_SHOW_HELP = "Print metrics, with optional formatting." metrics_show_parser = metrics_subparsers.add_parser( "show", diff --git a/dvc/commands/params.py b/dvc/commands/params.py index ede02b94bf..349cd1549e 100644 --- a/dvc/commands/params.py +++ b/dvc/commands/params.py @@ -1,6 +1,6 @@ from dvc.cli import completion, formatter from dvc.cli.command import CmdBase -from dvc.cli.utils import append_doc_link, fix_subparsers +from dvc.cli.utils import append_doc_link from dvc.log import logger from dvc.ui import ui @@ -65,10 +65,9 @@ def add_parser(subparsers, parent_parser): params_subparsers = params_parser.add_subparsers( dest="cmd", help="Use `dvc params CMD --help` to display command-specific help.", + required=True, ) - fix_subparsers(params_subparsers) - PARAMS_DIFF_HELP = ( "Show changes in params between commits in the DVC repository, or " "between a commit and the workspace." diff --git a/dvc/commands/plots.py b/dvc/commands/plots.py index 4fe70f8907..596c227238 100644 --- a/dvc/commands/plots.py +++ b/dvc/commands/plots.py @@ -6,7 +6,7 @@ from dvc.cli import completion, formatter from dvc.cli.command import CmdBase -from dvc.cli.utils import append_doc_link, fix_subparsers +from dvc.cli.utils import append_doc_link from dvc.exceptions import DvcException from dvc.log import logger from dvc.ui import ui @@ -228,10 +228,9 @@ def add_parser(subparsers, parent_parser): plots_subparsers = plots_parser.add_subparsers( dest="cmd", help="Use `dvc plots CMD --help` to display command-specific help.", + required=True, ) - fix_subparsers(plots_subparsers) - SHOW_HELP = ( "Generate plots from target files or from `plots` definitions in `dvc.yaml`." ) diff --git a/dvc/commands/queue/__init__.py b/dvc/commands/queue/__init__.py index e3315a0908..7347640d72 100644 --- a/dvc/commands/queue/__init__.py +++ b/dvc/commands/queue/__init__.py @@ -1,5 +1,5 @@ from dvc.cli import formatter -from dvc.cli.utils import append_doc_link, fix_subparsers +from dvc.cli.utils import append_doc_link from dvc.commands.queue import kill, logs, remove, start, status, stop SUB_COMMANDS = [ @@ -26,8 +26,8 @@ def add_parser(subparsers, parent_parser): queue_subparsers = queue_parser.add_subparsers( dest="cmd", help="Use `dvc queue CMD --help` to display command-specific help.", + required=True, ) - fix_subparsers(queue_subparsers) for cmd in SUB_COMMANDS: cmd.add_parser(queue_subparsers, parent_parser) diff --git a/dvc/commands/remote.py b/dvc/commands/remote.py index 12967c0019..4b6921dd75 100644 --- a/dvc/commands/remote.py +++ b/dvc/commands/remote.py @@ -1,5 +1,5 @@ from dvc.cli import formatter -from dvc.cli.utils import append_doc_link, fix_subparsers +from dvc.cli.utils import append_doc_link from dvc.commands.config import CmdConfig from dvc.ui import ui from dvc.utils import format_link @@ -160,10 +160,9 @@ def add_parser(subparsers, parent_parser): remote_subparsers = remote_parser.add_subparsers( dest="cmd", help="Use `dvc remote CMD --help` for command-specific help.", + required=True, ) - fix_subparsers(remote_subparsers) - REMOTE_ADD_HELP = "Add a new data remote." remote_add_parser = remote_subparsers.add_parser( "add", diff --git a/dvc/commands/stage.py b/dvc/commands/stage.py index 46b86aaaf5..f6c2a8bd08 100644 --- a/dvc/commands/stage.py +++ b/dvc/commands/stage.py @@ -6,7 +6,7 @@ from dvc.cli import completion, formatter from dvc.cli.command import CmdBase -from dvc.cli.utils import append_doc_link, fix_subparsers +from dvc.cli.utils import append_doc_link from dvc.log import logger from dvc.utils.cli_parse import parse_params from dvc.utils.humanize import truncate_text @@ -290,10 +290,9 @@ def add_parser(subparsers, parent_parser): stage_subparsers = stage_parser.add_subparsers( dest="cmd", help="Use `dvc stage CMD --help` to display command-specific help.", + required=True, ) - fix_subparsers(stage_subparsers) - STAGE_ADD_HELP = "Create stage" stage_add_parser = stage_subparsers.add_parser( "add", diff --git a/dvc/commands/studio.py b/dvc/commands/studio.py index 1239cf57d4..30914d8f40 100644 --- a/dvc/commands/studio.py +++ b/dvc/commands/studio.py @@ -3,7 +3,7 @@ from funcy import get_in from dvc.cli import formatter -from dvc.cli.utils import append_doc_link, fix_subparsers +from dvc.cli.utils import append_doc_link from dvc.commands.config import CmdConfig from dvc.log import logger @@ -97,8 +97,8 @@ def add_parser(subparsers, parent_parser): studio_subparser = studio_parser.add_subparsers( dest="cmd", help="Use `DVC studio CMD --help` to display command-specific help.", + required=True, ) - fix_subparsers(studio_subparser) STUDIO_LOGIN_HELP = "Authenticate DVC with Studio host" STUDIO_LOGIN_DESCRIPTION = (