Skip to content

Commit f07a70a

Browse files
committed
get/import: display path relative to temporary repo
1 parent 68c7366 commit f07a70a

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

dvc/output/local.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
from dvc.istextfile import istextfile
88
from dvc.output.base import OutputBase
99
from dvc.remote.local import RemoteLOCAL
10+
from dvc.utils import relpath
1011
from dvc.utils.compat import fspath_py35
1112
from dvc.utils.compat import str
1213
from dvc.utils.compat import urlparse
14+
from dvc.utils.fs import path_isin
1315

1416

1517
logger = logging.getLogger(__name__)
@@ -38,7 +40,14 @@ def _parse_path(self, remote, path):
3840
return self.REMOTE.path_cls(abs_p)
3941

4042
def __str__(self):
41-
return str(self.path_info)
43+
if not self.is_in_repo:
44+
return str(self.def_path)
45+
46+
cur_dir = os.getcwd()
47+
if path_isin(cur_dir, self.repo.root_dir):
48+
return relpath(self.path_info, cur_dir)
49+
50+
return relpath(self.path_info, self.repo.root_dir)
4251

4352
@property
4453
def fspath(self):

tests/unit/output/test_local.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
from mock import patch
1+
import os
22

3+
from mock import patch
34
from dvc.output import OutputLOCAL
45
from dvc.remote.local import RemoteLOCAL
56
from dvc.stage import Stage
7+
from dvc.utils import relpath
68
from tests.basic_env import TestDvc
79

810

@@ -21,6 +23,34 @@ def test_save_missing(self):
2123
o.save()
2224

2325

26+
def test_str_workdir_outside_repo(erepo):
27+
stage = Stage(erepo.dvc)
28+
output = OutputLOCAL(stage, "path", cache=False)
29+
30+
assert relpath("path", erepo.dvc.root_dir) == str(output)
31+
32+
33+
def test_str_workdir_inside_repo(dvc_repo):
34+
stage = Stage(dvc_repo)
35+
output = OutputLOCAL(stage, "path", cache=False)
36+
37+
assert "path" == str(output)
38+
39+
stage = Stage(dvc_repo, wdir="some_folder")
40+
output = OutputLOCAL(stage, "path", cache=False)
41+
42+
assert os.path.join("some_folder", "path") == str(output)
43+
44+
45+
def test_str_on_absolute_path(dvc_repo):
46+
stage = Stage(dvc_repo)
47+
48+
path = os.path.abspath(os.path.join("path", "to", "file"))
49+
output = OutputLOCAL(stage, path, cache=False)
50+
51+
assert path == str(output)
52+
53+
2454
class TestGetFilesNumber(TestDvc):
2555
def _get_output(self):
2656
stage = Stage(self.dvc)

0 commit comments

Comments
 (0)