Skip to content

Commit

Permalink
final changes from Garys review
Browse files Browse the repository at this point in the history
  • Loading branch information
gilesknap committed May 14, 2024
1 parent d11b619 commit e75acab
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/ibek/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class EntityPVI(BaseSettings):
pv_prefix: str = Field("", description='PV prefix for PVI PV - e.g. "$(P)"')


class Definition(BaseSettings):
class EntityDefinition(BaseSettings):
"""
A single definition of a class of Entity that an IOC instance may instantiate
"""
Expand Down
8 changes: 3 additions & 5 deletions src/ibek/entity_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from .args import EnumArg, IdArg, ObjectArg
from .ioc import Entity, EnumVal, clear_entity_model_ids, get_entity_by_id
from .support import Definition, Support
from .support import EntityDefinition, Support
from .utils import UTILS


Expand Down Expand Up @@ -50,7 +50,7 @@ def make_entity_models(self, definition_yaml: List[Path]) -> List[Entity]:
return self._entity_models.values()

def _make_entity_model(
self, definition: Definition, support: Support
self, definition: EntityDefinition, support: Support
) -> Type[Entity]:
"""
Create an Entity Model from a Definition instance and a Support instance.
Expand Down Expand Up @@ -100,8 +100,7 @@ def lookup_instance(cls, id):
else:
# arg.type is str, int, float, etc.
arg_type = getattr(builtins, arg.type)
default = getattr(arg, "default", None)
add_arg(arg.name, arg_type, arg.description, default)
add_arg(arg.name, arg_type, arg.description, getattr(arg, "default"))

# add in the calculated values Jinja Templates as Fields in the Entity
for value in definition.values:
Expand All @@ -118,7 +117,6 @@ def lookup_instance(cls, id):
__validators__=validators,
__base__=Entity,
) # type: ignore
entity_cls.model_rebuild()

# add a link back to the Definition Instance that generated this Entity Class
entity_cls.__definition__ = definition
Expand Down
4 changes: 2 additions & 2 deletions src/ibek/ioc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
)

from .args import IdArg
from .definition import Definition
from .definition import EntityDefinition
from .globals import BaseSettings
from .utils import UTILS

Expand Down Expand Up @@ -53,7 +53,7 @@ class Entity(BaseSettings):
entity_enabled: bool = Field(
description="enable or disable this entity instance", default=True
)
__definition__: Definition
__definition__: EntityDefinition

@model_validator(mode="after")
def add_ibek_attributes(self):
Expand Down
2 changes: 0 additions & 2 deletions src/ibek/ioc_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,4 @@ class NewIOC(IOC):
description="List of entities this IOC instantiates"
)

NewIOC.model_rebuild()

return NewIOC
4 changes: 2 additions & 2 deletions src/ibek/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from pydantic import Field

from .definition import Definition
from .definition import EntityDefinition
from .globals import BaseSettings


Expand All @@ -21,7 +21,7 @@ class Support(BaseSettings):
"""

module: str = Field(description="Support module name, normally the repo name")
defs: Sequence[Definition] = Field(
defs: Sequence[EntityDefinition] = Field(
description="The definitions an IOC can create using this module"
)

Expand Down
6 changes: 3 additions & 3 deletions tests/samples/schemas/ibek.support.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"title": "Database",
"type": "object"
},
"Definition": {
"EntityDefinition": {
"additionalProperties": false,
"description": "A single definition of a class of Entity that an IOC instance may instantiate",
"properties": {
Expand Down Expand Up @@ -242,7 +242,7 @@
"name",
"description"
],
"title": "Definition",
"title": "EntityDefinition",
"type": "object"
},
"EntityPVI": {
Expand Down Expand Up @@ -651,7 +651,7 @@
"defs": {
"description": "The definitions an IOC can create using this module",
"items": {
"$ref": "#/$defs/Definition"
"$ref": "#/$defs/EntityDefinition"
},
"title": "Defs",
"type": "array"
Expand Down
6 changes: 3 additions & 3 deletions tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from ibek.commands import semver_compare
from ibek.ioc import id_to_entity
from ibek.ioc_factory import IocFactory
from ibek.support import Definition, Support
from ibek.support import EntityDefinition, Support


def test_object_references(entity_factory):
Expand All @@ -16,12 +16,12 @@ def test_object_references(entity_factory):
support = Support(
module="mymodule",
defs=[
Definition(
EntityDefinition(
name="port",
description="a port",
args=[IdArg(name="name", description="an id")],
),
Definition(
EntityDefinition(
name="device",
description="a device",
args=[ObjectArg(name="port", description="the port")],
Expand Down

0 comments on commit e75acab

Please sign in to comment.