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

Tidier global entity #15

Merged
merged 11 commits into from
Dec 4, 2024
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
2 changes: 1 addition & 1 deletion .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Changes here will be overwritten by Copier
_commit: 2.3.0
_commit: 2.5.0
_src_path: gh:diamondlightsource/python-copier-template
author_email: [email protected]
author_name: Giles Knap
Expand Down
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ It is recommended that developers use a [vscode devcontainer](https://code.visua

This project was created using the [Diamond Light Source Copier Template](https://github.com/DiamondLightSource/python-copier-template) for Python projects.

For more information on common tasks like setting up a developer environment, running the tests, and setting a pre-commit hook, see the template's [How-to guides](https://diamondlightsource.github.io/python-copier-template/2.3.0/how-to.html).
For more information on common tasks like setting up a developer environment, running the tests, and setting a pre-commit hook, see the template's [How-to guides](https://diamondlightsource.github.io/python-copier-template/2.5.0/how-to.html).
17 changes: 9 additions & 8 deletions .github/pages/make_switcher.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
"""Make switcher.json to allow docs to switch between different versions."""

import json
import logging
from argparse import ArgumentParser
from pathlib import Path
from subprocess import CalledProcessError, check_output
from typing import Optional


def report_output(stdout: bytes, label: str) -> list[str]:
"""Print and return something received frm stdout."""
ret = stdout.decode().strip().split("\n")
print(f"{label}: {ret}")
return ret
Expand All @@ -24,7 +26,7 @@ def get_sorted_tags_list() -> list[str]:
return report_output(stdout, "Tags list")


def get_versions(ref: str, add: Optional[str]) -> list[str]:
def get_versions(ref: str, add: str | None) -> list[str]:
"""Generate the file containing the list of all GitHub Pages builds."""
# Get the directories (i.e. builds) from the GitHub Pages branch
try:
Expand Down Expand Up @@ -53,21 +55,20 @@ def get_versions(ref: str, add: Optional[str]) -> list[str]:
return versions


def write_json(path: Path, repository: str, versions: str):
def write_json(path: Path, repository: str, versions: list[str]):
"""Write the JSON switcher to path."""
org, repo_name = repository.split("/")
pages_url = f"https://{org}.github.io"
if repo_name != f"{org}.github.io":
# Only add the repo name if it isn't the source for the org pages site
pages_url += f"/{repo_name}"
struct = [
{"version": version, "url": f"{pages_url}/{version}/"} for version in versions
{"version": version, "url": f"https://{org}.github.io/{repo_name}/{version}/"}
for version in versions
]
text = json.dumps(struct, indent=2)
print(f"JSON switcher:\n{text}")
path.write_text(text, encoding="utf-8")


def main(args=None):
"""Parse args and write switcher."""
parser = ArgumentParser(
description="Make a versions.json file from gh-pages directories"
)
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ jobs:

- name: Publish to PyPI using trusted publishing
uses: pypa/gh-action-pypi-publish@release/v1
with:
attestations: false
2 changes: 1 addition & 1 deletion .github/workflows/_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Create GitHub Release
# We pin to the SHA, not the tag, for security reasons.
# https://docs.github.com/en/actions/learn-github-actions/security-hardening-for-github-actions#using-third-party-actions
uses: softprops/action-gh-release@c062e08bd532815e2082a85e87e3ef29c3e6d191 # v2.0.8
uses: softprops/action-gh-release@e7a8f85e1c67a31e6ed99a94b41bd0b71bbee6b8 # v2.0.9
with:
prerelease: ${{ contains(github.ref_name, 'a') || contains(github.ref_name, 'b') || contains(github.ref_name, 'rc') }}
files: "*"
Expand Down
23 changes: 0 additions & 23 deletions .vscode/launch.json

This file was deleted.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# The devcontainer should use the developer target and run as root with podman
# or docker with user namespaces.
ARG PYTHON_VERSION=3.11
FROM python:${PYTHON_VERSION} as developer
FROM python:${PYTHON_VERSION} AS developer

# Add any system dependencies for the developer/build environment here
RUN apt-get update && apt-get install -y --no-install-recommends \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![CI](https://github.com/epics-containers/builder2ibek/actions/workflows/ci.yml/badge.svg)](https://github.com/epics-containers/builder2ibek/actions/workflows/ci.yml)
[![Coverage](https://codecov.io/gh/epics-containers/builder2ibek/branch/main/graph/badge.svg)](https://codecov.io/gh/epics-containers/builder2ibek)
[![PyPI](https://img.shields.io/pypi/v/builder2ibek.svg)](https://pypi.org/project/builder2ibek)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)

# builder2ibek

Expand Down
1 change: 0 additions & 1 deletion src/builder2ibek/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,5 @@ def beamline(
raise typer.Exit(code=1)


# test with: python -m builder2ibek
if __name__ == "__main__":
cli()
31 changes: 13 additions & 18 deletions src/builder2ibek/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing import Any

from builder2ibek.builder import Builder, Element
from builder2ibek.converters.globalHandler import globalHandler
from builder2ibek.moduleinfos import module_infos
from builder2ibek.types import Entity, Generic_IOC

Expand Down Expand Up @@ -51,27 +50,23 @@

# then dispatch to a specific handler if there is one
assert isinstance(element, Element)
if element.module in module_infos:
info = module_infos[element.module]
entity.type = f"{info.yaml_component}.{element.name}"

new_xml = globalHandler(entity, element.name, ioc, info.handler)
if new_xml:
handle_new_xml(new_xml, entity, ioc, info)
else:
new_xml = globalHandler(entity, element.name, ioc)
if new_xml:
handle_new_xml(new_xml, entity, ioc)

info = (
module_infos[element.module]
if element.module in module_infos
else module_infos["generic"]
)

def handle_new_xml(new_xml: str, entity: Entity, ioc: Generic_IOC, info=None):
new_builder = Builder()
new_builder.load_string(new_xml)
ioc.entities.remove(entity)
do_dispatch(new_builder, ioc)
entity.type = f"{info.yaml_component}.{element.name}"
new_xml = info.handler(entity, element.name, ioc)
if new_xml:
new_builder = Builder()
new_builder.load_string(new_xml)
ioc.entities.remove(entity)
do_dispatch(new_builder, ioc)

Check warning on line 66 in src/builder2ibek/convert.py

View check run for this annotation

Codecov / codecov/patch

src/builder2ibek/convert.py#L63-L66

Added lines #L63 - L66 were not covered by tests
if entity.is_deleted():
ioc.entities.remove(entity)
if not entity.is_deleted() and info:
else:
add_defaults(entity, info.defaults)


Expand Down
2 changes: 2 additions & 0 deletions src/builder2ibek/converters/ADAravis.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from builder2ibek.converters.globalHandler import globalHandler
from builder2ibek.types import Entity, Generic_IOC

xml_component = ["aravisGigE", "ADAravis"]
# type in yaml differs from above field in XML
yaml_component = "ADAravis"


@globalHandler
def handler(entity: Entity, entity_type: str, ioc: Generic_IOC):
if entity_type == "aravisCamera":
entity.remove("PV_ALIAS")
Expand Down
2 changes: 2 additions & 0 deletions src/builder2ibek/converters/ADZMQ.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from builder2ibek.converters.globalHandler import globalHandler
from builder2ibek.types import Entity, Generic_IOC

xml_component = "ADZMQ"


@globalHandler
def handler(entity: Entity, entity_type: str, ioc: Generic_IOC):
"""
XML to YAML specialist convertor function for the pvlogging support module
Expand Down
2 changes: 2 additions & 0 deletions src/builder2ibek/converters/BL20J.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from builder2ibek.converters.globalHandler import globalHandler
from builder2ibek.types import Entity, Generic_IOC

xml_component = "BL20J"


@globalHandler
def handler(entity: Entity, entity_type: str, ioc: Generic_IOC):
"""
XML to YAML specialist convertor function for the pvlogging support module
Expand Down
2 changes: 2 additions & 0 deletions src/builder2ibek/converters/BL46P-BUILDER.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from builder2ibek.converters.globalHandler import globalHandler
from builder2ibek.types import Entity, Generic_IOC

xml_component = "BL46P-BUILDER"


@globalHandler
def handler(entity: Entity, entity_type: str, ioc: Generic_IOC):
"""
XML to YAML specialist convertor function
Expand Down
2 changes: 2 additions & 0 deletions src/builder2ibek/converters/adUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import ruamel.yaml as yaml

from builder2ibek.converters.globalHandler import globalHandler
from builder2ibek.types import Entity, Generic_IOC

xml_component = "adUtil"
Expand All @@ -13,6 +14,7 @@
GDA_PLUGINS = Path(__file__).parent / "gdaPlugins.yaml"


@globalHandler
def handler(entity: Entity, entity_type: str, ioc: Generic_IOC):
if entity_type == "gdaPlugins":
ioc.entities.remove(entity)
Expand Down
2 changes: 2 additions & 0 deletions src/builder2ibek/converters/autosave.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from builder2ibek.converters.globalHandler import globalHandler
from builder2ibek.types import Entity, Generic_IOC

xml_component = "autosave"


@globalHandler
def handler(entity: Entity, entity_type: str, ioc: Generic_IOC):
"""
XML to YAML specialist convertor function for the pvlogging support module
Expand Down
2 changes: 2 additions & 0 deletions src/builder2ibek/converters/deviocstats.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from builder2ibek.converters.globalHandler import globalHandler
from builder2ibek.types import Entity, Generic_IOC

xml_component = "devIocStats"
Expand All @@ -12,6 +13,7 @@
}


@globalHandler
def handler(entity: Entity, entity_type: str, ioc: Generic_IOC):
if (
entity_type == "devIocStatsHelper" or entity_type == "iocAdminSoft"
Expand Down
2 changes: 2 additions & 0 deletions src/builder2ibek/converters/digitelMpc.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from builder2ibek.converters.globalHandler import globalHandler
from builder2ibek.types import Entity, Generic_IOC

xml_component = "digitelMpc"


@globalHandler
def handler(entity: Entity, entity_type: str, ioc: Generic_IOC):
"""
XML to YAML specialist convertor function for the pmac support module
Expand Down
2 changes: 2 additions & 0 deletions src/builder2ibek/converters/dlsPLC.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from builder2ibek.converters.globalHandler import globalHandler
from builder2ibek.types import Entity, Generic_IOC

xml_component = "dlsPLC"


@globalHandler
def handler(entity: Entity, entity_type: str, ioc: Generic_IOC):
"""
XML to YAML specialist convertor function for the pmac support module
Expand Down
2 changes: 2 additions & 0 deletions src/builder2ibek/converters/epics_base.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from builder2ibek.converters.globalHandler import globalHandler
from builder2ibek.types import Entity, Generic_IOC

xml_component = "EPICS_BASE"
yaml_component = "epics"


@globalHandler
def handler(entity: Entity, entity_type: str, ioc: Generic_IOC):
if entity_type == "EpicsEnvSet":
if entity["key"] == "EPICS_CA_MAX_ARRAY_BYTES":
Expand Down
2 changes: 2 additions & 0 deletions src/builder2ibek/converters/ffmpegServer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from builder2ibek.converters.globalHandler import globalHandler
from builder2ibek.types import Entity, Generic_IOC

xml_component = "ffmpegServer"


@globalHandler
def handler(entity: Entity, entity_type: str, ioc: Generic_IOC):
"""
XML to YAML specialist convertor function for the pvlogging support module
Expand Down
26 changes: 18 additions & 8 deletions src/builder2ibek/converters/globalHandler.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
from builder2ibek.types import Entity, Generic_IOC
xml_component = "generic"

xml_component = "global"


def globalHandler(
entity: Entity, entity_type: str, ioc: Generic_IOC, target_handler=None
):
def handler(entity, entity_type, ioc, realHandler=None):
"""
Generic/global entity handler
"""
entity.remove("gda_name")
entity.remove("gda_desc")

if target_handler:
return target_handler(entity, entity_type, ioc)
if realHandler:
return realHandler(entity, entity_type, ioc)
else:
return None


def globalHandler(realHandler):
"""
Decorator for generic/global handler
"""
return lambda entity, entity_type, ioc: handler(
entity, entity_type, ioc, realHandler
)
2 changes: 2 additions & 0 deletions src/builder2ibek/converters/mks937a.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from builder2ibek.converters.globalHandler import globalHandler
from builder2ibek.types import Entity, Generic_IOC

xml_component = "mks937a"


@globalHandler
def handler(entity: Entity, entity_type: str, ioc: Generic_IOC):
"""
XML to YAML specialist convertor function for the pmac support module
Expand Down
2 changes: 2 additions & 0 deletions src/builder2ibek/converters/pmac.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
The convertor handler module for pmac support module
"""

from builder2ibek.converters.globalHandler import globalHandler
from builder2ibek.types import Entity, Generic_IOC

# The prefix for Builder XML Tags that this support module uses
Expand All @@ -16,6 +17,7 @@
)


@globalHandler
def handler(entity: Entity, entity_type: str, ioc: Generic_IOC):
"""
XML to YAML specialist convertor function for the pmac support module
Expand Down
2 changes: 2 additions & 0 deletions src/builder2ibek/converters/pvlogging.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from builder2ibek.converters.globalHandler import globalHandler
from builder2ibek.types import Entity, Generic_IOC

xml_component = "pvlogging"


@globalHandler
def handler(entity: Entity, entity_type: str, ioc: Generic_IOC):
"""
XML to YAML specialist convertor function for the pvlogging support module
Expand Down
2 changes: 2 additions & 0 deletions src/builder2ibek/converters/records.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from builder2ibek.converters.globalHandler import globalHandler
from builder2ibek.types import Entity, Generic_IOC

xml_component = "records"


@globalHandler
def handler(entity: Entity, entity_type: str, ioc: Generic_IOC):
"""
XML to YAML specialist convertor function for the pvlogging support module
Expand Down
2 changes: 1 addition & 1 deletion tests/samples/BL45P-MO-IOC-01.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<devIocStats.devIocStatsHelper ioc="BL45P-MO-IOC-01" name="MO1_STATS"/>
<pmac.pmacAsynIPPort IP="172.23.59.21" name="BRICK1port"/>
<pmac.GeoBrick P="BL45P-MO-STEP-01" Port="BRICK1port" name="BRICK1" />
<pmac.pmacDisableLimitsCheck Axis="2" Controller="BRICK1" name="BRICK1.DIS_LIM_CHECK.2"/>
<pmac.pmacDisableLimitsCheck Axis="2" Controller="BRICK1" name="BRICK1.DIS_LIM_CHECK.2" gda_name="Hello"/>
<pmac.pmacDisableLimitsCheck Axis="3" Controller="BRICK1" name="BRICK1.DIS_LIM_CHECK.3"/>
<pmac.pmacDisableLimitsCheck Axis="4" Controller="BRICK1" name="BRICK1.DIS_LIM_CHECK.4"/>
<pmac.pmacDisableLimitsCheck Axis="5" Controller="BRICK1" name="BRICK1.DIS_LIM_CHECK.5"/>
Expand Down
Loading
Loading