Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import: fix output message on not-existing output directory #3509

Merged
merged 1 commit into from
Mar 19, 2020
Merged
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
31 changes: 17 additions & 14 deletions dvc/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,15 @@ class StageFileBadNameError(DvcException):


class StagePathOutsideError(DvcException):
def __init__(self, path):
msg = "stage working or file path '{}' is outside of DVC repo"
super().__init__(msg.format(path))
pass


class StagePathNotFoundError(DvcException):
def __init__(self, path):
msg = "stage working or file path '{}' does not exist"
super().__init__(msg.format(path))
pass


class StagePathNotDirectoryError(DvcException):
def __init__(self, path):
msg = "stage working or file path '{}' is not directory"
super().__init__(msg.format(path))
pass


class StageCommitError(DvcException):
Expand Down Expand Up @@ -442,19 +436,28 @@ def _stage_fname(cls, outs, add):
return fname

@staticmethod
def _check_stage_path(repo, path):
def _check_stage_path(repo, path, is_wdir=False):
assert repo is not None

error_msg = "{wdir_or_path} '{path}' {{}}".format(
wdir_or_path="stage working dir" if is_wdir else "file path",
path=path,
)

real_path = os.path.realpath(path)
if not os.path.exists(real_path):
raise StagePathNotFoundError(path)
raise StagePathNotFoundError(error_msg.format("does not exist"))

if not os.path.isdir(real_path):
raise StagePathNotDirectoryError(path)
raise StagePathNotDirectoryError(
error_msg.format("is not directory")
)

proj_dir = os.path.realpath(repo.root_dir)
if real_path != proj_dir and not path_isin(real_path, proj_dir):
raise StagePathOutsideError(path)
raise StagePathOutsideError(
error_msg.format("is outside of DVC repo")
)

@property
def is_cached(self):
Expand Down Expand Up @@ -557,7 +560,7 @@ def create(repo, accompany_outs=False, **kwargs):
else:
path = os.path.abspath(fname)

Stage._check_stage_path(repo, wdir)
Stage._check_stage_path(repo, wdir, is_wdir=kwargs.get("wdir"))
Copy link
Member Author

@skshetry skshetry Mar 19, 2020

Choose a reason for hiding this comment

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

This will only throw error with message "stage working dir" for dvc.run() cases where wdir is explicitly set.

Stage._check_stage_path(repo, os.path.dirname(path))

stage.wdir = wdir
Expand Down