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

Added global handler #11

Merged
merged 9 commits into from
Oct 8, 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
3 changes: 1 addition & 2 deletions .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Changes here will be overwritten by Copier
_commit: 2.1.0
_commit: 2.3.0
_src_path: gh:diamondlightsource/python-copier-template
author_email: [email protected]
author_name: Giles Knap
component_owner: group:default/sscc
description: Conversion tool for DLS XML builder IOC instances to ibek ioc.yaml
distribution_name: builder2ibek
docker: false
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@
"workspaceMount": "source=${localWorkspaceFolder}/..,target=/workspaces,type=bind",
// After the container is created, install the python project in editable form
"postCreateCommand": "pip install $([ -f dev-requirements.txt ] && echo '-c dev-requirements.txt') -e '.[dev]' && pre-commit install"
}
}
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.1.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.3.0/how-to.html).
21 changes: 21 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
name: Bug Report
about: The template to use for reporting bugs and usability issues
title: " "
labels: 'bug'
assignees: ''

---

Describe the bug, including a clear and concise description of the expected behavior, the actual behavior and the context in which you encountered it (ideally include details of your environment).

## Steps To Reproduce
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error


## Acceptance Criteria
- Specific criteria that will be used to judge if the issue is fixed
13 changes: 13 additions & 0 deletions .github/ISSUE_TEMPLATE/issue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
name: Issue
about: The standard template to use for feature requests, design discussions and tasks
title: " "
labels: ''
assignees: ''

---

A brief description of the issue, including specific stakeholders and the business case where appropriate

## Acceptance Criteria
- Specific criteria that will be used to judge if the issue is fixed
8 changes: 8 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Fixes #ISSUE

### Instructions to reviewer on how to test:
1. Do thing x
2. Confirm thing y happens

### Checks for reviewer
- [ ] Would the PR title make sense to a user on a set of release notes
2 changes: 1 addition & 1 deletion .github/pages/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
<link rel="canonical" href="main/index.html">
</head>

</html>
</html>
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@9d7c94cfd0a1f3ed45544c887983e9fa900f0564 # v2.0.4
uses: softprops/action-gh-release@c062e08bd532815e2082a85e87e3ef29c3e6d191 # v2.0.8
with:
prerelease: ${{ contains(github.ref_name, 'a') || contains(github.ref_name, 'b') || contains(github.ref_name, 'rc') }}
files: "*"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
strategy:
matrix:
runs-on: ["ubuntu-latest"] # can add windows-latest, macos-latest
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.10", "3.11", "3.12"]
include:
# Include one that runs in the dev environment
- runs-on: "ubuntu-latest"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ cov.xml

# Sphinx documentation
docs/_build/
docs/_api

# PyBuilder
target/
Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ repos:
- id: check-added-large-files
- id: check-yaml
- id: check-merge-conflict
- id: end-of-file-fixer

- repo: local
hooks:
Expand Down
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"recommendations": [
"ms-vscode-remote.remote-containers",
]
}
}
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
},
"files.insertFinalNewline": true,
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
},
}
}
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
"problemMatcher": [],
}
]
}
}
10 changes: 0 additions & 10 deletions catalog-info.yaml

This file was deleted.

42 changes: 42 additions & 0 deletions out.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# yaml-language-server: $schema=/epics/ibek-defs/ioc.schema.json

ioc_name: "{{ __utils__.get_env('IOC_NAME') }}"

description: auto-generated by https://github.com/epics-containers/builder2ibek

entities:

- type: epics.EpicsEnvSet
name: EPICS_TS_MIN_WEST
value: '0'

- type: devIocStats.iocAdminSoft
IOC: '{{ ioc_name | upper }}'

- type: epics.EpicsCaMaxArrayBytes
max_bytes: 9000000

- type: devIocStats.devIocStatsHelper
__command__: delete
ioc: BL99P-EA-IOC-05
name: IOC-STATS

- type: ADAndor.andorCCD
ADDR: 0
BUFFERS: 2000
INSTALLPATH: /dls_sw/prod/R3.14.12.7/support/ANAndor/etc
P: BL99P-EA-DET-03
PORT: DET3.cam
R: ':CAM:'
TIMEOUT: 1

