Skip to content

Commit 5c6ec59

Browse files
committed
Improve check for remote datasets (only 'url' and 'local_dir' are
mandatory).
1 parent e355020 commit 5c6ec59

2 files changed

Lines changed: 23 additions & 7 deletions

File tree

smartBugs.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!/usr/bin/env python3
22

3-
# import docker
43
import yaml
5-
# import logging
64
import argparse
75
import os
86
import sys
@@ -85,7 +83,7 @@ def exec_cmd(args: argparse.Namespace):
8583
# local copy does not exist; we need to clone it
8684
print('\x1b[1;37m' + "%s is a remote dataset. Do you want to create a local copy? [Y/n] " % base_name + '\x1b[0m')
8785
answer = input()
88-
if answer in ['y', 'Y', 'Yes', 'YES', 'Ye', 'YE']:
86+
if answer in ['y', 'Y', 'yes', 'Yes', 'YES', '']:
8987
sys.stdout.write('\x1b[1;37m' + 'Cloning remote dataset [%s <- %s]... ' % (base_path, remote_info['url']) + '\x1b[0m')
9088
sys.stdout.flush()
9189
git.Repo.clone_from(remote_info['url'], base_path)

src/interface/cli.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env python3
22
import yaml
3-
# import logging
43
import argparse
54
import os
65
import sys
@@ -52,13 +51,29 @@ def __call__(self, parser, namespace, values, option_string=None):
5251

5352
# Parser stuff
5453
def isRemoteDataset(cfg_dataset, name):
54+
"""Given a dataset file configuration and a dataset name, return True
55+
if the dataset is remote and False otherwise.
56+
"""
5557
remote_info = cfg_dataset[name]
5658
if isinstance(remote_info, list):
57-
for prop in (e['url'] for e in remote_info if isinstance(e, dict) and 'url' in e):
59+
merged = {}
60+
for d in remote_info:
61+
if isinstance(d, dict):
62+
merged = merge_two_dicts(merged, d)
63+
64+
# A remote dataset needs to define an url and a local dir
65+
if 'url' in merged and 'local_dir' in merged:
5866
return True
5967
return False
6068

6169

70+
def merge_two_dicts(x, y):
71+
"""Given two dictionaries, merge them into a new dict as a shallow copy."""
72+
z = x.copy()
73+
z.update(y)
74+
return z
75+
76+
6277
# transform remote dataset info in dictionary
6378
def getRemoteDataset(cfg_dataset, name):
6479
remote_dataset = {}
@@ -72,8 +87,11 @@ def getRemoteDataset(cfg_dataset, name):
7287

7388
# at this point, subsets is a list of dicts
7489
# we want it to be a dictionary
75-
remote_dataset['subsets'] = \
76-
reduce(lambda a, b: dict(a, **b), remote_dataset['subsets'])
90+
if 'subsets' in remote_dataset:
91+
remote_dataset['subsets'] = \
92+
reduce(lambda a, b: dict(a, **b), remote_dataset['subsets'])
93+
else:
94+
remote_dataset['subsets'] = {}
7795

7896
return remote_dataset
7997

0 commit comments

Comments
 (0)