Skip to content

Commit

Permalink
index: add workspace/key generation helper
Browse files Browse the repository at this point in the history
  • Loading branch information
pmrowla authored and efiop committed Sep 15, 2022
1 parent fa45a9b commit ecb767d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
16 changes: 14 additions & 2 deletions dvc/output.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import logging
import os
from collections import defaultdict
from typing import TYPE_CHECKING, Dict, Optional, Set, Type
from typing import TYPE_CHECKING, Dict, Optional, Set, Tuple, Type
from urllib.parse import urlparse

from funcy import collecting, project
from funcy import cached_property, collecting, project
from voluptuous import And, Any, Coerce, Length, Lower, Required, SetTo

from dvc import prompt
Expand Down Expand Up @@ -34,6 +34,7 @@
from .utils.fs import path_isin

if TYPE_CHECKING:
from dvc_data.index import DataIndexKey
from dvc_objects.db import ObjectDB

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -490,6 +491,17 @@ def exists(self):

return self.fs.exists(self.fs_path)

@cached_property
def index_key(self) -> Tuple[str, "DataIndexKey"]:
if self.is_in_repo:
workspace = "repo"
key = self.repo.fs.path.relparts(self.fs_path, self.repo.root_dir)
else:
workspace = self.fs.protocol
no_drive = self.fs.path.flavour.splitdrive(self.fs_path)[1]
key = self.fs.path.parts(no_drive)[1:]
return workspace, key

def changed_checksum(self):
return self.hash_info != self.get_hash()

Expand Down
10 changes: 1 addition & 9 deletions dvc/repo/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,7 @@ def data(self) -> "Dict[str, DataIndex]":
if not out.use_cache:
continue

if out.is_in_repo:
workspace = "repo"
key = self.repo.fs.path.relparts(
out.fs_path, self.repo.root_dir
)
else:
workspace = out.fs.protocol
no_drive = out.fs.path.flavour.splitdrive(out.fs_path)[1]
key = out.fs.path.parts(no_drive)[1:]
workspace, key = out.index_key

try:
remote = self.repo.cloud.get_remote_odb(out.remote)
Expand Down

0 comments on commit ecb767d

Please sign in to comment.