@@ -100,17 +100,15 @@ def dataset_parent(client, revision, datadir, format, ctx=None):
100
100
@pass_local_client (
101
101
clean = False , commit = True , commit_only = DATASET_METADATA_PATHS
102
102
)
103
- def create_dataset (client , name , handle_duplicate_fn = None ):
103
+ def create_dataset (client , name ):
104
104
"""Create an empty dataset in the current repo.
105
105
106
106
:raises: ``renku.core.errors.ParameterError``
107
107
"""
108
- existing = client .load_dataset (name = name )
109
- if (not existing or handle_duplicate_fn and handle_duplicate_fn (existing )):
110
- with client .with_dataset (name = name ) as dataset :
111
- creator = Creator .from_git (client .repo )
112
- if creator not in dataset .creator :
113
- dataset .creator .append (creator )
108
+ with client .with_dataset (name = name , create = True ) as dataset :
109
+ creator = Creator .from_git (client .repo )
110
+ if creator not in dataset .creator :
111
+ dataset .creator .append (creator )
114
112
115
113
116
114
@pass_local_client (
@@ -140,15 +138,16 @@ def add_file(
140
138
name ,
141
139
link = False ,
142
140
force = False ,
141
+ create = False ,
143
142
sources = (),
144
143
destination = '' ,
145
144
with_metadata = None ,
146
145
urlscontext = contextlib .nullcontext
147
146
):
148
147
"""Add data file to a dataset."""
149
148
add_to_dataset (
150
- client , urls , name , link , force , sources , destination , with_metadata ,
151
- urlscontext
149
+ client , urls , name , link , force , create , sources , destination ,
150
+ with_metadata , urlscontext
152
151
)
153
152
154
153
@@ -158,6 +157,7 @@ def add_to_dataset(
158
157
name ,
159
158
link = False ,
160
159
force = False ,
160
+ create = False ,
161
161
sources = (),
162
162
destination = '' ,
163
163
with_metadata = None ,
@@ -169,7 +169,9 @@ def add_to_dataset(
169
169
with_metadata .identifier
170
170
) if with_metadata else None
171
171
try :
172
- with client .with_dataset (name = name , identifier = identifier ) as dataset :
172
+ with client .with_dataset (
173
+ name = name , identifier = identifier , create = create
174
+ ) as dataset :
173
175
with urlscontext (urls ) as bar :
174
176
client .add_data_to_dataset (
175
177
dataset ,
@@ -195,6 +197,13 @@ def add_to_dataset(
195
197
196
198
dataset .update_metadata (with_metadata )
197
199
200
+ except DatasetNotFound :
201
+ raise DatasetNotFound (
202
+ 'Dataset "{0}" does not exist.\n '
203
+ 'Use "renku dataset create {0}" to create the dataset or retry '
204
+ '"renku dataset add {0}" command with "--create" option for '
205
+ 'automatic dataset creation.' .format (name )
206
+ )
198
207
except (FileNotFoundError , git .exc .NoSuchPathError ):
199
208
raise ParameterError ('Could not process \n {0}' .format ('\n ' .join (urls )))
200
209
@@ -393,8 +402,6 @@ def import_dataset(
393
402
name ,
394
403
extract ,
395
404
with_prompt = False ,
396
- force = False ,
397
- handle_duplicate_fn = None ,
398
405
pool_init_fn = None ,
399
406
pool_init_args = None ,
400
407
download_file_fn = default_download_file
@@ -428,8 +435,7 @@ def import_dataset(
428
435
record .links .get ('latest_html' )
429
436
) + text_prompt
430
437
431
- if not force :
432
- click .confirm (text_prompt , abort = True )
438
+ click .confirm (text_prompt , abort = True )
433
439
434
440
except KeyError as e :
435
441
raise ParameterError ((
@@ -482,27 +488,20 @@ def import_dataset(
482
488
pool .close ()
483
489
484
490
dataset_name = name or dataset .display_name
485
- existing = client .load_dataset (name = dataset_name )
486
- if (
487
- not existing or force or
488
- (handle_duplicate_fn and handle_duplicate_fn (dataset_name ))
489
- ):
490
- add_to_dataset (
491
- client ,
492
- urls = [str (p ) for p in Path (data_folder ).glob ('*' )],
493
- name = dataset_name ,
494
- with_metadata = dataset
495
- )
491
+ add_to_dataset (
492
+ client ,
493
+ urls = [str (p ) for p in Path (data_folder ).glob ('*' )],
494
+ name = dataset_name ,
495
+ with_metadata = dataset ,
496
+ create = True
497
+ )
496
498
497
- if dataset .version :
498
- tag_name = re .sub ('[^a-zA-Z0-9.-_]' , '_' , dataset .version )
499
- tag_dataset (
500
- client ,
501
- dataset_name ,
502
- tag_name ,
503
- 'Tag {} created by renku import' .format (dataset .version ),
504
- force = True
505
- )
499
+ if dataset .version :
500
+ tag_name = re .sub ('[^a-zA-Z0-9.-_]' , '_' , dataset .version )
501
+ tag_dataset (
502
+ client , dataset_name , tag_name ,
503
+ 'Tag {} created by renku import' .format (dataset .version )
504
+ )
506
505
507
506
508
507
@pass_local_client (clean = True , commit = True , commit_only = DATASET_METADATA_PATHS )
0 commit comments