Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions dvc/command/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,6 @@ def default_targets(self):
logger.warning(msg)
return [Stage.STAGE_FILE]

def run_cmd(self):
from dvc.lock import LockError

try:
with self.repo.lock:
return self.run()
except LockError:
logger.exception("failed to lock before running a command")
return 1

# Abstract methods that have to be implemented by any inheritance class
def run(self):
pass
Expand All @@ -73,6 +63,3 @@ def run(self):
class CmdBaseNoRepo(CmdBase):
def __init__(self, args):
self.args = args

def run_cmd(self):
return self.run()
2 changes: 1 addition & 1 deletion dvc/command/destroy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


class CmdDestroy(CmdBase):
def run_cmd(self):
def run(self):
try:
statement = (
"This will destroy all information about your pipelines,"
Expand Down
2 changes: 1 addition & 1 deletion dvc/command/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


class CmdInstall(CmdBase):
def run_cmd(self):
def run(self):
try:
self.repo.install()
except Exception:
Expand Down
6 changes: 5 additions & 1 deletion dvc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging

from dvc.cli import parse_args
from dvc.lock import LockError
from dvc.config import ConfigError
from dvc.analytics import Analytics
from dvc.exceptions import NotDvcRepoError, DvcParserError
Expand Down Expand Up @@ -37,7 +38,10 @@ def main(argv=None):
logger.setLevel(logging.DEBUG)

cmd = args.func(args)
ret = cmd.run_cmd()
ret = cmd.run()
except LockError:
logger.exception("failed to lock before running a command")
Copy link
Contributor

@Suor Suor Sep 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we show more descriptive and actionable message? Like what is happening, i.e. that some concurrent dvc command is blocking. And if that is not so then what lock files should people remove.

Copy link
Contributor Author

@efiop efiop Sep 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Suor Sure. This is the old one that I've just moved. Created an issue for that one #2520

ret = 250
except ConfigError:
logger.exception("configuration error")
ret = 251
Expand Down
22 changes: 20 additions & 2 deletions dvc/repo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from contextlib import contextmanager
from itertools import chain

from functools import wraps
from funcy import cached_property

from dvc.config import Config
Expand All @@ -23,6 +24,15 @@
logger = logging.getLogger(__name__)


def locked(f):
@wraps(f)
def wrapper(repo, *args, **kwargs):
with repo.lock:
return f(repo, *args, **kwargs)

return wrapper


class Repo(object):
DVC_DIR = ".dvc"

Expand All @@ -36,9 +46,9 @@ class Repo(object):
from dvc.repo.imp import imp
from dvc.repo.imp_url import imp_url
from dvc.repo.reproduce import reproduce
from dvc.repo.checkout import checkout
from dvc.repo.checkout import _checkout
from dvc.repo.push import push
from dvc.repo.fetch import fetch
from dvc.repo.fetch import _fetch
from dvc.repo.pull import pull
from dvc.repo.status import status
from dvc.repo.gc import gc
Expand Down Expand Up @@ -486,3 +496,11 @@ def clone(url, to_path, rev=None):
git.close()

return Repo(to_path)

@locked
def checkout(self, *args, **kwargs):
return self._checkout(*args, **kwargs)

@locked
def fetch(self, *args, **kwargs):
return self._fetch(*args, **kwargs)
3 changes: 3 additions & 0 deletions dvc/repo/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
from dvc.utils import walk_files, LARGE_DIR_SIZE
from dvc.exceptions import RecursiveAddingWhileUsingFilename

from . import locked


logger = logging.getLogger(__name__)


@locked
@scm_context
def add(repo, target, recursive=False, no_commit=False, fname=None):
if recursive and fname:
Expand Down
4 changes: 3 additions & 1 deletion dvc/repo/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ def get_all_files_numbers(stages):
return sum(stage.get_all_files_number() for stage in stages)


def checkout(self, target=None, with_deps=False, force=False, recursive=False):
def _checkout(
self, target=None, with_deps=False, force=False, recursive=False
):
from dvc.stage import StageFileDoesNotExistError, StageFileBadNameError

all_stages = self.stages()
Expand Down
4 changes: 4 additions & 0 deletions dvc/repo/commit.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from . import locked


@locked
def commit(self, target, with_deps=False, recursive=False, force=False):
stages = self.collect(target, with_deps=with_deps, recursive=recursive)
with self.state:
Expand Down
3 changes: 3 additions & 0 deletions dvc/repo/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
DIFF_EQUAL,
)

