Skip to content

Commit

Permalink
Merge pull request #84 from epics-containers/convert-name-handling
Browse files Browse the repository at this point in the history
Improvements to convert for pmac
  • Loading branch information
GDYendell authored Jan 30, 2024
2 parents b7ee8e9 + 962b199 commit c5d3202
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 14 deletions.
18 changes: 13 additions & 5 deletions src/pvi/_convert/_asyn_convert.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
from typing import Any, Optional, Type

from pvi.device import SignalR, SignalRW, SignalW
from pvi.device import SignalR, SignalRW, SignalW, enforce_pascal_case

from ._parameters import (
AsynParameter,
Expand Down Expand Up @@ -37,7 +37,7 @@ def model_post_init(self, __context: Any):
def get_parameter_name(self) -> Optional[str]:
# e.g. from: field(INP, "@asyn($(PORT),$(ADDR=0),$(TIMEOUT=1))FILE_PATH")
# extract: FILE_PATH
parameter_name_extractor = r"(?:@asyn\()(?:(?:\$\([^\)]*\)[,]*)*)(?:\))(\S+)"
parameter_name_extractor = r"@asyn\(.*\)(\S+)"
parameter_name = None
for k, v in self.fields.items():
if k == "INP" or k == "OUT":
Expand Down Expand Up @@ -76,7 +76,10 @@ class SettingPair(Parameter):

def generate_component(self) -> SignalRW:
asyn_cls = self.write_record.asyn_component_type()
component = asyn_cls(name=self.write_record.name)
component = asyn_cls(
name=enforce_pascal_case(self.write_record.name),
write_record=self.write_record.name,
)

return SignalRW(
name=component.name,
Expand All @@ -98,7 +101,9 @@ def generate_component(self) -> SignalR:
else:
name = self.read_record.name

component = asyn_cls(name=name, read_record=self.read_record.name)
component = asyn_cls(
name=enforce_pascal_case(name), read_record=self.read_record.name
)

return SignalR(
name=component.name,
Expand All @@ -113,7 +118,10 @@ class Action(Parameter):
def generate_component(self) -> SignalW:
asyn_cls = self.write_record.asyn_component_type()

component = asyn_cls(name=self.write_record.name)
component = asyn_cls(
name=enforce_pascal_case(self.write_record.name),
write_record=self.write_record.name,
)

return SignalW(
name=component.name,
Expand Down
7 changes: 7 additions & 0 deletions src/pvi/_convert/_template_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ def _extract_infos(self, fields_str: str) -> List[Tuple[str, str]]:

def _create_asyn_record(self, record_str: str) -> AsynRecord:
record_type, record_name, record_fields = self._parse_record(record_str)

if record_type == "motor":
newline = "\n"
raise RecordError(
f"Record `{record_str.split(newline)[0]}` is type motor - ignoring"
)

fields = dict(self._extract_fields(record_fields))
info = dict(self._extract_infos(record_fields))
record = AsynRecord(
Expand Down
4 changes: 2 additions & 2 deletions src/pvi/_convert/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
def extract_device_and_parent_class(header_text: str) -> Tuple[str, str]:
# e.g. extract 'NDPluginDriver' and 'asynNDArrayDriver' from
# class epicsShareClass NDPluginDriver : public asynNDArrayDriver, public epicsThreadRunable { # noqa
class_extractor = re.compile(r"class.* (\w+) : \w+ (\w+).*")
class_extractor = re.compile(r"class.*\s+(\w+)\s+:\s+\w+\s+(\w+).*")
match = re.search(class_extractor, header_text)
assert match, "Can't find classes"
assert match, "Can't find device class and parent class in header file"
classname, parent = match.groups()
return classname, parent

Expand Down
6 changes: 3 additions & 3 deletions src/pvi/_format/bob.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ def set(
add_combo_box_items(t_copy, combo_box)
case ("table", TableRead() | TableWrite() as table):
add_table_columns(t_copy, table)
case (
("textentry", TextWrite(format=format))
| ("textupdate", TextRead(format=format))
case ("textentry", TextWrite(format=format)) | (
"textupdate",
TextRead(format=format),
) if format is not None:
add_format(t_copy, BOB_TEXT_FORMATS[format])

Expand Down
6 changes: 2 additions & 4 deletions src/pvi/_yaml_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@


@overload
def type_first(tree: dict) -> dict:
...
def type_first(tree: dict) -> dict: ...


@overload
def type_first(tree: list) -> list:
...
def type_first(tree: list) -> list: ...


def type_first(tree: dict | list) -> dict | list:
Expand Down

0 comments on commit c5d3202

Please sign in to comment.