Skip to content

Commit d711ecd

Browse files
authored
cli: remove fix_subparsers (#10229)
It does not look like we need this.
1 parent e3b0f19 commit d711ecd

File tree

15 files changed

+25
-50
lines changed

15 files changed

+25
-50
lines changed

dvc/cli/parser.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,9 @@ def get_main_parser():
203203
metavar="command",
204204
dest="cmd",
205205
help="Use `dvc command --help` for command-specific help.",
206+
required=True,
206207
)
207208

208-
from .utils import fix_subparsers
209-
210-
fix_subparsers(subparsers)
211-
212209
for cmd in COMMANDS:
213210
cmd.add_parser(subparsers, parent_parser)
214211

dvc/cli/utils.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,6 @@ def __call__(self, parser, args, values, option_string=None): # noqa: ARG002
2626
setattr(args, self.dest, d)
2727

2828

29-
def fix_subparsers(subparsers):
30-
"""Workaround for bug in Python 3. See more info at:
31-
https://bugs.python.org/issue16308
32-
https://github.com/iterative/dvc/issues/769
33-
34-
Args:
35-
subparsers: subparsers to fix.
36-
"""
37-
subparsers.required = True
38-
subparsers.dest = "cmd"
39-
40-
4129
def append_doc_link(help_message, path):
4230
from dvc.utils import format_link
4331

dvc/commands/artifacts.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from dvc.cli import completion, formatter
22
from dvc.cli.command import CmdBaseNoRepo
3-
from dvc.cli.utils import DictAction, append_doc_link, fix_subparsers
3+
from dvc.cli.utils import DictAction, append_doc_link
44
from dvc.exceptions import DvcException
55
from dvc.log import logger
66

@@ -50,8 +50,8 @@ def add_parser(subparsers, parent_parser):
5050
artifacts_subparsers = artifacts_parser.add_subparsers(
5151
dest="cmd",
5252
help="Use `dvc artifacts CMD --help` to display command-specific help.",
53+
required=True,
5354
)
54-
fix_subparsers(artifacts_subparsers)
5555

