Skip to content
Open
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
3 changes: 3 additions & 0 deletions dvc/repo/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from ..repo.scm_context import scm_context
from ..utils import LARGE_DIR_SIZE, glob_targets, resolve_output, resolve_paths
from ..utils.collections import ensure_list, validate
from ..utils.hdf5 import get_external_links
from . import locked

if TYPE_CHECKING:
Expand Down Expand Up @@ -237,6 +238,8 @@ def _find_all_targets(
if not repo.scm.belongs_to_scm(path)
if not repo.scm.is_tracked(path)
)
elif (target.find(".h5") != -1):
yield from get_external_links(target)
else:
yield target

Expand Down
21 changes: 21 additions & 0 deletions dvc/utils/hdf5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

import h5py

class H5ls:
def __init__(self):
# Store an empty list for link names
self.names = []

def __call__(self, name, obj):
for key, val in obj.items():
p = obj.get(name=key,default=None, getclass=False, getlink=True)
if (isinstance(p, h5py.ExternalLink)):
self.names.append(p.filename)

def get_external_links(target):
h5ls = H5ls()
h5ls.names.append(target)
with h5py.File(target,'r') as hdf:
hdf.visititems(h5ls)
return set(h5ls.names)