-
Notifications
You must be signed in to change notification settings - Fork 260
Refactor the Code data plugin
#5510
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
Changes from all commits
82c45bb
aa1e324
1ec894a
4f79e00
0f3dc5c
abed94f
2d3cf68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,10 +14,11 @@ | |
| import tabulate | ||
|
|
||
| from aiida.cmdline.commands.cmd_verdi import verdi | ||
| from aiida.cmdline.groups.dynamic import DynamicEntryPointCommandGroup | ||
| from aiida.cmdline.params import arguments, options | ||
| from aiida.cmdline.params.options.commands import code as options_code | ||
| from aiida.cmdline.utils import echo | ||
| from aiida.cmdline.utils.decorators import with_dbenv | ||
| from aiida.cmdline.utils.decorators import deprecated_command, with_dbenv | ||
| from aiida.common import exceptions | ||
|
|
||
|
|
||
|
|
@@ -26,6 +27,11 @@ def verdi_code(): | |
| """Setup and manage codes.""" | ||
|
|
||
|
|
||
| @verdi_code.group('create', cls=DynamicEntryPointCommandGroup, entry_point_name_filter=r'core\.code\..*') | ||
| def code_create(): | ||
| """Create a new code.""" | ||
|
|
||
|
|
||
| def get_default(key, ctx): | ||
| """ | ||
| Get the default argument using a user instance property | ||
|
|
@@ -79,6 +85,7 @@ def set_code_builder(ctx, param, value): | |
| @options.CONFIG_FILE() | ||
| @click.pass_context | ||
| @with_dbenv() | ||
| @deprecated_command('This command will be removed soon, use `verdi code create` instead.') | ||
| def setup_code(ctx, non_interactive, **kwargs): | ||
| """Setup a new code.""" | ||
| from aiida.orm.utils.builders.code import CodeBuilder | ||
|
|
@@ -106,7 +113,6 @@ def setup_code(ctx, non_interactive, **kwargs): | |
| except Exception as exception: # pylint: disable=broad-except | ||
| echo.echo_critical(f'Unable to store the Code: {exception}') | ||
|
|
||
| code.reveal() | ||
| echo.echo_success(f'Code<{code.pk}> {code.full_label} created') | ||
|
|
||
|
|
||
|
|
@@ -121,9 +127,11 @@ def code_test(code): | |
| * Whether the remote executable exists. | ||
|
|
||
| """ | ||
| if not code.is_local(): | ||
| from aiida.orm import InstalledCode | ||
|
|
||
| if isinstance(code, InstalledCode): | ||
| try: | ||
| code.validate_remote_exec_path() | ||
| code.validate_filepath_executable() | ||
| except exceptions.ValidationError as exception: | ||
| echo.echo_critical(f'validation failed: {exception}') | ||
|
|
||
|
|
@@ -163,10 +171,11 @@ def code_duplicate(ctx, code, non_interactive, **kwargs): | |
| kwargs['code_type'] = CodeBuilder.CodeType.STORE_AND_UPLOAD | ||
|
|
||
| if kwargs.pop('hide_original'): | ||
| code.hide() | ||
| code.is_hidden = True | ||
|
|
||
| # Convert entry point to its name | ||
| kwargs['input_plugin'] = kwargs['input_plugin'].name | ||
| if kwargs['input_plugin']: | ||
| kwargs['input_plugin'] = kwargs['input_plugin'].name | ||
|
|
||
| code_builder = ctx.code_builder | ||
| for key, value in kwargs.items(): | ||
|
|
@@ -175,7 +184,7 @@ def code_duplicate(ctx, code, non_interactive, **kwargs): | |
|
|
||
| try: | ||
| new_code.store() | ||
| new_code.reveal() | ||
| new_code.is_hidden = False | ||
| except ValidationError as exception: | ||
| echo.echo_critical(f'Unable to store the Code: {exception}') | ||
|
|
||
|
|
@@ -188,31 +197,15 @@ def code_duplicate(ctx, code, non_interactive, **kwargs): | |
| def show(code): | ||
| """Display detailed information for a code.""" | ||
| from aiida.cmdline import is_verbose | ||
| from aiida.repository import FileType | ||
|
|
||
| table = [] | ||
| table.append(['PK', code.pk]) | ||
| table.append(['UUID', code.uuid]) | ||
| table.append(['Label', code.label]) | ||
| table.append(['Description', code.description]) | ||
| table.append(['Default plugin', code.get_input_plugin_name()]) | ||
|
|
||
| if code.is_local(): | ||
| table.append(['Type', 'local']) | ||
| table.append(['Exec name', code.get_execname()]) | ||
| table.append(['List of files/folders:', '']) | ||
| for obj in code.list_objects(): | ||
| if obj.file_type == FileType.DIRECTORY: | ||
| table.append(['directory', obj.name]) | ||
| else: | ||
| table.append(['file', obj.name]) | ||
| else: | ||
| table.append(['Type', 'remote']) | ||
| table.append(['Remote machine', code.get_remote_computer().label]) | ||
| table.append(['Remote absolute path', code.get_remote_exec_path()]) | ||
|
|
||
| table.append(['Prepend text', code.get_prepend_text()]) | ||
| table.append(['Append text', code.get_append_text()]) | ||
| table.append(['Default plugin', code.default_calc_job_plugin]) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this means less code information is shown by
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I removed it for now because it was hard-coding a bunch of stuff. But you are right, I think we might be able to get this behavior dynamically using the cli option definitions. There are some caveats though. As long as the cli options are stored as simple attributes, the automatic introspection may fail if there are more complex data types that are being returned, or they don't have a direct property to access it. |
||
| table.append(['Prepend text', code.prepend_text]) | ||
| table.append(['Append text', code.append_text]) | ||
|
|
||
| if is_verbose(): | ||
| table.append(['Calculations', len(code.base.links.get_outgoing().all())]) | ||
|
|
@@ -252,7 +245,7 @@ def _dry_run_callback(pks): | |
| def hide(codes): | ||
| """Hide one or more codes from `verdi code list`.""" | ||
| for code in codes: | ||
| code.hide() | ||
| code.is_hidden = True | ||
| echo.echo_success(f'Code<{code.pk}> {code.full_label} hidden') | ||
|
|
||
|
|
||
|
|
@@ -262,7 +255,7 @@ def hide(codes): | |
| def reveal(codes): | ||
| """Reveal one or more hidden codes in `verdi code list`.""" | ||
| for code in codes: | ||
| code.reveal() | ||
| code.is_hidden = False | ||
| echo.echo_success(f'Code<{code.pk}> {code.full_label} revealed') | ||
|
|
||
|
|
||
|
|
@@ -275,7 +268,7 @@ def relabel(code, label): | |
| old_label = code.full_label | ||
|
|
||
| try: | ||
| code.relabel(label) | ||
| code.label = label | ||
| except (TypeError, ValueError) as exception: | ||
| echo.echo_critical(f'invalid code label: {exception}') | ||
| else: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # -*- coding: utf-8 -*- | ||
| """Module with custom implementations of :class:`click.Group`.""" | ||
|
|
||
| # AUTO-GENERATED | ||
|
|
||
| # yapf: disable | ||
| # pylint: disable=wildcard-import | ||
|
|
||
| from .dynamic import * | ||
| from .verdi import * | ||
|
|
||
| __all__ = ( | ||
| 'DynamicEntryPointCommandGroup', | ||
| 'VerdiCommandGroup', | ||
| ) | ||
|
|
||
| # yapf: enable |
Uh oh!
There was an error while loading. Please reload this page.