Skip to content

Commit 516a6df

Browse files
Discard direct orm import from cmdline package
1 parent 98af554 commit 516a6df

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/aiida/cmdline/commands/cmd_code.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212
import warnings
1313
from collections import defaultdict
1414
from functools import partial
15-
from typing import Any
15+
from typing import TYPE_CHECKING, Any
1616

1717
import click
1818

19-
from aiida import orm
2019
from aiida.cmdline.commands.cmd_data.cmd_export import data_export
2120
from aiida.cmdline.commands.cmd_verdi import verdi
2221
from aiida.cmdline.groups.dynamic import DynamicEntryPointCommandGroup
@@ -27,13 +26,16 @@
2726
from aiida.cmdline.utils.decorators import with_dbenv
2827
from aiida.common import exceptions
2928

29+
if TYPE_CHECKING:
30+
from aiida.orm import Code
31+
3032

3133
@verdi.group('code')
3234
def verdi_code():
3335
"""Setup and manage codes."""
3436

3537

36-
def create_code(ctx: click.Context, cls: orm.Code, **kwargs) -> None:
38+
def create_code(ctx: click.Context, cls: Code, **kwargs) -> None:
3739
"""Create a new `Code` instance."""
3840
try:
3941
Model = cls.Model.as_input_model()

src/aiida/cmdline/groups/dynamic.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import click
1010

11-
from aiida import orm
1211
from aiida.common import exceptions
1312
from aiida.plugins.entry_point import ENTRY_POINT_GROUP_FACTORY_MAPPING, get_entry_point_names
1413
from aiida.plugins.factories import BaseFactory
@@ -98,7 +97,7 @@ def call_command(self, ctx: click.Context, cls: t.Any, non_interactive: bool, **
9897

9998
if hasattr(cls, 'Model'):
10099
# The plugin defines a pydantic model: use it to validate the provided arguments
101-
Model = cls.Model.as_input_model() if issubclass(cls, orm.Entity) else cls.Model
100+
Model = cls.Model.as_input_model() if hasattr(cls.Model, 'as_input_model') else cls.Model
102101
try:
103102
Model(**kwargs)
104103
except ValidationError as exception:
@@ -170,7 +169,7 @@ def list_options(self, entry_point: str) -> list[t.Callable[[FC], FC]]:
170169
options_spec = self.factory(entry_point).get_cli_options() # type: ignore[union-attr]
171170
return [self.create_option(*item) for item in options_spec]
172171

173-
Model = cls.Model.as_input_model() if issubclass(cls, orm.Entity) else cls.Model
172+
Model = cls.Model.as_input_model() if hasattr(cls.Model, 'as_input_model') else cls.Model
174173

175174
options_spec = {}
176175

0 commit comments

Comments
 (0)