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
18 changes: 7 additions & 11 deletions dvc/repo/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Set,
)

from funcy import cached_property, memoize, nullcontext
from funcy import cached_property, nullcontext

from dvc.utils import dict_md5

Expand Down Expand Up @@ -146,9 +146,11 @@ def outs_trie(self) -> "Trie":

return build_outs_trie(self.stages)

@property
@cached_property
def graph(self) -> "DiGraph":
return self.build_graph()
from dvc.repo.graph import build_graph

return build_graph(self.stages, self.outs_trie)

@cached_property
def outs_graph(self) -> "DiGraph":
Expand Down Expand Up @@ -230,15 +232,9 @@ def _discard_stage(
stages.remove(stage)
return stages

@memoize
def build_graph(self) -> "DiGraph":
from dvc.repo.graph import build_graph

return build_graph(self.stages, self.outs_trie)

def check_graph(self) -> None:
if not getattr(self.repo, "_skip_graph_checks", False):
self.build_graph()
self.graph # pylint: disable=pointless-statement

def dumpd(self) -> Dict[str, Dict]:
def dump(stage: "Stage"):
Expand Down Expand Up @@ -275,7 +271,7 @@ def identifier(self) -> str:
# pylint: disable=pointless-statement
print("no of stages", len(index.stages))
with log_durations(print, "building graph"):
index.build_graph()
index.graph # pylint: disable=pointless-statement
with log_durations(print, "calculating hash"):
print(index.identifier)
with log_durations(print, "updating"):
Expand Down
3 changes: 1 addition & 2 deletions tests/func/test_repo_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def test_index(tmp_dir, scm, dvc, run_copy):

assert index.outs_graph
assert index.graph
assert index.build_graph()
assert isinstance(index.outs_trie, Trie)
assert index.identifier
index.check_graph()
Expand Down Expand Up @@ -229,7 +228,7 @@ def test_unique_identifier(tmp_dir, dvc, scm, run_copy):

def test_skip_graph_checks(dvc, mocker):
# See https://github.com/iterative/dvc/issues/2671 for more info
mock_build_graph = mocker.spy(Index, "build_graph")
mock_build_graph = mocker.spy(Index.graph, "fget")

# sanity check
Index(dvc).check_graph()
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/repo/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ def test_locked(mocker):

def test_skip_graph_checks(tmp_dir, dvc, mocker, run_copy):
# See https://github.com/iterative/dvc/issues/2671 for more info
mock_build_graph = mocker.patch("dvc.repo.index.Index.build_graph")
from dvc.repo.index import Index

mock_build_graph = mocker.spy(Index.graph, "fget")

# sanity check
tmp_dir.gen("foo", "foo text")
Expand Down