Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detection for nested folders #623

Merged
merged 11 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 2 additions & 2 deletions datumaro/cli/util/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ def parse_full_revpath(s: str, ctx_project: Optional[Project] = None) \

errors = []
try:
return parse_dataset_pathspec(s, env=env), None
return parse_revspec(s, ctx_project=ctx_project)
except (DatumaroError, OSError) as e:
errors.append(e)

try:
return parse_revspec(s, ctx_project=ctx_project)
return parse_dataset_pathspec(s, env=env), None
except (DatumaroError, OSError) as e:
errors.append(e)

Expand Down
17 changes: 14 additions & 3 deletions datumaro/components/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing import (
Any, Callable, Dict, Iterable, Iterator, List, Optional, Tuple, Type, Union,
)
import glob
import inspect
import logging as log
import os
Expand Down Expand Up @@ -905,16 +906,26 @@ def import_from(cls, path: str, format: Optional[str] = None,
return dataset

@staticmethod
def detect(path: str, env: Optional[Environment] = None) -> str:
def detect(path: str, env: Optional[Environment] = None,
zhiltsov-max marked this conversation as resolved.
Show resolved Hide resolved
depth: Optional[int] = 2) -> str:
if env is None:
env = Environment()

matches = env.detect_dataset(path)
for _ in range(depth):
matches = env.detect_dataset(path)
if matches and len(matches) == 1:
return matches[0]

paths = glob.glob(osp.join(path, '*'))
path = '' if len(paths) != 1 else paths[0]
ignore_dirs = {'__MSOSX', '__MACOSX'}
if not osp.isdir(path) or osp.basename(path) in ignore_dirs:
break

if not matches:
raise NoMatchingFormatsError()
if 1 < len(matches):
raise MultipleFormatsMatchError(matches)
return matches[0]

@contextmanager
def eager_mode(new_mode: bool = True, dataset: Optional[Dataset] = None) -> None:
Expand Down