mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-19 07:18:27 +01:00
cache relpath and path_in_repo (#4053)
This commit is contained in:
@@ -3,7 +3,7 @@ import os
|
||||
import string
|
||||
from collections import defaultdict
|
||||
|
||||
from funcy import project
|
||||
from funcy import cached_property, project
|
||||
|
||||
import dvc.dependency as dependency
|
||||
import dvc.prompt as prompt
|
||||
@@ -127,6 +127,8 @@ class Stage(params.StageParams):
|
||||
@path.setter
|
||||
def path(self, path):
|
||||
self._path = path
|
||||
self.__dict__.pop("path_in_repo", None)
|
||||
self.__dict__.pop("relpath", None)
|
||||
|
||||
@property
|
||||
def dvcfile(self):
|
||||
@@ -172,11 +174,11 @@ class Stage(params.StageParams):
|
||||
and self.path_in_repo == other.path_in_repo
|
||||
)
|
||||
|
||||
@property
|
||||
@cached_property
|
||||
def path_in_repo(self):
|
||||
return relpath(self.path, self.repo.root_dir)
|
||||
|
||||
@property
|
||||
@cached_property
|
||||
def relpath(self):
|
||||
return relpath(self.path)
|
||||
|
||||
|
||||
@@ -220,6 +220,10 @@ def test_stage_strings_representation(tmp_dir, dvc, run_copy):
|
||||
folder = tmp_dir / "dir"
|
||||
folder.mkdir()
|
||||
with folder.chdir():
|
||||
# `Stage` caches `relpath` results, forcing it to reset
|
||||
stage1.path = stage1.path
|
||||
stage2.path = stage2.path
|
||||
|
||||
rel_path = os.path.relpath(stage1.path)
|
||||
assert stage1.addressing == rel_path
|
||||
assert repr(stage1) == f"Stage: '{rel_path}'"
|
||||
|
||||
Reference in New Issue
Block a user