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
6 changes: 6 additions & 0 deletions dvc/output/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ class OutputLOCAL(OutputBase):
REMOTE = RemoteLOCAL
sep = os.sep

def __init__(self, stage, path, *args, **kwargs):
if stage and path_isin(path, stage.repo.root_dir):
path = relpath(path, stage.wdir)

super().__init__(stage, path, *args, **kwargs)

def _parse_path(self, remote, path):
parsed = urlparse(path)
if parsed.scheme == "remote":
Expand Down
2 changes: 1 addition & 1 deletion tests/func/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def test(self):
self.assertEqual(ret, 0)

d = load_stage_file("bar.dvc")
self.assertEqual(d["outs"][0]["path"], bar)
self.assertEqual(d["outs"][0]["path"], self.BAR)


class TestCmdAdd(TestDvc):
Expand Down
23 changes: 19 additions & 4 deletions tests/unit/output/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,28 @@ def test_str_workdir_inside_repo(dvc):
assert os.path.join("some_folder", "path") == str(output)


def test_str_on_absolute_path(dvc):
def test_str_on_local_absolute_path(dvc):
stage = Stage(dvc)

path = os.path.abspath(os.path.join("path", "to", "file"))
output = OutputLOCAL(stage, path, cache=False)
rel_path = os.path.join("path", "to", "file")
abs_path = os.path.abspath(rel_path)
output = OutputLOCAL(stage, abs_path, cache=False)

assert path == str(output)
assert output.def_path == rel_path
assert output.path_info.fspath == abs_path
assert str(output) == rel_path


def test_str_on_external_absolute_path(dvc):
stage = Stage(dvc)

rel_path = os.path.join("..", "path", "to", "file")
abs_path = os.path.abspath(rel_path)
output = OutputLOCAL(stage, abs_path, cache=False)

assert output.def_path == abs_path
assert output.path_info.fspath == abs_path
assert str(output) == abs_path


class TestGetFilesNumber(TestDvc):
Expand Down