Skip to content

Commit c66da3c

Browse files
committed
Defer import in conversion step too
1 parent f57e5c9 commit c66da3c

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/optimade_maker/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
__version__ = "0.1.0"
1111

1212
from pathlib import Path
13-
from typing import TYPE_CHECKING, Optional
13+
from typing import TYPE_CHECKING, Optional, Union
1414

1515
import yaml
1616
from pydantic import BaseModel, Field
@@ -61,7 +61,7 @@ class PropertyDefinition(BaseModel):
6161
"`name` will be used for the field in the actual OPTIMADE API."
6262
),
6363
)
64-
aiida_query: Optional[list[AiidaQueryItem]] = Field(
64+
aiida_query: Optional[list["AiidaQueryItem"]] = Field(
6565
None,
6666
description=("A list of AiiDA QueryBuilder steps to retrieve this property."),
6767
)
@@ -88,7 +88,7 @@ class EntryConfig(BaseModel):
8888
entry_type: str = Field(
8989
description="The OPTIMADE entry type, e.g. `structures` or `references`."
9090
)
91-
entry_paths: list[ParsedFiles] | AiidaEntryPath = Field(
91+
entry_paths: Union[list[ParsedFiles], "AiidaEntryPath"] = Field(
9292
description=(
9393
"A list of paths patterns to parse, provided relative to the top-level of the archive entry, "
9494
"after any compressed locations have been decompressed. Supports Python glob syntax for wildcards."

src/optimade_maker/convert.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
from optimade.models import EntryInfoResource, EntryResource
1717
from optimade.server.schemas import ENTRY_INFO_SCHEMAS, retrieve_queryable_properties
1818

19-
from .aiida_plugin import AiidaEntryPath, construct_entries_from_aiida
19+
try:
20+
from .aiida_plugin import AiidaEntryPath, construct_entries_from_aiida
21+
except ImportError:
22+
pass
2023
from .config import Config, EntryConfig, JSONLConfig, ParsedFiles, PropertyDefinition
2124

2225
PROVIDER_PREFIX = os.environ.get("OPTIMAKE_PROVIDER_PREFIX", "optimake")
@@ -613,11 +616,15 @@ def construct_entries(
613616
provider_prefix: str,
614617
limit: int | None = None,
615618
) -> dict[str, dict]:
616-
if isinstance(entry_config.entry_paths, AiidaEntryPath):
619+
try:
620+
is_aiida_archive = isinstance(entry_config.entry_paths, AiidaEntryPath)
621+
except Exception:
622+
is_aiida_archive = False
623+
624+
if is_aiida_archive:
617625
optimade_entries = construct_entries_from_aiida(
618626
archive_path, entry_config, provider_prefix
619627
)
620-
621628
else:
622629
optimade_entries = construct_entries_from_files(
623630
archive_path, entry_config, provider_prefix, limit=limit

0 commit comments

Comments
 (0)