MCPcopy
hub / github.com/treeverse/dvc / main

Function main

dvc/cli/__init__.py:151–257  ·  view source on GitHub ↗

Main entry point for dvc CLI. Args: argv: optional list of arguments to parse. sys.argv is used by default. Returns: int: command's return code.

(argv=None)

Source from the content-addressed store, hash-verified

149
150
151def main(argv=None): # noqa: C901, PLR0912, PLR0915
152 """Main entry point for dvc CLI.
153
154 Args:
155 argv: optional list of arguments to parse. sys.argv is used by default.
156
157 Returns:
158 int: command's return code.
159 """
160 from contextlib import ExitStack
161
162 from dvc._debug import debugtools
163 from dvc.config import ConfigError
164 from dvc.exceptions import DvcException, NotDvcRepoError
165 from dvc.logger import set_loggers_level
166
167 # NOTE: stderr/stdout may be closed if we are running from dvc.daemon.
168 # On Linux we directly call cli.main after double forking and closing
169 # the copied parent's standard file descriptors. If we make any logging
170 # calls in this state it will cause an exception due to writing to a closed
171 # file descriptor.
172 if not sys.stderr or sys.stderr.closed:
173 logging.disable()
174 elif not sys.stdout or sys.stdout.closed:
175 logging.disable(logging.INFO)
176
177 args = None
178 stack = ExitStack()
179 try:
180 args = parse_args(argv)
181
182 level = None
183 if args.quiet:
184 level = logging.CRITICAL
185 elif args.verbose == 1:
186 level = logging.DEBUG
187 elif args.verbose > 1:
188 level = logging.TRACE # type: ignore[attr-defined]
189
190 if level is not None:
191 stack.enter_context(set_loggers_level(level))
192
193 if level and level <= logging.DEBUG:
194 from platform import platform, python_implementation, python_version
195
196 from dvc import PKG, __version__
197
198 pyv = f"{python_implementation()} {python_version()}"
199 pkg = f" ({PKG})" if PKG else ""
200 logger.debug("v%s%s, %s on %s", __version__, pkg, pyv, platform())
201 logger.debug("command: %s", " ".join(argv or sys.argv))
202
203 logger.trace(args)
204
205 if sys.stdout and not sys.stdout.closed and not args.quiet:
206 from dvc.ui import ui
207
208 ui.enable()

Callers 15

__main__.pyFile · 0.90
_runMethod · 0.90
_runMethod · 0.90
_runMethod · 0.90
callFunction · 0.90
test_config_output_dirFunction · 0.90
test_remoteFunction · 0.90
test_remote_overwriteFunction · 0.90
test_remove_defaultFunction · 0.90
test_remote_removeFunction · 0.90

Calls 12

set_loggers_levelFunction · 0.90
debugtoolsFunction · 0.90
clean_reposFunction · 0.90
parse_argsFunction · 0.85
_log_exceptionsFunction · 0.85
joinMethod · 0.80
enableMethod · 0.80
funcMethod · 0.80
openMethod · 0.80
is_enabledMethod · 0.80
do_runMethod · 0.45
closeMethod · 0.45

Tested by 15

callFunction · 0.72
test_config_output_dirFunction · 0.72
test_remoteFunction · 0.72
test_remote_overwriteFunction · 0.72
test_remove_defaultFunction · 0.72
test_remote_removeFunction · 0.72
test_remote_default_cmdFunction · 0.72
test_show_defaultFunction · 0.72
test_list_shows_defaultFunction · 0.72
test_upper_case_remoteFunction · 0.72