Skip to content

Commit

Permalink
url info and repo grap optimization: address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
shcheklein committed Jul 5, 2019
1 parent 0abf530 commit 8fd18f5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
2 changes: 1 addition & 1 deletion dvc/path_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def name(self):

@property
def parts(self):
return (self.scheme, self.parsed.netloc) + self._path.parts
return (self.scheme, self.netloc) + self._path.parts

@property
def bucket(self):
Expand Down
17 changes: 6 additions & 11 deletions dvc/repo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import os
import logging

from itertools import chain

from dvc.config import Config
from dvc.exceptions import (
NotDvcRepoError,
Expand Down Expand Up @@ -305,26 +307,19 @@ def graph(self, stages=None, from_directory=None):
for stage in stages:
for out in stage.outs:
if out.path_info in outs:
stages = [
stage.relpath,
outs.get(out.path_info).stage.relpath,
]
stages = [stage.relpath, outs[out.path_info].stage.relpath]
raise OutputDuplicationError(str(out), stages)
outs[out.path_info] = out

for stage in stages:
for out in stage.outs:
for p in out.path_info.parents:
if p in outs:
raise OverlappingOutputPathsError(
outs.get(p), outs.get(out.path_info)
)
raise OverlappingOutputPathsError(outs[p], out)

for stage in stages:
stage_path_info = PathInfo(stage.path)
if stage_path_info in outs:
raise StagePathAsOutputError(stage.wdir, stage.relpath)
for p in stage_path_info.parents:
for p in chain([stage_path_info], stage_path_info.parents):
if p in outs:
raise StagePathAsOutputError(stage.wdir, stage.relpath)

Expand All @@ -341,7 +336,7 @@ def graph(self, stages=None, from_directory=None):
or dep.path_info.isin(out)
or out.isin(dep.path_info)
):
dep_stage = outs.get(out).stage
dep_stage = outs[out].stage
dep_node = relpath(dep_stage.path, self.root_dir)
G.add_node(dep_node, stage=dep_stage)
G.add_edge(node, dep_node)
Expand Down
38 changes: 22 additions & 16 deletions tests/unit/test_path_info.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
from dvc.path_info import URLInfo
import pytest

from dvc.path_info import URLInfo, CloudURLInfo

def test_url_info_str():
u = URLInfo("ssh://[email protected]:/test1/")

@pytest.mark.parametrize("cls", [URLInfo, CloudURLInfo])
def test_url_info_str(cls):
u = cls("ssh://[email protected]:/test1/")
assert u.url == "ssh://[email protected]/test1/"
assert str(u) == u.url


def test_url_info_eq():
u1 = URLInfo("ssh://[email protected]:/test1/")
u2 = URLInfo("ssh://[email protected]/test1")
@pytest.mark.parametrize("cls", [URLInfo, CloudURLInfo])
def test_url_info_eq(cls):
u1 = cls("ssh://[email protected]:/test1/")
u2 = cls("ssh://[email protected]/test1")
assert u1 == u2


def test_url_info_parent():
u1 = URLInfo("ssh://[email protected]:/test1/test2")
@pytest.mark.parametrize("cls", [URLInfo, CloudURLInfo])
def test_url_info_parent(cls):
u1 = cls("ssh://[email protected]:/test1/test2")
p = u1.parent
u3 = URLInfo("ssh://[email protected]/test1")
u3 = cls("ssh://[email protected]/test1")
assert u3 == p
assert str(p) == "ssh://[email protected]/test1"


def test_url_info_parents():
u1 = URLInfo("ssh://[email protected]:/test1/test2/test3")
parents = u1.parents
assert len(parents) == 3
assert parents[0] == URLInfo("ssh://[email protected]/test1/test2")
assert parents[1] == URLInfo("ssh://[email protected]/test1")
assert parents[2] == URLInfo("ssh://[email protected]/")
@pytest.mark.parametrize("cls", [URLInfo, CloudURLInfo])
def test_url_info_parents(cls):
u1 = cls("ssh://[email protected]:/test1/test2/test3")
assert list(u1.parents) == [
cls("ssh://[email protected]/test1/test2"),
cls("ssh://[email protected]/test1"),
cls("ssh://[email protected]/"),
]

0 comments on commit 8fd18f5

Please sign in to comment.