17
17
# limitations under the License.
18
18
"""Project initialization logic."""
19
19
20
+ import os
20
21
from pathlib import Path
21
- from typing import Dict
22
+ from typing import Dict , List , Optional
22
23
from uuid import uuid4
23
24
24
25
import attr
44
45
from renku .core .template .usecase import select_template
45
46
from renku .core .util import communication
46
47
from renku .core .util .os import is_path_empty
48
+ from renku .domain_model .project import Project
47
49
from renku .domain_model .template import Template , TemplateMetadata
48
50
from renku .version import __version__ , is_release
49
51
@@ -172,20 +174,23 @@ def _init(
172
174
if template is None :
173
175
raise errors .TemplateNotFoundError (f"Couldn't find template with id { template_id } " )
174
176
177
+ namespace , name = Project .get_namespace_and_name (client = client , name = name )
178
+ name = name or os .path .basename (path .rstrip (os .path .sep ))
179
+
175
180
metadata = dict ()
176
181
# NOTE: supply metadata
177
182
metadata ["__template_source__" ] = template_source
178
183
metadata ["__template_ref__" ] = template_ref
179
184
metadata ["__template_id__" ] = template_id
180
- metadata ["__namespace__" ] = ""
185
+ metadata ["__namespace__" ] = namespace or ""
181
186
metadata ["__sanitized_project_name__" ] = ""
182
187
metadata ["__repository__" ] = ""
183
188
metadata ["__project_slug__" ] = ""
184
189
metadata ["__project_description__" ] = description
185
190
if is_release () and "__renku_version__" not in metadata :
186
191
metadata ["__renku_version__" ] = __version__
187
- metadata ["name" ] = name # NOTE: kept for backwards compatibility
188
192
metadata ["__name__" ] = name
193
+ metadata ["name" ] = metadata ["__name__" ] # NOTE: kept for backwards compatibility
189
194
metadata ["__template_version__" ] = template .version
190
195
metadata ["__automated_update__" ] = True # TODO: This should come from a command line flag
191
196
@@ -225,7 +230,6 @@ def _init(
225
230
client = client ,
226
231
name = name ,
227
232
custom_metadata = custom_metadata ,
228
- force = force ,
229
233
data_dir = data_dir ,
230
234
description = description ,
231
235
keywords = keywords ,
@@ -253,30 +257,28 @@ def create_from_template(
253
257
rendered_template : RenderedTemplate ,
254
258
actions : Dict [str , FileAction ],
255
259
client ,
256
- name = None ,
257
- custom_metadata = None ,
258
- force = None ,
259
- data_dir = None ,
260
- user = None ,
261
- commit_message = None ,
262
- description = None ,
263
- keywords = None ,
264
- install_mergetool = False ,
260
+ name : Optional [str ] = None ,
261
+ namespace : Optional [str ] = None ,
262
+ custom_metadata : Optional [Dict ] = None ,
263
+ data_dir : Optional [str ] = None ,
264
+ commit_message : Optional [str ] = None ,
265
+ description : Optional [str ] = None ,
266
+ keywords : Optional [List [str ]] = None ,
267
+ install_mergetool : bool = False ,
265
268
):
266
269
"""Initialize a new project from a template.
267
270
268
271
Args:
269
272
rendered_template(RenderedTemplate): Rendered template.
270
273
actions(Dict[str, FileAction]): mapping of paths and actions to take.
271
274
client: ``LocalClient``.
272
- name: Name of the project (Default value = None).
273
- custom_metadata: Custom JSON-LD metadata (Default value = None).
274
- force: Whether to overwrite files (Default value = None).
275
- data_dir: Where to store dataset data (Default value = None).
276
- user: Current user (Default value = None).
277
- commit_message: Message for initial commit (Default value = None).
278
- description: Description of the project (Default value = None).
279
- keywords: Keywords for project (Default value = None).
275
+ name(Optional[str]): Name of the project (Default value = None).
276
+ namespace(Optional[str]): Namespace of the project (Default value = None).
277
+ custom_metadata(Optional[Dict]): Custom JSON-LD metadata (Default value = None).
278
+ data_dir(Optional[str]): Where to store dataset data (Default value = None).
279
+ commit_message(Optional[str]): Message for initial commit (Default value = None).
280
+ description(Optional[str]): Description of the project (Default value = None).
281
+ keywords(Optional[List[str]]): Keywords for project (Default value = None).
280
282
install_mergetool(bool): Whether to setup renku metadata mergetool (Default value = False).
281
283
"""
282
284
commit_only = [f"{ RENKU_HOME } /" , str (client .template_checksums )] + list (rendered_template .get_files ())
@@ -301,7 +303,7 @@ def create_from_template(
301
303
302
304
with client .commit (commit_message = commit_message , commit_only = commit_only , skip_dirty_checks = True ):
303
305
with client .with_metadata (
304
- name = name , description = description , custom_metadata = custom_metadata , keywords = keywords
306
+ name = name , namespace = namespace , description = description , custom_metadata = custom_metadata , keywords = keywords
305
307
) as project :
306
308
copy_template_to_client (
307
309
rendered_template = rendered_template , client = client , project = project , actions = actions
@@ -314,46 +316,42 @@ def create_from_template(
314
316
client .set_value ("renku" , client .DATA_DIR_CONFIG_KEY , str (data_dir ))
315
317
316
318
317
- @inject .autoparams ()
319
+ @inject .autoparams ("client_dispatcher" )
318
320
def _create_from_template_local (
319
- template_path ,
320
- name ,
321
+ template_path : Path ,
322
+ name : str ,
323
+ namespace : str ,
321
324
client_dispatcher : IClientDispatcher ,
322
- metadata = None ,
323
- custom_metadata = None ,
324
- default_metadata = None ,
325
- template_version = None ,
326
- immutable_template_files = None ,
327
- automated_template_update = True ,
328
- user = None ,
329
- source = None ,
330
- ref = None ,
331
- invoked_from = None ,
332
- initial_branch = None ,
333
- commit_message = None ,
334
- description = None ,
335
- keywords = None ,
325
+ metadata : Optional [Dict ] = None ,
326
+ custom_metadata : Optional [Dict ] = None ,
327
+ default_metadata : Optional [Dict ] = None ,
328
+ template_version : Optional [str ] = None ,
329
+ immutable_template_files : Optional [List [str ]] = None ,
330
+ automated_template_update : bool = True ,
331
+ user : Optional [Dict [str , str ]] = None ,
332
+ initial_branch : Optional [str ] = None ,
333
+ commit_message : Optional [str ] = None ,
334
+ description : Optional [str ] = None ,
335
+ keywords : Optional [List [str ]] = None ,
336
336
):
337
337
"""Initialize a new project from a template.
338
338
339
339
Args:
340
- template_path: Path to template.
341
- name: project name.
340
+ template_path(Path): Path to template.
341
+ name(str): project name.
342
+ namespace(str): project namespace.
342
343
client_dispatcher(IClientDispatcher): Injected client dispatcher.
343
- metadata: Project metadata (Default value = None).
344
- custom_metadata: Custom JSON-LD metadata (Default value = None).
345
- default_metadata: Default project metadata (Default value = None).
346
- template_version: Version of the template (Default value = None).
347
- immutable_template_files: Immutable template files (Default value = None).
348
- automated_template_update: If template can be updated automatically (Default value = True).
349
- user: Git user (Default value = None).
350
- source: Template source. (Default value = None).
351
- ref: Template reference (Default value = None).
352
- invoked_from: Where this was invoked from (Default value = None).
353
- initial_branch: Name of initial/main branch (Default value = None).
354
- commit_message: Message of initial commit (Default value = None).
355
- description: Project description (Default value = None).
356
- keywords: Project keywords (Default value = None).
344
+ metadata(Optional[Dict]): Project metadata (Default value = None).
345
+ custom_metadata(Optional[Dict]): Custom JSON-LD metadata (Default value = None).
346
+ default_metadata(Optional[Dict]): Default project metadata (Default value = None).
347
+ template_version(Optional[str]): Version of the template (Default value = None).
348
+ immutable_template_files(Optional[List[str]]): Immutable template files (Default value = None).
349
+ automated_template_update(bool): If template can be updated automatically (Default value = True).
350
+ user(Optional[Doct[str, str]]): Git user (Default value = None).
351
+ initial_branch(Optional[str]): Name of initial/main branch (Default value = None).
352
+ commit_message(Optional[str]): Message of initial commit (Default value = None).
353
+ description(Optional[str]): Project description (Default value = None).
354
+ keywords(Optional[List[str]]): Project keywords (Default value = None).
357
355
"""
358
356
client = client_dispatcher .current_client
359
357
@@ -380,7 +378,7 @@ def _create_from_template_local(
380
378
description = "" ,
381
379
parameters = {},
382
380
icon = "" ,
383
- immutable_files = immutable_template_files ,
381
+ immutable_files = immutable_template_files or [] ,
384
382
allow_update = automated_template_update ,
385
383
source = metadata ["__template_source__" ],
386
384
reference = metadata ["__template_ref__" ],
@@ -403,9 +401,8 @@ def _create_from_template_local(
403
401
actions = actions ,
404
402
client = client ,
405
403
name = name ,
404
+ namespace = namespace ,
406
405
custom_metadata = custom_metadata ,
407
- force = False ,
408
- user = user ,
409
406
commit_message = commit_message ,
410
407
description = description ,
411
408
keywords = keywords ,
0 commit comments