@@ -285,8 +285,6 @@ def set_template_vars_in_context(ctx, param, value):
285285 return value
286286
287287
288-
289- # Modified computer setup command
290288@verdi_computer .command ('setup' )
291289@options_computer .LABEL ()
292290@options_computer .HOSTNAME ()
@@ -301,12 +299,12 @@ def set_template_vars_in_context(ctx, param, value):
301299@options_computer .USE_DOUBLE_QUOTES ()
302300@options_computer .PREPEND_TEXT ()
303301@options_computer .APPEND_TEXT ()
304- @options .NON_INTERACTIVE () # Uncomment this line
305- @options .TEMPLATE_FILE ()
306- @options .TEMPLATE_VARS ()
302+ @options .NON_INTERACTIVE ()
303+ @options .TEMPLATE_VARS () # This should come before TEMPLATE_FILE
304+ @options .TEMPLATE_FILE () # This will process the template and set defaults
307305@click .pass_context
308306@with_dbenv ()
309- def computer_setup (ctx , non_interactive , template , template_vars , ** kwargs ):
307+ def computer_setup (ctx , non_interactive , ** kwargs ):
310308 """Create a new computer."""
311309 from aiida .orm .utils .builders .computer import ComputerBuilder
312310
@@ -315,31 +313,6 @@ def computer_setup(ctx, non_interactive, template, template_vars, **kwargs):
315313 print (f"Debug: kwargs keys = { list (kwargs .keys ())} " )
316314 print (f"Debug: ctx.default_map = { ctx .default_map } " )
317315
318- # Handle template variables
319- template_var_dict = None
320- if template_vars :
321- try :
322- template_var_dict = json .loads (template_vars )
323- except json .JSONDecodeError as e :
324- echo .echo_critical (f'Invalid JSON in template-vars: { e } ' )
325-
326- # Process template if provided
327- if template :
328- try :
329- # Load and process the template
330- config_data = load_and_process_template (
331- template , interactive = not non_interactive , template_vars = template_var_dict
332- )
333-
334- # Update kwargs with config file data
335- # Only update if the value wasn't explicitly provided on command line
336- for key , value in config_data .items ():
337- if key not in kwargs or kwargs [key ] is None :
338- kwargs [key ] = value
339-
340- except Exception as e :
341- echo .echo_critical (f'Error processing template: { e } ' )
342-
343316 # Check for existing computer
344317 if kwargs .get ('label' ) and kwargs ['label' ] in get_computer_names ():
345318 echo .echo_critical (
@@ -372,91 +345,6 @@ def computer_setup(ctx, non_interactive, template, template_vars, **kwargs):
372345 profile = ctx .obj ['profile' ]
373346 echo .echo_report (f' verdi -p { profile .name } computer configure { computer .transport_type } { computer .label } ' )
374347
375- # Modified computer setup command
376- # @verdi_computer.command('setup')
377- # @options_computer.LABEL()
378- # @options_computer.HOSTNAME()
379- # @options_computer.DESCRIPTION()
380- # @options_computer.TRANSPORT()
381- # @options_computer.SCHEDULER()
382- # @options_computer.SHEBANG()
383- # @options_computer.WORKDIR()
384- # @options_computer.MPI_RUN_COMMAND()
385- # @options_computer.MPI_PROCS_PER_MACHINE()
386- # @options_computer.DEFAULT_MEMORY_PER_MACHINE()
387- # @options_computer.USE_DOUBLE_QUOTES()
388- # @options_computer.PREPEND_TEXT()
389- # @options_computer.APPEND_TEXT()
390- # # @options.NON_INTERACTIVE()
391- # # @options.CONFIG_FILE() # Keep the original config option for backward compatibility
392- # @options.TEMPLATE_FILE() # Add our new template option
393- # @options.TEMPLATE_VARS()
394- # @click.pass_context
395- # @with_dbenv()
396- # def computer_setup(ctx, non_interactive, template, template_vars, **kwargs):
397- # """Create a new computer."""
398- # from aiida.orm.utils.builders.computer import ComputerBuilder
399-
400- # print('HELLO')
401-
402- # # Handle template variables
403- # template_var_dict = None
404- # if template_vars:
405- # try:
406- # template_var_dict = json.loads(template_vars)
407- # except json.JSONDecodeError as e:
408- # echo.echo_critical(f'Invalid JSON in template-vars: {e}')
409-
410- # # Process template if provided
411- # if template:
412- # try:
413- # # Load and process the template
414- # config_data = load_and_process_template(
415- # template, interactive=not non_interactive, template_vars=template_var_dict
416- # )
417-
418- # # Update kwargs with config file data
419- # # Only update if the value wasn't explicitly provided on command line
420- # for key, value in config_data.items():
421- # if key not in kwargs or kwargs[key] is None:
422- # kwargs[key] = value
423-
424- # except Exception as e:
425- # echo.echo_critical(f'Error processing template: {e}')
426-
427- # # Check for existing computer
428- # if kwargs.get('label') and kwargs['label'] in get_computer_names():
429- # echo.echo_critical(
430- # 'A computer called {c} already exists. '
431- # 'Use "verdi computer duplicate {c}" to set up a new '
432- # 'computer starting from the settings of {c}.'.format(c=kwargs['label'])
433- # )
434-
435- # # Convert entry points to their names
436- # if kwargs.get('transport'):
437- # kwargs['transport'] = kwargs['transport'].name
438- # if kwargs.get('scheduler'):
439- # kwargs['scheduler'] = kwargs['scheduler'].name
440-
441- # computer_builder = ComputerBuilder(**kwargs)
442- # try:
443- # computer = computer_builder.new()
444- # except (ComputerBuilder.ComputerValidationError, ValidationError) as e:
445- # echo.echo_critical(f'{type(e).__name__}: {e}')
446-
447- # try:
448- # computer.store()
449- # except ValidationError as err:
450- # echo.echo_critical(f'unable to store the computer: {err}. Exiting...')
451- # else:
452- # echo.echo_success(f'Computer<{computer.pk}> {computer.label} created')
453-
454- # echo.echo_report('Note: before the computer can be used, it has to be configured with the command:')
455-
456- # profile = ctx.obj['profile']
457- # echo.echo_report(f' verdi -p {profile.name} computer configure {computer.transport_type} {computer.label}')
458-
459-
460348@verdi_computer .command ('duplicate' )
461349@arguments .COMPUTER (callback = set_computer_builder )
462350@options_computer .LABEL (contextual_default = partial (get_parameter_default , 'label' ))
0 commit comments