from . import locked


DIFF_TARGET = "target"
DIFF_IS_DIR = "is_dir"
Expand Down Expand Up @@ -220,6 +222,7 @@ def _diff_royal(self, target, diff_dct):
return _diff_file(self, target, diff_dct)


@locked
def diff(self, a_ref, target=None, b_ref=None):
"""Gerenates diff message string output

Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/fetch.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import unicode_literals


def fetch(
def _fetch(
self,
targets=None,
jobs=None,
Expand Down
3 changes: 3 additions & 0 deletions dvc/repo/gc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import collections
import logging

from . import locked


logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -53,6 +55,7 @@ def _do_gc(typ, func, clist):
logger.info("No unused {} cache to remove.".format(typ))


@locked
def gc(
self,
all_branches=False,
Expand Down
3 changes: 3 additions & 0 deletions dvc/repo/imp_url.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from dvc.utils.compat import pathlib
from dvc.repo.scm_context import scm_context

from . import locked as locked_repo


@locked_repo
@scm_context
def imp_url(self, url, out=None, fname=None, erepo=None, locked=True):
from dvc.stage import Stage
Expand Down
4 changes: 4 additions & 0 deletions dvc/repo/lock.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from . import locked


@locked
def lock(self, target, unlock=False):
from dvc.stage import Stage

Expand Down
3 changes: 3 additions & 0 deletions dvc/repo/move.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
from dvc.exceptions import MoveNotDataSourceError
from dvc.repo.scm_context import scm_context

from . import locked


def _expand_target_path(from_path, to_path):
if os.path.isdir(to_path):
return os.path.join(to_path, os.path.basename(from_path))
return to_path


@locked
@scm_context
def move(self, from_path, to_path):
"""
Expand Down
7 changes: 5 additions & 2 deletions dvc/repo/pull.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from __future__ import unicode_literals

from . import locked


@locked
def pull(
self,
targets=None,
Expand All @@ -12,7 +15,7 @@ def pull(
force=False,
recursive=False,
):
processed_files_count = self.fetch(
processed_files_count = self._fetch(
targets,
jobs,
remote=remote,
Expand All @@ -22,7 +25,7 @@ def pull(
recursive=recursive,
)
for target in targets or [None]:
self.checkout(
self._checkout(
target=target,
with_deps=with_deps,
force=force,
Expand Down
3 changes: 3 additions & 0 deletions dvc/repo/push.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from __future__ import unicode_literals

from . import locked


@locked
def push(
self,
targets=None,
Expand Down
4 changes: 4 additions & 0 deletions dvc/repo/remove.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from . import locked


@locked
def remove(self, target, outs_only=False):
from dvc.stage import Stage

Expand Down
4 changes: 4 additions & 0 deletions dvc/repo/reproduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from dvc.repo.scm_context import scm_context
from dvc.utils import relpath

from . import locked


logger = logging.getLogger(__name__)


Expand All @@ -29,6 +32,7 @@ def _reproduce_stage(stages, node, **kwargs):
return [stage]


@locked
@scm_context
def reproduce(
self,
Expand Down
4 changes: 3 additions & 1 deletion dvc/repo/run.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from __future__ import unicode_literals

from dvc.repo.scm_context import scm_context
from . import locked
from .scm_context import scm_context


@locked
@scm_context
def run(self, no_exec=False, **kwargs):
from dvc.stage import Stage
Expand Down
3 changes: 3 additions & 0 deletions dvc/repo/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import logging
from funcy.py3 import cat

from . import locked


logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -91,6 +93,7 @@ def _cloud_status(
return ret


@locked
def status(
self,
targets=None,
Expand Down
4 changes: 4 additions & 0 deletions dvc/repo/update.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from . import locked


@locked
def update(self, target):
from dvc.stage import Stage

Expand Down