Skip to content

Commit

Permalink
cli: remove fix_subparsers (iterative#10229)
Browse files Browse the repository at this point in the history
It does not look like we need this.
  • Loading branch information
skshetry authored Jan 11, 2024
1 parent e3b0f19 commit d711ecd
Show file tree
Hide file tree
Showing 15 changed files with 25 additions and 50 deletions.
5 changes: 1 addition & 4 deletions dvc/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 0 additions & 12 deletions dvc/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions dvc/commands/artifacts.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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(
Expand Down
5 changes: 2 additions & 3 deletions dvc/commands/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -122,5 +123,3 @@ def add_parser(subparsers, parent_parser):
action="store_true",
)
cache_migrate_parser.set_defaults(func=CmdCacheMigrate)

fix_subparsers(cache_subparsers)
4 changes: 1 addition & 3 deletions dvc/commands/daemon.py
Original file line number Diff line number Diff line change
@@ -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__)
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions dvc/commands/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."
Expand Down
4 changes: 2 additions & 2 deletions dvc/commands/experiments/__init__.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions dvc/commands/git_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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",
Expand Down
5 changes: 2 additions & 3 deletions dvc/commands/metrics.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 2 additions & 3 deletions dvc/commands/params.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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."
Expand Down
5 changes: 2 additions & 3 deletions dvc/commands/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`."
)
Expand Down
4 changes: 2 additions & 2 deletions dvc/commands/queue/__init__.py
Original file line number Diff line number Diff line change
@@ -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 = [
Expand All @@ -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)
5 changes: 2 additions & 3 deletions dvc/commands/remote.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 2 additions & 3 deletions dvc/commands/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions dvc/commands/studio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 = (
Expand Down

0 comments on commit d711ecd

Please sign in to comment.