- type: ADCore.NDPosPlugin
ADDR: 0
BLOCK: 0
ENABLED: 1
NDARRAY_PORT: DET3.cam
P: BL99P-EA-DET-03
PORT: DET3.pos
QUEUE: 1000
R: ':POS:'
TIMEOUT: 1
29 changes: 17 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
[build-system]
requires = ["setuptools>=64", "setuptools_scm[toml]>=6.2"]
requires = ["setuptools>=64", "setuptools_scm[toml]>=8"]
build-backend = "setuptools.build_meta"

[project]
name = "builder2ibek"
classifiers = [
"Development Status :: 3 - Alpha",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
description = "Conversion tool for DLS XML builder IOC instances to ibek ioc.yaml"
dependencies = ["ibek"] # Add project dependencies here, e.g. ["click", "numpy"]
Expand Down Expand Up @@ -45,7 +43,7 @@ name = "Giles Knap"


[tool.setuptools_scm]
write_to = "src/builder2ibek/_version.py"
version_file = "src/builder2ibek/_version.py"

[tool.mypy]
ignore_missing_imports = true # Ignore missing stubs in imported modules
Expand Down Expand Up @@ -97,11 +95,18 @@ lint.ignore = [
]
line-length = 88
lint.select = [
"B", # flake8-bugbear - https://docs.astral.sh/ruff/rules/#flake8-bugbear-b
"C4", # flake8-comprehensions - https://docs.astral.sh/ruff/rules/#flake8-comprehensions-c4
"E", # pycodestyle errors - https://docs.astral.sh/ruff/rules/#error-e
"F", # pyflakes rules - https://docs.astral.sh/ruff/rules/#pyflakes-f
"W", # pycodestyle warnings - https://docs.astral.sh/ruff/rules/#warning-w
"I", # isort - https://docs.astral.sh/ruff/rules/#isort-i
"UP", # pyupgrade - https://docs.astral.sh/ruff/rules/#pyupgrade-up
"B", # flake8-bugbear - https://docs.astral.sh/ruff/rules/#flake8-bugbear-b
"C4", # flake8-comprehensions - https://docs.astral.sh/ruff/rules/#flake8-comprehensions-c4
"E", # pycodestyle errors - https://docs.astral.sh/ruff/rules/#error-e
"F", # pyflakes rules - https://docs.astral.sh/ruff/rules/#pyflakes-f
"W", # pycodestyle warnings - https://docs.astral.sh/ruff/rules/#warning-w
"I", # isort - https://docs.astral.sh/ruff/rules/#isort-i
"UP", # pyupgrade - https://docs.astral.sh/ruff/rules/#pyupgrade-up
"SLF", # self - https://docs.astral.sh/ruff/settings/#lintflake8-self
]

[tool.ruff.lint.per-file-ignores]
# By default, private member access is allowed in tests
# See https://github.com/DiamondLightSource/python-copier-template/issues/154
# Remove this line to forbid private member access in tests
"tests/**/*" = ["SLF001"]
8 changes: 8 additions & 0 deletions src/builder2ibek/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
"""Top level API.

.. data:: __version__
:type: str

Version number as calculated by https://github.com/pypa/setuptools_scm
"""

from ._version import __version__

__all__ = ["__version__"]
28 changes: 19 additions & 9 deletions src/builder2ibek/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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 @@ -53,16 +54,25 @@
if element.module in module_infos:
info = module_infos[element.module]
entity.type = f"{info.yaml_component}.{element.name}"
new_xml = info.handler(entity, element.name, ioc)

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

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

View check run for this annotation

Codecov / codecov/patch

src/builder2ibek/convert.py#L60

Added line #L60 was not covered by tests
else:
new_xml = globalHandler(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)
if entity.is_deleted():
ioc.entities.remove(entity)
else:
add_defaults(entity, info.defaults)
handle_new_xml(new_xml, entity, ioc)

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

View check run for this annotation

Codecov / codecov/patch

src/builder2ibek/convert.py#L64

Added line #L64 was not covered by tests


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)
if entity.is_deleted():
ioc.entities.remove(entity)
if not entity.is_deleted() and info:
add_defaults(entity, info.defaults)

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

View check run for this annotation

Codecov / codecov/patch

src/builder2ibek/convert.py#L68-L75

Added lines #L68 - L75 were not covered by tests


