Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement better typing in EpicsName PandAName PviName #90

Open
evalott100 opened this issue Jan 25, 2024 · 0 comments
Open

Implement better typing in EpicsName PandAName PviName #90

evalott100 opened this issue Jan 25, 2024 · 0 comments
Assignees

Comments

@evalott100
Copy link
Contributor

Currently we define types for each of the above names:

# EPICS format, i.e. ":" dividers
EpicsName = NewType("EpicsName", str)
# PandA format, i.e. "." dividers
PandAName = NewType("PandAName", str)
# No dividers and PascalCase
PviName = NewType("PviName", str)
def panda_to_epics_name(field_name: PandAName) -> EpicsName:
"""Convert PandA naming convention to EPICS convention. This module defaults to
EPICS names internally, only converting back to PandA names when necessary."""
return EpicsName(field_name.replace(".", ":"))
def epics_to_panda_name(field_name: EpicsName) -> PandAName:
"""Convert EPICS naming convention to PandA convention. This module defaults to
EPICS names internally, only converting back to PandA names when necessary."""
return PandAName(field_name.replace(":", "."))
def epics_to_pvi_name(field_name: EpicsName) -> PviName:
"""Converts EPICS naming convention to PVI naming convention.
For example PANDA:PCAP:TRIG_EDGE -> TrigEdge."""
relevant_section = field_name.split(":")[-1]
words = relevant_section.replace("-", "_").split("_")
capitalised_word = "".join(word.capitalize() for word in words)
# We don't want to allow any non-alphanumeric characters.
formatted_word = re.search(r"[A-Za-z0-9]+", capitalised_word)
assert formatted_word
return PviName(formatted_word.group())

But when used at runtime we don't have restrictions, and everything is a str.

We should turn these types into pydantic BaseModel and validate each against a regex schema on initialisation.

@evalott100 evalott100 self-assigned this Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant