Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
GDYendell committed Oct 18, 2024
1 parent b34b112 commit d970bc4
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 30 deletions.
112 changes: 84 additions & 28 deletions schemas/pvi.device.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,18 @@
"description": "Reference to another Device.",
"properties": {
"name": {
"description": "PascalCase name to uniquely identify",
"pattern": "^([A-Z][a-z0-9]*)*$",
"title": "Name",
"type": "string"
"anyOf": [
{
"pattern": "^([A-Z][a-z0-9]*)*$",
"type": "string"
},
{
"pattern": "^\\d*$",
"type": "string"
}
],
"description": "PascalCase name or number to uniquely identify",
"title": "Name"
},
"label": {
"anyOf": [
Expand Down Expand Up @@ -284,10 +292,18 @@
"description": "Group of child components in a Layout",
"properties": {
"name": {
"description": "PascalCase name to uniquely identify",
"pattern": "^([A-Z][a-z0-9]*)*$",
"title": "Name",
"type": "string"
"anyOf": [
{
"pattern": "^([A-Z][a-z0-9]*)*$",
"type": "string"
},
{
"pattern": "^\\d*$",
"type": "string"
}
],
"description": "PascalCase name or number to uniquely identify",
"title": "Name"
},
"label": {
"anyOf": [
Expand Down Expand Up @@ -487,10 +503,18 @@
"description": "Read-only `Signal` backed by a single PV.",
"properties": {
"name": {
"description": "PascalCase name to uniquely identify",
"pattern": "^([A-Z][a-z0-9]*)*$",
"title": "Name",
"type": "string"
"anyOf": [
{
"pattern": "^([A-Z][a-z0-9]*)*$",
"type": "string"
},
{
"pattern": "^\\d*$",
"type": "string"
}
],
"description": "PascalCase name or number to uniquely identify",
"title": "Name"
},
"label": {
"anyOf": [
Expand Down Expand Up @@ -584,10 +608,18 @@
"description": "Read/write `Signal` backed by a demand PV and a readback PV.\n\nOne PV can be used as both a demand and a readback by leaving `read_pv` unset. In\nthis case no readback widget will be displayed unless `read_widget` is set.\n\nIf `read_pv` is set and `read_widget` is not, a `TextRead` widget will be used.",
"properties": {
"name": {
"description": "PascalCase name to uniquely identify",
"pattern": "^([A-Z][a-z0-9]*)*$",
"title": "Name",
"type": "string"
"anyOf": [
{
"pattern": "^([A-Z][a-z0-9]*)*$",
"type": "string"
},
{
"pattern": "^\\d*$",
"type": "string"
}
],
"description": "PascalCase name or number to uniquely identify",
"title": "Name"
},
"label": {
"anyOf": [
Expand Down Expand Up @@ -715,10 +747,18 @@
"description": "Reference to another Signal with the same name in this Device.",
"properties": {
"name": {
"description": "PascalCase name to uniquely identify",
"pattern": "^([A-Z][a-z0-9]*)*$",
"title": "Name",
"type": "string"
"anyOf": [
{
"pattern": "^([A-Z][a-z0-9]*)*$",
"type": "string"
},
{
"pattern": "^\\d*$",
"type": "string"
}
],
"description": "PascalCase name or number to uniquely identify",
"title": "Name"
},
"label": {
"anyOf": [
Expand Down Expand Up @@ -767,10 +807,18 @@
"description": "Write-only `Signal` backed by a single PV.",
"properties": {
"name": {
"description": "PascalCase name to uniquely identify",
"pattern": "^([A-Z][a-z0-9]*)*$",
"title": "Name",
"type": "string"
"anyOf": [
{
"pattern": "^([A-Z][a-z0-9]*)*$",
"type": "string"
},
{
"pattern": "^\\d*$",
"type": "string"
}
],
"description": "PascalCase name or number to uniquely identify",
"title": "Name"
},
"label": {
"anyOf": [
Expand Down Expand Up @@ -857,10 +905,18 @@
"description": "`SignalW` that can be triggered to write a fixed value to a PV.",
"properties": {
"name": {
"description": "PascalCase name to uniquely identify",
"pattern": "^([A-Z][a-z0-9]*)*$",
"title": "Name",
"type": "string"
"anyOf": [
{
"pattern": "^([A-Z][a-z0-9]*)*$",
"type": "string"
},
{
"pattern": "^\\d*$",
"type": "string"
}
],
"description": "PascalCase name or number to uniquely identify",
"title": "Name"
},
"label": {
"anyOf": [
Expand Down
8 changes: 6 additions & 2 deletions src/pvi/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def enforce_pascal_case(s: str) -> str:
return s[0].upper() + s[1:]


PascalStr = Annotated[str, Field(pattern="^([A-Z][a-z0-9]*)*$")]
PascalStr = Annotated[str, Field(pattern=r"^([A-Z][a-z0-9]*)*$")]
NumberStr = Annotated[str, Field(pattern=r"^\d*$")]


class TextFormat(Enum):
Expand Down Expand Up @@ -286,7 +287,10 @@ class SubScreen(Layout):


class Named(TypedModel):
name: PascalStr = Field(description="PascalCase name to uniquely identify")
name: Annotated[
PascalStr | NumberStr,
Field(description="PascalCase name or number to uniquely identify"),
]


class Component(Named):
Expand Down

0 comments on commit d970bc4

Please sign in to comment.