mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-07 07:18:27 +01:00
* test: clean flake8 config root clutter * test: pre-commit: add isort Compatible with black (see https://github.com/timothycrosley/isort/issues/694) * lint: reorder imports * lint: more complex imports * lint: fix deepsource * config: isort: add first party dvc * tests: restyled: add isort * temp commit to revert before merge * Revert "temp commit to revert before merge" This reverts commit 11db0fd8e95fe891597cbb9bf804480909b19e24.
70 lines
1.9 KiB
Python
70 lines
1.9 KiB
Python
import argparse
|
|
import logging
|
|
|
|
from dvc.command.base import CmdBaseNoRepo, append_doc_link
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class CmdInit(CmdBaseNoRepo):
|
|
def run(self):
|
|
from dvc.repo import Repo
|
|
from dvc.exceptions import InitError
|
|
|
|
try:
|
|
self.repo = Repo.init(
|
|
".",
|
|
no_scm=self.args.no_scm,
|
|
force=self.args.force,
|
|
subdir=self.args.subdir,
|
|
)
|
|
self.config = self.repo.config
|
|
except InitError:
|
|
logger.exception("failed to initiate DVC")
|
|
return 1
|
|
return 0
|
|
|
|
|
|
def add_parser(subparsers, parent_parser):
|
|
"""Setup parser for `dvc init`."""
|
|
INIT_HELP = "Initialize DVC in the current directory."
|
|
INIT_DESCRIPTION = (
|
|
"Initialize DVC in the current directory. Expects directory\n"
|
|
"to be a Git repository unless --no-scm option is specified."
|
|
)
|
|
|
|
init_parser = subparsers.add_parser(
|
|
"init",
|
|
parents=[parent_parser],
|
|
description=append_doc_link(INIT_DESCRIPTION, "init"),
|
|
help=INIT_HELP,
|
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
)
|
|
init_parser.add_argument(
|
|
"--no-scm",
|
|
action="store_true",
|
|
default=False,
|
|
help="Initiate DVC in directory that is "
|
|
"not tracked by any SCM tool (e.g. Git).",
|
|
)
|
|
init_parser.add_argument(
|
|
"-f",
|
|
"--force",
|
|
action="store_true",
|
|
default=False,
|
|
help=(
|
|
"Overwrite existing '.dvc/' directory. "
|
|
"This operation removes local cache."
|
|
),
|
|
)
|
|
init_parser.add_argument(
|
|
"--subdir",
|
|
action="store_true",
|
|
default=False,
|
|
help=(
|
|
"Necessary for running this command inside a subdirectory of a "
|
|
"parent SCM repository."
|
|
),
|
|
)
|
|
init_parser.set_defaults(func=CmdInit)
|