Skip to content

Commit

Permalink
get/import: display path relative to temporary repo
Browse files Browse the repository at this point in the history
  • Loading branch information
skshetry committed Nov 18, 2019
1 parent 68c7366 commit f07a70a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
11 changes: 10 additions & 1 deletion dvc/output/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
from dvc.istextfile import istextfile
from dvc.output.base import OutputBase
from dvc.remote.local import RemoteLOCAL
from dvc.utils import relpath
from dvc.utils.compat import fspath_py35
from dvc.utils.compat import str
from dvc.utils.compat import urlparse
from dvc.utils.fs import path_isin


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

def __str__(self):
return str(self.path_info)
if not self.is_in_repo:
return str(self.def_path)

cur_dir = os.getcwd()
if path_isin(cur_dir, self.repo.root_dir):
return relpath(self.path_info, cur_dir)

return relpath(self.path_info, self.repo.root_dir)

@property
def fspath(self):
Expand Down
32 changes: 31 additions & 1 deletion tests/unit/output/test_local.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from mock import patch
import os

from mock import patch
from dvc.output import OutputLOCAL
from dvc.remote.local import RemoteLOCAL
from dvc.stage import Stage
from dvc.utils import relpath
from tests.basic_env import TestDvc


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


def test_str_workdir_outside_repo(erepo):
stage = Stage(erepo.dvc)
output = OutputLOCAL(stage, "path", cache=False)

assert relpath("path", erepo.dvc.root_dir) == str(output)


def test_str_workdir_inside_repo(dvc_repo):
stage = Stage(dvc_repo)
output = OutputLOCAL(stage, "path", cache=False)

assert "path" == str(output)

stage = Stage(dvc_repo, wdir="some_folder")
output = OutputLOCAL(stage, "path", cache=False)

assert os.path.join("some_folder", "path") == str(output)


def test_str_on_absolute_path(dvc_repo):
stage = Stage(dvc_repo)

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

assert path == str(output)


class TestGetFilesNumber(TestDvc):
def _get_output(self):
stage = Stage(self.dvc)
Expand Down

0 comments on commit f07a70a

Please sign in to comment.