Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ requires-python = ">=3.9"
dependencies = [
"numpy",
"scipy",
"node-graph==0.3.10",
"node-graph==0.3.11",
"node-graph-widget>=0.0.5",
"aiida-core~=2.6",
"cloudpickle",
Expand Down Expand Up @@ -140,6 +140,9 @@ workgraph = "aiida_workgraph.cli.cmd_workgraph:workgraph"
[project.entry-points."aiida_workgraph.type_mapping"]
"workgraph.builtins_mapping" = "aiida_workgraph.orm.mapping:builtins_type_mapping"

[project.entry-points."aiida_workgraph.type_promotion"]
"workgraph.builtins_mapping" = "aiida_workgraph.orm.mapping:TYPE_PROMOTIONS"

[tool.flit.sdist]
exclude = ["docs/", "tests/"]

Expand Down
31 changes: 5 additions & 26 deletions src/aiida_workgraph/orm/mapping.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from aiida import orm
import importlib.metadata
from typing import Any

builtins_type_mapping = {
Expand All @@ -22,28 +21,8 @@
Any: "workgraph.any",
}


# Load additional mapping from entry points
def load_custom_type_mapping():
"""Loads custom type mapping from plugins."""
type_mapping = {}

entry_points = importlib.metadata.entry_points()

if hasattr(entry_points, "select"): # Python 3.10+
group_entries = entry_points.select(group="aiida_workgraph.type_mapping")
else: # Python 3.9 and earlier
group_entries = entry_points.get("aiida_workgraph.type_mapping", [])

for entry_point in group_entries:
try:
# Load the function or dict and merge with default mapping
custom_mapping = entry_point.load()
if isinstance(custom_mapping, dict):
type_mapping.update(custom_mapping)
except Exception as e:
print(f"Failed to load type mapping from {entry_point.name}: {e}")
return type_mapping


type_mapping = load_custom_type_mapping()
TYPE_PROMOTIONS: set[tuple[str, str]] = {
("workgraph.bool", "workgraph.int"),
("workgraph.bool", "workgraph.float"),
("workgraph.int", "workgraph.float"),
}
3 changes: 3 additions & 0 deletions src/aiida_workgraph/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
socket_group="aiida_workgraph.socket",
property_group="aiida_workgraph.property",
type_mapping_group="aiida_workgraph.type_mapping",
type_promotion_group="aiida_workgraph.type_promotion",
identifier_prefix="workgraph",
)

type_mapping = registry_hub.type_mapping
2 changes: 1 addition & 1 deletion src/aiida_workgraph/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
)

from aiida_workgraph.property import TaskProperty
from aiida_workgraph.orm.mapping import type_mapping
from aiida_workgraph.registry import type_mapping


class TaskSocket(NodeSocket):
Expand Down
2 changes: 1 addition & 1 deletion src/aiida_workgraph/socket_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
BaseSocketSpecAPI,
BaseSpecInferAPI,
)
from aiida_workgraph.orm.mapping import type_mapping
from aiida_workgraph.registry import type_mapping
from aiida.engine import Process
from aiida.engine.processes.process_spec import ProcessSpec
from plumpy.ports import Port, PortNamespace
Expand Down
2 changes: 1 addition & 1 deletion src/aiida_workgraph/workgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from node_graph.config import BUILTIN_NODES
from node_graph.collection import NodeCollection
from node_graph.socket import BaseSocket, NodeSocketNamespace
from aiida_workgraph.orm.mapping import type_mapping
from aiida_workgraph.registry import type_mapping
from aiida_workgraph.socket_spec import SocketSpecAPI
from node_graph.error_handler import ErrorHandlerSpec

Expand Down
2 changes: 1 addition & 1 deletion tests/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_type_mapping(data_type, data, identifier) -> None:
"""Test the mapping of data types to socket types."""

# Ensure mapping are up-to-date
from aiida_workgraph.orm.mapping import type_mapping
from aiida_workgraph.registry import type_mapping

assert (
identifier in type_mapping.values()
Expand Down
8 changes: 4 additions & 4 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.