mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
add: auto convert absolute_path => relative (#2975)
* add: auto convert absolute_path => relative - fixes #2955 * use path_isin * catch-all absolute paths in repo * unneeded leftover * revert realtive imports for later * output: move abs2relpath from Base to Local * output:local:fix parse_path * remove path_info * test:local versus base abs2relpath * test:fix remaining abs2relpath test * output: local path relative to wdir * output: local: modify path before inheritance * output: local: minor inheritance fix * test: local: split output test * test: local: positively explicit
This commit is contained in:
@@ -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":
|
||||
|
||||
@@ -216,7 +216,7 @@ class TestAddLocalRemoteFile(TestDvc):
|
||||
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):
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user