5656
ARTIFACTS_GET_HELP = "Download an artifact from a DVC project."
5757
get_parser = artifacts_subparsers.add_parser(

dvc/commands/cache.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from dvc.cli import completion, formatter
55
from dvc.cli.command import CmdBase
6-
from dvc.cli.utils import append_doc_link, fix_subparsers
6+
from dvc.cli.utils import append_doc_link
77
from dvc.commands.config import CmdConfig
88
from dvc.ui import ui
99

@@ -64,6 +64,7 @@ def add_parser(subparsers, parent_parser):
6464
cache_subparsers = cache_parser.add_subparsers(
6565
dest="cmd",
6666
help="Use `dvc cache CMD --help` for command-specific help.",
67+
required=True,
6768
)
6869

6970
parent_cache_config_parser = argparse.ArgumentParser(
@@ -122,5 +123,3 @@ def add_parser(subparsers, parent_parser):
122123
action="store_true",
123124
)
124125
cache_migrate_parser.set_defaults(func=CmdCacheMigrate)
125-
126-
fix_subparsers(cache_subparsers)

dvc/commands/daemon.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from dvc.cli import completion
22
from dvc.cli.command import CmdBaseNoRepo
3-
from dvc.cli.utils import fix_subparsers
43
from dvc.log import logger
54

65
logger = logger.getChild(__name__)
@@ -53,10 +52,9 @@ def add_parser(subparsers, parent_parser):
5352
daemon_subparsers = daemon_parser.add_subparsers(
5453
dest="cmd",
5554
help="Use `dvc daemon CMD --help` for command-specific help.",
55+
required=True,
5656
)
5757

58-
fix_subparsers(daemon_subparsers)
59-
6058
DAEMON_UPDATER_HELP = "Fetch latest available version."
6159
daemon_updater_parser = daemon_subparsers.add_parser(
6260
"updater",

dvc/commands/data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from dvc.cli import formatter
66
from dvc.cli.command import CmdBase
7-
from dvc.cli.utils import append_doc_link, fix_subparsers
7+
from dvc.cli.utils import append_doc_link
88
from dvc.log import logger
99
from dvc.ui import ui
1010
from dvc.utils import colorize
@@ -134,8 +134,8 @@ def add_parser(subparsers, parent_parser):
134134
data_subparsers = data_parser.add_subparsers(
135135
dest="cmd",
136136
help="Use `dvc data CMD --help` to display command-specific help.",
137+
required=True,
137138
)
138-
fix_subparsers(data_subparsers)
139139

140140
DATA_STATUS_HELP = (
141141
"Show changes between the last git commit, the dvcfiles and the workspace."

dvc/commands/experiments/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from dvc.cli import formatter
2-
from dvc.cli.utils import append_doc_link, fix_subparsers, hide_subparsers_from_help
2+
from dvc.cli.utils import append_doc_link, hide_subparsers_from_help
33
from dvc.commands.experiments import (
44
apply,
55
branch,
@@ -50,9 +50,9 @@ def add_parser(subparsers, parent_parser):
5050
experiments_subparsers = experiments_parser.add_subparsers(
5151
dest="cmd",
5252
help="Use `dvc experiments CMD --help` to display command-specific help.",
53+
required=True,
5354
)
5455

55-
fix_subparsers(experiments_subparsers)
5656
for cmd in SUB_COMMANDS:
5757
cmd.add_parser(experiments_subparsers, parent_parser)
5858
hide_subparsers_from_help(experiments_subparsers)

dvc/commands/git_hook.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from dvc.cli import formatter
44
from dvc.cli.command import CmdBaseNoRepo
5-
from dvc.cli.utils import fix_subparsers
65
from dvc.exceptions import NotDvcRepoError
76
from dvc.log import logger
87

@@ -95,10 +94,9 @@ def add_parser(subparsers, parent_parser):
9594
git_hook_subparsers = git_hook_parser.add_subparsers(
9695
dest="cmd",
9796
help="Use `dvc daemon CMD --help` for command-specific help.",
97+
required=True,
9898
)
9999

100-
fix_subparsers(git_hook_subparsers)
101-
102100
PRE_COMMIT_HELP = "Run pre-commit GIT hook."
103101
pre_commit_parser = git_hook_subparsers.add_parser(
104102
"pre-commit",

dvc/commands/metrics.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from dvc.cli import completion, formatter
22
from dvc.cli.command import CmdBase
3-
from dvc.cli.utils import append_doc_link, fix_subparsers
3+
from dvc.cli.utils import append_doc_link
44
from dvc.log import logger
55
from dvc.ui import ui
66
from dvc.utils.serialize import encode_exception
@@ -111,10 +111,9 @@ def add_parser(subparsers, parent_parser):
111111
metrics_subparsers = metrics_parser.add_subparsers(
112112
dest="cmd",
113113
help="Use `dvc metrics CMD --help` to display command-specific help.",
114+
required=True,
114115
)
115116

116-
fix_subparsers(metrics_subparsers)
117-
118117
METRICS_SHOW_HELP = "Print metrics, with optional formatting."
119118
metrics_show_parser = metrics_subparsers.add_parser(
120119
"show",

dvc/commands/params.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from dvc.cli import completion, formatter
22
from dvc.cli.command import CmdBase
3-
from dvc.cli.utils import append_doc_link, fix_subparsers
3+
from dvc.cli.utils import append_doc_link
44
from dvc.log import logger
55
from dvc.ui import ui
66

@@ -65,10 +65,9 @@ def add_parser(subparsers, parent_parser):
6565
params_subparsers = params_parser.add_subparsers(
6666
dest="cmd",
6767
help="Use `dvc params CMD --help` to display command-specific help.",
68+
required=True,
6869
)
6970

70-
fix_subparsers(params_subparsers)
71-
7271
PARAMS_DIFF_HELP = (
7372
"Show changes in params between commits in the DVC repository, or "
7473
"between a commit and the workspace."

dvc/commands/plots.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from dvc.cli import completion, formatter
88
from dvc.cli.command import CmdBase
9-
from dvc.cli.utils import append_doc_link, fix_subparsers
9+
from dvc.cli.utils import append_doc_link
1010
from dvc.exceptions import DvcException
1111
from dvc.log import logger
1212
from dvc.ui import ui
@@ -228,10 +228,9 @@ def add_parser(subparsers, parent_parser):
228228
plots_subparsers = plots_parser.add_subparsers(
229229
dest="cmd",
230230
help="Use `dvc plots CMD --help` to display command-specific help.",
231+
required=True,
231232
)
232233

233-
fix_subparsers(plots_subparsers)
234-
235234
SHOW_HELP = (
236235
"Generate plots from target files or from `plots` definitions in `dvc.yaml`."
237236
)

dvc/commands/queue/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from dvc.cli import formatter
2-
from dvc.cli.utils import append_doc_link, fix_subparsers
2+
from dvc.cli.utils import append_doc_link
33
from dvc.commands.queue import kill, logs, remove, start, status, stop
44

55
SUB_COMMANDS = [
@@ -26,8 +26,8 @@ def add_parser(subparsers, parent_parser):
2626
queue_subparsers = queue_parser.add_subparsers(
2727
dest="cmd",
2828
help="Use `dvc queue CMD --help` to display command-specific help.",
29+
required=True,
2930
)
3031

31-
fix_subparsers(queue_subparsers)
3232
for cmd in SUB_COMMANDS:
3333
cmd.add_parser(queue_subparsers, parent_parser)

dvc/commands/remote.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from dvc.cli import formatter
2-
from dvc.cli.utils import append_doc_link, fix_subparsers
2+
from dvc.cli.utils import append_doc_link
33
from dvc.commands.config import CmdConfig
44
from dvc.ui import ui
55
from dvc.utils import format_link
@@ -160,10 +160,9 @@ def add_parser(subparsers, parent_parser):
160160
remote_subparsers = remote_parser.add_subparsers(
161161
dest="cmd",
162162
help="Use `dvc remote CMD --help` for command-specific help.",
163+
required=True,
163164
)
164165

165-
fix_subparsers(remote_subparsers)
166-
167166
REMOTE_ADD_HELP = "Add a new data remote."
168167
remote_add_parser = remote_subparsers.add_parser(
169168
"add",

dvc/commands/stage.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from dvc.cli import completion, formatter
88
from dvc.cli.command import CmdBase
9-
from dvc.cli.utils import append_doc_link, fix_subparsers
9+
from dvc.cli.utils import append_doc_link
1010
from dvc.log import logger
1111
from dvc.utils.cli_parse import parse_params
1212
from dvc.utils.humanize import truncate_text
@@ -290,10 +290,9 @@ def add_parser(subparsers, parent_parser):
290290
stage_subparsers = stage_parser.add_subparsers(
291291
dest="cmd",
292292
help="Use `dvc stage CMD --help` to display command-specific help.",
293+
required=True,
293294
)
294295

295-
fix_subparsers(stage_subparsers)
296-
297296
STAGE_ADD_HELP = "Create stage"
298297
stage_add_parser = stage_subparsers.add_parser(
299298
"add",

dvc/commands/studio.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from funcy import get_in
44

55
from dvc.cli import formatter
6-
from dvc.cli.utils import append_doc_link, fix_subparsers
6+
from dvc.cli.utils import append_doc_link
77
from dvc.commands.config import CmdConfig
88
from dvc.log import logger
99

@@ -97,8 +97,8 @@ def add_parser(subparsers, parent_parser):
9797
studio_subparser = studio_parser.add_subparsers(
9898
dest="cmd",
9999
help="Use `DVC studio CMD --help` to display command-specific help.",
100+
required=True,
100101
)
101-
fix_subparsers(studio_subparser)
102102

103103
STUDIO_LOGIN_HELP = "Authenticate DVC with Studio host"
104104
STUDIO_LOGIN_DESCRIPTION = (

0 commit comments

Comments
 (0)