Skip to content

Commit

Permalink
verdi code show: Add missing code attributes (#5916)
Browse files Browse the repository at this point in the history
The implementation of `verdi code show` hardcoded the attributes to show.
This led to not all attributes always being shown, since the hard-coded
attributes were just those shared between all `AbstractCode` subclasses.
However, the subclasses have specific attributes that are important as
well.

The command now uses the `get_cli_options` classmethod to get a list
of all attributes relevant to the code type. In principle, each of these
have a corresponding property on the class to retrieve the associated
value so we can use `getattr` to retrieve it. There are exceptions, such
as the `filepath_files` option for the `PortableCode` which is only
needed during setup and not stored permanently, so the `AttributeError`
that can be raised is caught and ignored.

Finally, there are three attributes that are still hard-coded, PK, UUID
and the `entry_point`, since these are not actually part of the list
returned by `get_cli_options` but are shared by all code types and are
useful to display.
  • Loading branch information
ConradJohnston authored Mar 8, 2023
1 parent 35f95a7 commit 68cc062
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions aiida/cmdline/commands/cmd_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,12 @@ def show(code):
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.default_calc_job_plugin])
table.append(['Prepend text', code.prepend_text])
table.append(['Append text', code.append_text])

table.append(['Type', code.entry_point.name])
for key in code.get_cli_options().keys():
try:
table.append([key.capitalize().replace('_', ' '), getattr(code, key)])
except AttributeError:
continue
if is_verbose():
table.append(['Calculations', len(code.base.links.get_outgoing().all())])

Expand Down

0 comments on commit 68cc062

Please sign in to comment.