Skip to content

Commit

Permalink
CodeBuilder: do not rely on type of input_plugin_name
Browse files Browse the repository at this point in the history
The `CodeBuilder` could receive the `input_plugin_name` keyword argument
as an `EntryPoint` from the `verdi code setup/duplicate` commands, so it
included a switch to get the entry point name from it.

Due to a bug in setuptools, the type of the `EntryPoint` can change
under certain circumstances and so the `isinstance` check on the entry
point does not hit. This causes the `EntryPoint` to be passed to the
`Code.set_input_plugin_name` method, which does not check the type and
casts the argument to `str`. However, the `__str__` of `EntryPoint` does
not return just the name, but a more verbose representation. This will
cause the `Code` to be unusable.

The conversion of the `EntryPoint` to its name in the `CodeBuilder is
removed and instead the CLI commands are responsible for passing the
string entry point name.

Ideally, `Code.set_input_plugin_name` is updated to only accept `str`
arguments and remove the cast. But this would be a breaking change and
so is not done for now.
  • Loading branch information
sphuber committed Feb 16, 2022
1 parent bc661db commit 1f99246
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 6 additions & 0 deletions aiida/cmdline/commands/cmd_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ def setup_code(ctx, non_interactive, **kwargs):
else:
kwargs['code_type'] = CodeBuilder.CodeType.STORE_AND_UPLOAD

# Convert entry point to its name
kwargs['input_plugin'] = kwargs['input_plugin'].name

code_builder = CodeBuilder(**kwargs)

try:
Expand Down Expand Up @@ -160,6 +163,9 @@ def code_duplicate(ctx, code, non_interactive, **kwargs):
if kwargs.pop('hide_original'):
code.hide()

# Convert entry point to its name
kwargs['input_plugin'] = kwargs['input_plugin'].name

code_builder = ctx.code_builder
for key, value in kwargs.items():
setattr(code_builder, key, value)
Expand Down
5 changes: 0 additions & 5 deletions aiida/orm/utils/builders/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import enum
import os

import importlib_metadata

from aiida.cmdline.utils.decorators import with_dbenv
from aiida.common.utils import ErrorAccumulator

Expand Down Expand Up @@ -155,9 +153,6 @@ def _set_code_attr(self, key, value):
Checks compatibility with other code attributes.
"""
if key == 'input_plugin' and isinstance(value, importlib_metadata.EntryPoint):
value = value.name

if key == 'description' and value is None:
value = ''

Expand Down

0 comments on commit 1f99246

Please sign in to comment.