Metadata-Version: 2.4
Name: dls-ibek-yaml-editor
Version: 1.0.0b1
Summary: A gui tool for creating and editing ibek ioc.yaml files
Author-email: Lee Hudson <lee.hudson@diamond.ac.uk>
License:                                  Apache License
                                   Version 2.0, January 2004
                                http://www.apache.org/licenses/
        
           TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
        
           1. Definitions.
        
              "License" shall mean the terms and conditions for use, reproduction,
              and distribution as defined by Sections 1 through 9 of this document.
        
              "Licensor" shall mean the copyright owner or entity authorized by
              the copyright owner that is granting the License.
        
              "Legal Entity" shall mean the union of the acting entity and all
              other entities that control, are controlled by, or are under common
              control with that entity. For the purposes of this definition,
              "control" means (i) the power, direct or indirect, to cause the
              direction or management of such entity, whether by contract or
              otherwise, or (ii) ownership of fifty percent (50%) or more of the
              outstanding shares, or (iii) beneficial ownership of such entity.
        
              "You" (or "Your") shall mean an individual or Legal Entity
              exercising permissions granted by this License.
        
              "Source" form shall mean the preferred form for making modifications,
              including but not limited to software source code, documentation
              source, and configuration files.
        
              "Object" form shall mean any form resulting from mechanical
              transformation or translation of a Source form, including but
              not limited to compiled object code, generated documentation,
              and conversions to other media types.
        
              "Work" shall mean the work of authorship, whether in Source or
              Object form, made available under the License, as indicated by a
              copyright notice that is included in or attached to the work
              (an example is provided in the Appendix below).
        
              "Derivative Works" shall mean any work, whether in Source or Object
              form, that is based on (or derived from) the Work and for which the
              editorial revisions, annotations, elaborations, or other modifications
              represent, as a whole, an original work of authorship. For the purposes
              of this License, Derivative Works shall not include works that remain
              separable from, or merely link (or bind by name) to the interfaces of,
              the Work and Derivative Works thereof.
        
              "Contribution" shall mean any work of authorship, including
              the original version of the Work and any modifications or additions
              to that Work or Derivative Works thereof, that is intentionally
              submitted to Licensor for inclusion in the Work by the copyright owner
              or by an individual or Legal Entity authorized to submit on behalf of
              the copyright owner. For the purposes of this definition, "submitted"
              means any form of electronic, verbal, or written communication sent
              to the Licensor or its representatives, including but not limited to
              communication on electronic mailing lists, source code control systems,
              and issue tracking systems that are managed by, or on behalf of, the
              Licensor for the purpose of discussing and improving the Work, but
              excluding communication that is conspicuously marked or otherwise
              designated in writing by the copyright owner as "Not a Contribution."
        
              "Contributor" shall mean Licensor and any individual or Legal Entity
              on behalf of whom a Contribution has been received by Licensor and
              subsequently incorporated within the Work.
        
           2. Grant of Copyright License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              copyright license to reproduce, prepare Derivative Works of,
              publicly display, publicly perform, sublicense, and distribute the
              Work and such Derivative Works in Source or Object form.
        
           3. Grant of Patent License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              (except as stated in this section) patent license to make, have made,
              use, offer to sell, sell, import, and otherwise transfer the Work,
              where such license applies only to those patent claims licensable
              by such Contributor that are necessarily infringed by their
              Contribution(s) alone or by combination of their Contribution(s)
              with the Work to which such Contribution(s) was submitted. If You
              institute patent litigation against any entity (including a
              cross-claim or counterclaim in a lawsuit) alleging that the Work
              or a Contribution incorporated within the Work constitutes direct
              or contributory patent infringement, then any patent licenses
              granted to You under this License for that Work shall terminate
              as of the date such litigation is filed.
        
           4. Redistribution. You may reproduce and distribute copies of the
              Work or Derivative Works thereof in any medium, with or without
              modifications, and in Source or Object form, provided that You
              meet the following conditions:
        
              (a) You must give any other recipients of the Work or
                  Derivative Works a copy of this License; and
        
              (b) You must cause any modified files to carry prominent notices
                  stating that You changed the files; and
        
              (c) You must retain, in the Source form of any Derivative Works
                  that You distribute, all copyright, patent, trademark, and
                  attribution notices from the Source form of the Work,
                  excluding those notices that do not pertain to any part of
                  the Derivative Works; and
        
              (d) If the Work includes a "NOTICE" text file as part of its
                  distribution, then any Derivative Works that You distribute must
                  include a readable copy of the attribution notices contained
                  within such NOTICE file, excluding those notices that do not
                  pertain to any part of the Derivative Works, in at least one
                  of the following places: within a NOTICE text file distributed
                  as part of the Derivative Works; within the Source form or
                  documentation, if provided along with the Derivative Works; or,
                  within a display generated by the Derivative Works, if and
                  wherever such third-party notices normally appear. The contents
                  of the NOTICE file are for informational purposes only and
                  do not modify the License. You may add Your own attribution
                  notices within Derivative Works that You distribute, alongside
                  or as an addendum to the NOTICE text from the Work, provided
                  that such additional attribution notices cannot be construed
                  as modifying the License.
        
              You may add Your own copyright statement to Your modifications and
              may provide additional or different license terms and conditions
              for use, reproduction, or distribution of Your modifications, or
              for any such Derivative Works as a whole, provided Your use,
              reproduction, and distribution of the Work otherwise complies with
              the conditions stated in this License.
        
           5. Submission of Contributions. Unless You explicitly state otherwise,
              any Contribution intentionally submitted for inclusion in the Work
              by You to the Licensor shall be under the terms and conditions of
              this License, without any additional terms or conditions.
              Notwithstanding the above, nothing herein shall supersede or modify
              the terms of any separate license agreement you may have executed
              with Licensor regarding such Contributions.
        
           6. Trademarks. This License does not grant permission to use the trade
              names, trademarks, service marks, or product names of the Licensor,
              except as required for reasonable and customary use in describing the
              origin of the Work and reproducing the content of the NOTICE file.
        
           7. Disclaimer of Warranty. Unless required by applicable law or
              agreed to in writing, Licensor provides the Work (and each
              Contributor provides its Contributions) on an "AS IS" BASIS,
              WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
              implied, including, without limitation, any warranties or conditions
              of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
              PARTICULAR PURPOSE. You are solely responsible for determining the
              appropriateness of using or redistributing the Work and assume any
              risks associated with Your exercise of permissions under this License.
        
           8. Limitation of Liability. In no event and under no legal theory,
              whether in tort (including negligence), contract, or otherwise,
              unless required by applicable law (such as deliberate and grossly
              negligent acts) or agreed to in writing, shall any Contributor be
              liable to You for damages, including any direct, indirect, special,
              incidental, or consequential damages of any character arising as a
              result of this License or out of the use or inability to use the
              Work (including but not limited to damages for loss of goodwill,
              work stoppage, computer failure or malfunction, or any and all
              other commercial damages or losses), even if such Contributor
              has been advised of the possibility of such damages.
        
           9. Accepting Warranty or Additional Liability. While redistributing
              the Work or Derivative Works thereof, You may choose to offer,
              and charge a fee for, acceptance of support, warranty, indemnity,
              or other liability obligations and/or rights consistent with this
              License. However, in accepting such obligations, You may act only
              on Your own behalf and on Your sole responsibility, not on behalf
              of any other Contributor, and only if You agree to indemnify,
              defend, and hold each Contributor harmless for any liability
              incurred by, or claims asserted against, such Contributor by reason
              of your accepting any such warranty or additional liability.
        
           END OF TERMS AND CONDITIONS
        
           APPENDIX: How to apply the Apache License to your work.
        
              To apply the Apache License to your work, attach the following
              boilerplate notice, with the fields enclosed by brackets "{}"
              replaced with your own identifying information. (Don't include
              the brackets!)  The text should be enclosed in the appropriate
              comment syntax for the file format. We also recommend that a
              file or class name and description of purpose be included on the
              same "printed page" as the copyright notice for easier
              identification within third-party archives.
        
           Copyright {yyyy} {name of copyright owner}
        
           Licensed under the Apache License, Version 2.0 (the "License");
           you may not use this file except in compliance with the License.
           You may obtain a copy of the License at
        
               http://www.apache.org/licenses/LICENSE-2.0
        
           Unless required by applicable law or agreed to in writing, software
           distributed under the License is distributed on an "AS IS" BASIS,
           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
           See the License for the specific language governing permissions and
           limitations under the License.
        