def add_defaults(entity: dict[str, Any], defaults: dict[str, dict[str, Any]]):
Expand Down
2 changes: 1 addition & 1 deletion src/builder2ibek/converters/digitelMpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"""
if entity_type in ["digitelMpc", "digitelMpcTsp"]:
# transform unit into quoted 2 digit format
unit = int(entity.get("unit"))
unit = int(entity.get("unit")) # type: ignore

Check warning on line 12 in src/builder2ibek/converters/digitelMpc.py

View check run for this annotation

Codecov / codecov/patch

src/builder2ibek/converters/digitelMpc.py#L12

Added line #L12 was not covered by tests
unit_enum = f"{unit:02d}"
entity.unit = unit_enum
3 changes: 2 additions & 1 deletion src/builder2ibek/converters/dlsPLC.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"""
if entity_type == "fastVacuumChannel":
# transform unit into quoted 2 digit format
id = int(entity.get("id"))
id_val = entity.get("id")
id = int(id_val) # type: ignore

Check warning on line 13 in src/builder2ibek/converters/dlsPLC.py

View check run for this annotation

Codecov / codecov/patch

src/builder2ibek/converters/dlsPLC.py#L12-L13

Added lines #L12 - L13 were not covered by tests
id_enum = f"{id:02d}"
entity.id = id_enum
elif entity_type == "NX102_readReal":
Expand Down
2 changes: 1 addition & 1 deletion src/builder2ibek/converters/gdaPlugins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@
PORT: $(PORTPREFIX).hdf
QUEUE: $(PLUGINQUEUE=16)
R: ':HDF5:'
TIMEOUT: 1
TIMEOUT: 1
13 changes: 13 additions & 0 deletions src/builder2ibek/converters/globalHandler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from builder2ibek.types import Entity, Generic_IOC

xml_component = "global"


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

if target_handler:
return target_handler(entity, entity_type, ioc)
12 changes: 9 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from typing import Any

import pytest

Expand All @@ -7,9 +8,14 @@
if os.getenv("PYTEST_RAISE", "0") == "1":

@pytest.hookimpl(tryfirst=True)
def pytest_exception_interact(call):
raise call.excinfo.value
def pytest_exception_interact(call: pytest.CallInfo[Any]):
if call.excinfo is not None:
raise call.excinfo.value
else:
raise RuntimeError(
f"{call} has no exception data, an unknown error has occurred"
)

@pytest.hookimpl(tryfirst=True)
def pytest_internalerror(excinfo):
def pytest_internalerror(excinfo: pytest.ExceptionInfo[Any]):
raise excinfo.value
9 changes: 9 additions & 0 deletions tests/samples/BL99P-EA-IOC-05.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" ?>
<components arch="linux-x86_64">
<EPICS_BASE.EpicsEnvSet key="EPICS_CA_MAX_ARRAY_BYTES" value="9000000"/>
<devIocStats.devIocStatsHelper ioc="BL99P-EA-IOC-05" name="IOC-STATS"/>
<!--ADAndor.andorCCD ADDR="0" BUFFERS="2000" INSTALLPATH="/dls_sw/prod/R3.14.12.7/support/andorCCDSDK/2-102dls4/andorCCDSDKApp/src/sdk/andor/etc" P="BL99P-EA-DET-03" PORT="DET3.cam" R=":CAM:" TIMEOUT="1"/-->
<ADAndor.andorCCD ADDR="0" BUFFERS="2000" INSTALLPATH="/dls_sw/prod/R3.14.12.7/support/ANAndor/etc" P="BL99P-EA-DET-03" PORT="DET3.cam" R=":CAM:" TIMEOUT="1"/>
<!--<ADZMQ.NDZMQPlugin DEST_ADDR="127.0.0.1:1515" NDARRAY_PORT="DET3.cam" P="BL99P-EA-DET-03" PORT="DET3.zmq" QUEUE="1000" R=":ZMQ:" TRANSPORT="tcp" ZMQ_TYPE="PUSH"/>-->
<ADCore.NDPosPlugin ADDR="0" BLOCK="0" ENABLED="1" NDARRAY_PORT="DET3.cam" P="BL99P-EA-DET-03" PORT="DET3.pos" QUEUE="1000" R=":POS:" TIMEOUT="1"/>
</components>
22 changes: 22 additions & 0 deletions tests/test_file_conversion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import subprocess
import sys


def test_cli_version():
conversion_samples = [
"tests/samples/BL45P-MO-IOC-01.xml",
"tests/samples/BL99P-EA-IOC-05.xml",
]

for sample in conversion_samples:
cmd = [
sys.executable,
"-m",
"builder2ibek",
"file",
"--yaml",
"out.yaml",
sample,
]
result = subprocess.run(cmd)
assert result.returncode == 0