Project-URL: GitHub, https://github.com/DiamondLightSource/dls-ibek-yaml-editor
Classifier: Development Status :: 3 - Alpha
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: >=3.13
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: ibek>=4.8.2
Requires-Dist: pyside6-essentials<6.10,>=6.9
Requires-Dist: ruamel-yaml>=0.19.1
Requires-Dist: typer>=0.27.3
Dynamic: license-file

[![CI](https://github.com/DiamondLightSource/dls-ibek-yaml-editor/actions/workflows/ci.yml/badge.svg)](https://github.com/DiamondLightSource/dls-ibek-yaml-editor/actions/workflows/ci.yml)
[![Coverage](https://codecov.io/gh/DiamondLightSource/dls-ibek-yaml-editor/branch/main/graph/badge.svg)](https://codecov.io/gh/DiamondLightSource/dls-ibek-yaml-editor)
[![PyPI](https://img.shields.io/pypi/v/dls-ibek-yaml-editor.svg)](https://pypi.org/project/dls-ibek-yaml-editor)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)

# dls-ibek-yaml-editor

An xeb-like GUI for creating and editing ibek `ioc.yaml` files.

You point it at an IOC service directory, for example
`deb-services/services/fe99i-mo-ioc-01`. The tool reads the generic IOC image
pinned in that directory's `values.yaml`. It then fetches that image's
`/epics/ibek-defs` straight from the container registry. You don't need docker,
podman or a local checkout. The definitions are cached for reuse on later runs.
Those definitions include the modules inherited from the base image
(asyn, iocStats, autosave, …). So the editor offers exactly the entities that
version of the generic IOC can instantiate.

What            | Where
:---:           | :---:
Source          | <https://github.com/DiamondLightSource/dls-ibek-yaml-editor>
PyPI            | `pip install dls-ibek-yaml-editor`
Releases        | <https://github.com/DiamondLightSource/dls-ibek-yaml-editor/releases>
Code structure  | [docs/architecture.md](docs/architecture.md)
Development and testing | [docs/development.md](docs/development.md)

## Usage

Requires Python 3.13 or later and a desktop environment that can run Qt.

```sh
uvx dls-ibek-yaml-editor services/fe99i-mo-ioc-01            # edit, or create a new instance
uvx dls-ibek-yaml-editor services/fe99i-mo-ioc-01 --validate # check it with ibek
uvx dls-ibek-yaml-editor services/fe99i-mo-ioc-01 --list-entities
```

The argument can be any of these:

- a service directory
- its `config` directory
- an `ioc.yaml`

If a service directory has no `config/ioc.yaml` yet, the tool starts a new
instance and writes the file on the first save. The new file's `$schema`
header points at the schema published for the pinned image tag when a schema
URL can be derived from it, so VS Code can validate the file outside the
container. Services using `compose.yml` or `compose.yaml` are also recognised.

`--validate` and `--list-entities` run without opening a window or requiring a
display. Validation exits with status 0 on success and 1 if there are problems
or the IOC file is missing.

These options change where the entities come from:

Option                | Entities come from
:---                  | :---
(default)             | the image in `values.yaml`
`--image REF`         | another image
`--generic-ioc PATH`  | a local generic IOC checkout, for an unreleased version: its Dockerfile's support modules, plus the base image's from the registry. A warning is shown if the checkout's tag differs from `values.yaml`.
`--defs DIR`          | a folder of `*.ibek.support.yaml`

If combined, `--defs` takes priority over `--generic-ioc`, which takes priority
over the image. Support files beside the target `ioc.yaml` (normally
`config/*.ibek.support.yaml`) are always added on top. A local definition
replaces the whole module with the same name. Invalid support files and
missing definition directories are reported as errors.

## The window

The layout follows xeb:

- **Left:** the entity types used in the file. Pick one to edit its table.
  Rows are entities and columns are parameters.
- **Entity order:** every entity in file order, in a dock on the left.
- **Components menu:** adds a type.
- **Undo stack:** in a dock on the left.

Inside the table:

- Defaults are shown in grey italics and are not written to the file.
- Required cells that are empty are red. Bold column headers are required
  parameters.
- Enums and booleans are edited with editable drop-downs, so Jinja values
  can be retained. Object references offer the ids of active entities in the
  file.
- The first column, **X**, comments a row out, as in xeb. The entity is saved
  as a commented-out block (`  # - type: …`), as VS Code's Ctrl+/ would write
  it, and blocks like that in an existing file open as X rows. ibek ignores a
  commented entity, so validation skips it and its ids can't be referenced.
  Clear the cell (Ctrl+D) to uncomment it.

The Edit menu keeps xeb's commands and shortcuts:

- Insert Row (Ctrl+I) and Insert Row Under (Ctrl+U)
- Cut, copy and paste (tab-separated, so spreadsheets work)
- Clear (Ctrl+D)
- Fill Cells (Ctrl+L)
- Fill Cells and Increment (Ctrl+R), which turns `MOT.APTR03X` into
  `MOT.APTR04X`, `MOT.APTR05X`, …

The order of `entities` is the IOC's startup order. A type's entities don't
have to be together: a file can interleave types (port A, motor on A, port B,
motor on B), and it is opened and saved in its own order. Each type still has
one table, and the type list is in order of each type's first entity.

- **Entity order** lists every entity, numbered, in file order. The current
  table's entities are bold and commented-out ones grey. Drag an entity to move
  it anywhere in the file; click it to show it in its table.
- Drag a row header to move an entity to another row's place in the file.
  Inserted rows go next to the row they were inserted at. The first entity of a
  new table goes after the last entity of the tables listed before it.
- **Components > Group Entities by Type** keeps each type's entities together,
  as xeb does, in the order of the type list. Dragging a type in the list, or
  Components > Move Table Up/Down, moves a whole table, so it groups the file
  too. Removing a table leaves the rest of the order alone.

All of these can be undone, and nothing is written until you save. ibek needs
an entity to come before anything that refers to its id, and validation
reports a reference that comes too early. This check applies to object
references; plain string links, such as some `port` parameters, are not
checked.

**Tools > Validate** (F5) checks the file with ibek's own model. It runs again
on every save, and the problems are listed and highlighted in the tables.
Editing clears the previous results; press F5 to check again. If validation
finds problems when saving, you can cancel or choose **Save anyway**.

Dictionary and list parameters accept YAML or JSON in the cell, and are shown
as YAML flow text, such as `{when: 2026-10-27, n: 1}`. Clipboard text
uses quoted tab-separated values for spreadsheets; backslashes stay literal.
Clearing a cell removes its key. Existing null and empty-string values are
preserved until edited. Types missing from the definitions have read-only cells.

Saving retains comments, quoting and Jinja text, but serialises the whole
document, so spacing and indentation may change. Commented entities stay
commented out. Invalid entity collections are rejected when opening a file.
The file is replaced only after a complete temporary copy has been written.
Existing symlinks are followed and file permissions retained; new files get
the usual permissions for your umask (0664 with umask 002). A file owned by
someone else, or in a directory you can't create files in, is rewritten in
place instead, so its owner doesn't change.

## Registry access

Public images can be fetched anonymously. For private registries, credentials
are read from inline `auth` entries in `~/.docker/config.json` (or
`$DOCKER_CONFIG/config.json`), then from matching `CI_REGISTRY`,
`CI_REGISTRY_USER` and `CI_REGISTRY_PASSWORD`. Docker credential helpers are
not supported.

Fetched definitions are cached in `~/.cache/dls-ibek-yaml-editor`, or wherever
`DLS_IBEK_YAML_EDITOR_CACHE` points. A cached tag is used without contacting
the registry, so later runs start at once and work offline. Pass `--refresh`
to check the registry for an image rebuilt under the same tag (`latest` is
always checked). If a refresh fails, an existing valid cache is used with a
message explaining why.

For an epics-containers runtime image, the first fetch reads only the start of
the layer that holds `/epics`, which is quick. Other images, or one whose
definitions link into a lower layer, have every layer read and merged, which
downloads the whole image once. Refreshes keep older cache snapshots so open
documents can still use them. To reclaim space, close the editor and remove
its cache directory; the next run fetches definitions again. Caches written by
older editor versions are still used.

With no target, `--image`, `--generic-ioc` or `--defs` open an untitled
instance using those entities; Save asks where to write it.
