lightfall-utils 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lightfall_utils-0.1.0/.github/workflows/release.yml +66 -0
- lightfall_utils-0.1.0/.gitignore +9 -0
- lightfall_utils-0.1.0/LEGAL.md +13 -0
- lightfall_utils-0.1.0/LICENSE.md +33 -0
- lightfall_utils-0.1.0/PKG-INFO +54 -0
- lightfall_utils-0.1.0/README.md +24 -0
- lightfall_utils-0.1.0/pyproject.toml +67 -0
- lightfall_utils-0.1.0/src/lightfall_utils/__init__.py +3 -0
- lightfall_utils-0.1.0/src/lightfall_utils/_version.py +24 -0
- lightfall_utils-0.1.0/src/lightfall_utils/ca/__init__.py +9 -0
- lightfall_utils-0.1.0/src/lightfall_utils/ca/context.py +100 -0
- lightfall_utils-0.1.0/src/lightfall_utils/ca/pv.py +307 -0
- lightfall_utils-0.1.0/src/lightfall_utils/caproto_shutdown.py +89 -0
- lightfall_utils-0.1.0/src/lightfall_utils/config/__init__.py +12 -0
- lightfall_utils-0.1.0/src/lightfall_utils/config/layers.py +317 -0
- lightfall_utils-0.1.0/src/lightfall_utils/config/manager.py +246 -0
- lightfall_utils-0.1.0/src/lightfall_utils/log_buffer.py +231 -0
- lightfall_utils-0.1.0/src/lightfall_utils/logging.py +235 -0
- lightfall_utils-0.1.0/src/lightfall_utils/py.typed +0 -0
- lightfall_utils-0.1.0/src/lightfall_utils/qt_affinity.py +92 -0
- lightfall_utils-0.1.0/src/lightfall_utils/theming/__init__.py +30 -0
- lightfall_utils-0.1.0/src/lightfall_utils/theming/builtin.py +737 -0
- lightfall_utils-0.1.0/src/lightfall_utils/theming/manager.py +1030 -0
- lightfall_utils-0.1.0/src/lightfall_utils/theming/provider.py +102 -0
- lightfall_utils-0.1.0/src/lightfall_utils/theming/registry.py +195 -0
- lightfall_utils-0.1.0/src/lightfall_utils/threads.py +1071 -0
- lightfall_utils-0.1.0/tests/ca_ioc.py +16 -0
- lightfall_utils-0.1.0/tests/conftest.py +45 -0
- lightfall_utils-0.1.0/tests/test_ca_context.py +16 -0
- lightfall_utils-0.1.0/tests/test_ca_pv.py +84 -0
- lightfall_utils-0.1.0/tests/test_caproto_shutdown.py +46 -0
- lightfall_utils-0.1.0/tests/test_config_layers.py +42 -0
- lightfall_utils-0.1.0/tests/test_config_manager.py +60 -0
- lightfall_utils-0.1.0/tests/test_log_buffer.py +169 -0
- lightfall_utils-0.1.0/tests/test_logging.py +93 -0
- lightfall_utils-0.1.0/tests/test_package_hygiene.py +20 -0
- lightfall_utils-0.1.0/tests/test_qt_affinity.py +59 -0
- lightfall_utils-0.1.0/tests/test_theming.py +114 -0
- lightfall_utils-0.1.0/tests/test_threads.py +484 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Release pipeline, triggered by v* tags:
|
|
2
|
+
# build-dist / publish-pypi: sdist + wheel to PyPI via OIDC trusted
|
|
3
|
+
# publishing (environment: pypi; publisher registered on pypi.org against
|
|
4
|
+
# this workflow file). Mirrors lightfall's release.yml minus app packaging.
|
|
5
|
+
|
|
6
|
+
name: Release
|
|
7
|
+
|
|
8
|
+
on:
|
|
9
|
+
push:
|
|
10
|
+
tags: ["v*"]
|
|
11
|
+
workflow_dispatch:
|
|
12
|
+
|
|
13
|
+
permissions:
|
|
14
|
+
contents: write
|
|
15
|
+
|
|
16
|
+
jobs:
|
|
17
|
+
build-dist:
|
|
18
|
+
runs-on: ubuntu-latest
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v4
|
|
21
|
+
with:
|
|
22
|
+
fetch-depth: 0 # hatch-vcs derives the version from git tags
|
|
23
|
+
- uses: actions/setup-python@v5
|
|
24
|
+
with:
|
|
25
|
+
python-version: "3.11"
|
|
26
|
+
- name: Build sdist and wheel
|
|
27
|
+
run: |
|
|
28
|
+
python -m pip install build twine
|
|
29
|
+
python -m build
|
|
30
|
+
python -m twine check dist/*
|
|
31
|
+
- uses: actions/upload-artifact@v4
|
|
32
|
+
with:
|
|
33
|
+
name: dist-pypi
|
|
34
|
+
path: dist/
|
|
35
|
+
if-no-files-found: error
|
|
36
|
+
retention-days: 7
|
|
37
|
+
|
|
38
|
+
publish-pypi:
|
|
39
|
+
needs: build-dist
|
|
40
|
+
if: startsWith(github.ref, 'refs/tags/')
|
|
41
|
+
runs-on: ubuntu-latest
|
|
42
|
+
environment: pypi
|
|
43
|
+
permissions:
|
|
44
|
+
id-token: write # OIDC trusted publishing
|
|
45
|
+
steps:
|
|
46
|
+
- uses: actions/download-artifact@v4
|
|
47
|
+
with:
|
|
48
|
+
name: dist-pypi
|
|
49
|
+
path: dist/
|
|
50
|
+
- name: Publish to PyPI
|
|
51
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
52
|
+
|
|
53
|
+
release:
|
|
54
|
+
needs: build-dist
|
|
55
|
+
if: startsWith(github.ref, 'refs/tags/')
|
|
56
|
+
runs-on: ubuntu-latest
|
|
57
|
+
steps:
|
|
58
|
+
- uses: actions/download-artifact@v4
|
|
59
|
+
with:
|
|
60
|
+
name: dist-pypi
|
|
61
|
+
path: dist/
|
|
62
|
+
- uses: softprops/action-gh-release@v2
|
|
63
|
+
with:
|
|
64
|
+
name: lightfall-utils ${{ github.ref_name }}
|
|
65
|
+
generate_release_notes: true
|
|
66
|
+
files: dist/**
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Lightfall Copyright (c) 2026,
|
|
2
|
+
The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Dept. of Energy). All rights reserved.
|
|
3
|
+
|
|
4
|
+
If you have questions about your rights to use or distribute this software,
|
|
5
|
+
please contact Berkeley Lab's Intellectual Property Office at
|
|
6
|
+
IPO@lbl.gov.
|
|
7
|
+
|
|
8
|
+
NOTICE. This Software was developed under funding from the U.S. Department
|
|
9
|
+
of Energy and the U.S. Government consequently retains certain rights. As
|
|
10
|
+
such, the U.S. Government has been granted for itself and others acting on
|
|
11
|
+
its behalf a paid-up, nonexclusive, irrevocable, worldwide license in the
|
|
12
|
+
Software to reproduce, distribute copies to the public, prepare derivative
|
|
13
|
+
works, and perform publicly and display publicly, and to permit others to do so.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
Lightfall Copyright (c) 2026,
|
|
2
|
+
The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Dept. of Energy). All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
(1) Redistributions of source code must retain the above copyright notice,
|
|
8
|
+
this list of conditions and the following disclaimer.
|
|
9
|
+
|
|
10
|
+
(2) Redistributions in binary form must reproduce the above copyright
|
|
11
|
+
notice, this list of conditions and the following disclaimer in the
|
|
12
|
+
documentation and/or other materials provided with the distribution.
|
|
13
|
+
|
|
14
|
+
(3) Neither the name of the University of California, Lawrence Berkeley
|
|
15
|
+
National Laboratory, U.S. Dept. of Energy nor the names of its contributors
|
|
16
|
+
may be used to endorse or promote products derived from this software
|
|
17
|
+
without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
21
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
22
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
23
|
+
|
|
24
|
+
You are under no obligation whatsoever to provide any bug fixes, patches,
|
|
25
|
+
or upgrades to the features, functionality or performance of the source
|
|
26
|
+
code ("Enhancements") to anyone; however, if you choose to make your
|
|
27
|
+
Enhancements available either publicly, or directly to Lawrence Berkeley
|
|
28
|
+
National Laboratory, without imposing a separate written license agreement
|
|
29
|
+
for such Enhancements, then you hereby grant the following license: a
|
|
30
|
+
non-exclusive, royalty-free perpetual license to install, use, modify,
|
|
31
|
+
prepare derivative works, incorporate into other computer software,
|
|
32
|
+
distribute, and sublicense such enhancements or derivative works thereof,
|
|
33
|
+
in binary and source code form.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: lightfall-utils
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Shared Qt/EPICS infrastructure for ALS control applications: managed threading, loguru logging, semantic theming, layered config, and a caproto/Qt bridge
|
|
5
|
+
Author: ALS Controls Team
|
|
6
|
+
License-Expression: BSD-3-Clause
|
|
7
|
+
License-File: LEGAL.md
|
|
8
|
+
License-File: LICENSE.md
|
|
9
|
+
Requires-Python: >=3.11
|
|
10
|
+
Requires-Dist: loguru>=0.7
|
|
11
|
+
Requires-Dist: pydantic>=2.0
|
|
12
|
+
Requires-Dist: pyside6>=6.6
|
|
13
|
+
Requires-Dist: pyyaml>=6.0
|
|
14
|
+
Provides-Extra: ca
|
|
15
|
+
Requires-Dist: caproto>=1.1; extra == 'ca'
|
|
16
|
+
Provides-Extra: dev
|
|
17
|
+
Requires-Dist: caproto>=1.1; extra == 'dev'
|
|
18
|
+
Requires-Dist: pyright>=1.1; extra == 'dev'
|
|
19
|
+
Requires-Dist: pytest-cov>=4.0; extra == 'dev'
|
|
20
|
+
Requires-Dist: pytest-qt>=4.2; extra == 'dev'
|
|
21
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
22
|
+
Requires-Dist: ruff>=0.1; extra == 'dev'
|
|
23
|
+
Provides-Extra: docs
|
|
24
|
+
Requires-Dist: myst-parser>=2.0; extra == 'docs'
|
|
25
|
+
Requires-Dist: sphinx-immaterial>=0.12; extra == 'docs'
|
|
26
|
+
Requires-Dist: sphinx<9.0,>=7.0; extra == 'docs'
|
|
27
|
+
Provides-Extra: multihomed
|
|
28
|
+
Requires-Dist: netifaces>=0.11; (sys_platform != 'darwin') and extra == 'multihomed'
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# lightfall-utils
|
|
32
|
+
|
|
33
|
+
Shared Qt/EPICS infrastructure for ALS control applications (Lightfall, CAtfish).
|
|
34
|
+
|
|
35
|
+
Extracted from [Lightfall](https://github.com/als-controls/lightfall). Modules:
|
|
36
|
+
|
|
37
|
+
- `lightfall_utils.threads` — managed Qt thread pool, `QThreadFuture`, main-thread marshalling
|
|
38
|
+
- `lightfall_utils.logging` / `log_buffer` — loguru configuration, timing, in-process log ring buffer
|
|
39
|
+
- `lightfall_utils.qt_affinity` — GUI-thread assertion helpers (`gui_thread_only`)
|
|
40
|
+
- `lightfall_utils.config` — priority-layered YAML config with pydantic validation
|
|
41
|
+
- `lightfall_utils.theming` — semantic design tokens, theme registry/manager, QSS generation
|
|
42
|
+
- `lightfall_utils.ca` — caproto → Qt signal bridge (`SharedContext`, `PV`); requires the `ca` extra
|
|
43
|
+
- `lightfall_utils.caproto_shutdown` — drains caproto's user-callback thread pools cleanly at application shutdown
|
|
44
|
+
|
|
45
|
+
Install: `pip install lightfall-utils[ca]`. Add the `multihomed` extra alongside `ca` for caproto multi-homed interface enumeration (`pip install lightfall-utils[ca,multihomed]`).
|
|
46
|
+
|
|
47
|
+
Development:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
python -m venv .venv
|
|
51
|
+
.venv\Scripts\activate # Windows (source .venv/bin/activate on Unix)
|
|
52
|
+
pip install -e ".[dev]"
|
|
53
|
+
pytest
|
|
54
|
+
```
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# lightfall-utils
|
|
2
|
+
|
|
3
|
+
Shared Qt/EPICS infrastructure for ALS control applications (Lightfall, CAtfish).
|
|
4
|
+
|
|
5
|
+
Extracted from [Lightfall](https://github.com/als-controls/lightfall). Modules:
|
|
6
|
+
|
|
7
|
+
- `lightfall_utils.threads` — managed Qt thread pool, `QThreadFuture`, main-thread marshalling
|
|
8
|
+
- `lightfall_utils.logging` / `log_buffer` — loguru configuration, timing, in-process log ring buffer
|
|
9
|
+
- `lightfall_utils.qt_affinity` — GUI-thread assertion helpers (`gui_thread_only`)
|
|
10
|
+
- `lightfall_utils.config` — priority-layered YAML config with pydantic validation
|
|
11
|
+
- `lightfall_utils.theming` — semantic design tokens, theme registry/manager, QSS generation
|
|
12
|
+
- `lightfall_utils.ca` — caproto → Qt signal bridge (`SharedContext`, `PV`); requires the `ca` extra
|
|
13
|
+
- `lightfall_utils.caproto_shutdown` — drains caproto's user-callback thread pools cleanly at application shutdown
|
|
14
|
+
|
|
15
|
+
Install: `pip install lightfall-utils[ca]`. Add the `multihomed` extra alongside `ca` for caproto multi-homed interface enumeration (`pip install lightfall-utils[ca,multihomed]`).
|
|
16
|
+
|
|
17
|
+
Development:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
python -m venv .venv
|
|
21
|
+
.venv\Scripts\activate # Windows (source .venv/bin/activate on Unix)
|
|
22
|
+
pip install -e ".[dev]"
|
|
23
|
+
pytest
|
|
24
|
+
```
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling", "hatch-vcs"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "lightfall-utils"
|
|
7
|
+
description = "Shared Qt/EPICS infrastructure for ALS control applications: managed threading, loguru logging, semantic theming, layered config, and a caproto/Qt bridge"
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
license = "BSD-3-Clause"
|
|
10
|
+
license-files = ["LICENSE.md", "LEGAL.md"]
|
|
11
|
+
requires-python = ">=3.11"
|
|
12
|
+
authors = [{ name = "ALS Controls Team" }]
|
|
13
|
+
dynamic = ["version"]
|
|
14
|
+
dependencies = [
|
|
15
|
+
"PySide6>=6.6",
|
|
16
|
+
"loguru>=0.7",
|
|
17
|
+
"pydantic>=2.0",
|
|
18
|
+
"pyyaml>=6.0",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[project.optional-dependencies]
|
|
22
|
+
ca = ["caproto>=1.1"]
|
|
23
|
+
# netifaces (abandoned upstream, sdist-only) enables caproto multi-homed interface enumeration; caproto degrades gracefully without it
|
|
24
|
+
multihomed = ["netifaces>=0.11; sys_platform != 'darwin'"]
|
|
25
|
+
dev = [
|
|
26
|
+
"caproto>=1.1",
|
|
27
|
+
"pytest>=8.0",
|
|
28
|
+
"pytest-cov>=4.0",
|
|
29
|
+
"pytest-qt>=4.2",
|
|
30
|
+
"ruff>=0.1",
|
|
31
|
+
"pyright>=1.1",
|
|
32
|
+
]
|
|
33
|
+
docs = [
|
|
34
|
+
"sphinx>=7.0,<9.0",
|
|
35
|
+
"myst-parser>=2.0",
|
|
36
|
+
"sphinx-immaterial>=0.12",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[tool.hatch.version]
|
|
40
|
+
source = "vcs"
|
|
41
|
+
fallback-version = "0.0.0.dev0"
|
|
42
|
+
|
|
43
|
+
[tool.hatch.build.hooks.vcs]
|
|
44
|
+
version-file = "src/lightfall_utils/_version.py"
|
|
45
|
+
|
|
46
|
+
[tool.hatch.build.targets.wheel]
|
|
47
|
+
packages = ["src/lightfall_utils"]
|
|
48
|
+
|
|
49
|
+
[tool.ruff]
|
|
50
|
+
line-length = 100
|
|
51
|
+
target-version = "py311"
|
|
52
|
+
|
|
53
|
+
[tool.ruff.lint]
|
|
54
|
+
select = ["E", "W", "F", "I", "B", "C4", "UP"]
|
|
55
|
+
ignore = ["E501"]
|
|
56
|
+
|
|
57
|
+
[tool.ruff.lint.isort]
|
|
58
|
+
known-first-party = ["lightfall_utils"]
|
|
59
|
+
|
|
60
|
+
[tool.pytest.ini_options]
|
|
61
|
+
testpaths = ["tests"]
|
|
62
|
+
addopts = "-ra -q"
|
|
63
|
+
qt_api = "pyside6"
|
|
64
|
+
|
|
65
|
+
[tool.pyright]
|
|
66
|
+
include = ["src"]
|
|
67
|
+
pythonVersion = "3.11"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# file generated by vcs-versioning
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"__version__",
|
|
7
|
+
"__version_tuple__",
|
|
8
|
+
"version",
|
|
9
|
+
"version_tuple",
|
|
10
|
+
"__commit_id__",
|
|
11
|
+
"commit_id",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
version: str
|
|
15
|
+
__version__: str
|
|
16
|
+
__version_tuple__: tuple[int | str, ...]
|
|
17
|
+
version_tuple: tuple[int | str, ...]
|
|
18
|
+
commit_id: str | None
|
|
19
|
+
__commit_id__: str | None
|
|
20
|
+
|
|
21
|
+
__version__ = version = '0.1.0'
|
|
22
|
+
__version_tuple__ = version_tuple = (0, 1, 0)
|
|
23
|
+
|
|
24
|
+
__commit_id__ = commit_id = None
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Shared CA context management for the application.
|
|
3
|
+
|
|
4
|
+
Provides a singleton-like shared context that widgets can use to connect to PVs.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import threading
|
|
10
|
+
from typing import TYPE_CHECKING
|
|
11
|
+
|
|
12
|
+
from caproto.threading.client import Context
|
|
13
|
+
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from caproto.threading.client import PV as CaprotoPV
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class SharedContext:
|
|
19
|
+
"""
|
|
20
|
+
Manages a shared caproto threading context for all widgets.
|
|
21
|
+
|
|
22
|
+
This class provides a singleton pattern for the CA context to avoid
|
|
23
|
+
creating multiple contexts and to share connections efficiently.
|
|
24
|
+
|
|
25
|
+
Attributes:
|
|
26
|
+
context: The underlying caproto threading Context instance.
|
|
27
|
+
|
|
28
|
+
Example:
|
|
29
|
+
>>> ctx = SharedContext.get_instance()
|
|
30
|
+
>>> pv = ctx.get_pv("MY:PV:NAME")
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
_instance: SharedContext | None = None
|
|
34
|
+
_lock = threading.Lock()
|
|
35
|
+
|
|
36
|
+
def __init__(self) -> None:
|
|
37
|
+
self._context: Context | None = None
|
|
38
|
+
self._pvs: dict[str, CaprotoPV] = {}
|
|
39
|
+
|
|
40
|
+
@classmethod
|
|
41
|
+
def get_instance(cls) -> SharedContext:
|
|
42
|
+
"""
|
|
43
|
+
Get the singleton SharedContext instance.
|
|
44
|
+
|
|
45
|
+
Returns:
|
|
46
|
+
The shared context instance.
|
|
47
|
+
"""
|
|
48
|
+
if cls._instance is None:
|
|
49
|
+
with cls._lock:
|
|
50
|
+
if cls._instance is None:
|
|
51
|
+
cls._instance = cls()
|
|
52
|
+
return cls._instance
|
|
53
|
+
|
|
54
|
+
@property
|
|
55
|
+
def context(self) -> Context:
|
|
56
|
+
"""
|
|
57
|
+
Get the underlying caproto Context, creating it if necessary.
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
The caproto threading Context.
|
|
61
|
+
"""
|
|
62
|
+
if self._context is None:
|
|
63
|
+
self._context = Context()
|
|
64
|
+
return self._context
|
|
65
|
+
|
|
66
|
+
def get_pv(self, pv_name: str) -> CaprotoPV:
|
|
67
|
+
"""
|
|
68
|
+
Get or create a PV connection.
|
|
69
|
+
|
|
70
|
+
Args:
|
|
71
|
+
pv_name: The name of the PV to connect to.
|
|
72
|
+
|
|
73
|
+
Returns:
|
|
74
|
+
The caproto PV object.
|
|
75
|
+
"""
|
|
76
|
+
if pv_name not in self._pvs:
|
|
77
|
+
(pv,) = self.context.get_pvs(pv_name)
|
|
78
|
+
self._pvs[pv_name] = pv
|
|
79
|
+
return self._pvs[pv_name]
|
|
80
|
+
|
|
81
|
+
def clear(self) -> None:
|
|
82
|
+
"""
|
|
83
|
+
Clear all cached PVs and reset the context.
|
|
84
|
+
|
|
85
|
+
Useful for testing or when reconfiguring the connection.
|
|
86
|
+
"""
|
|
87
|
+
self._pvs.clear()
|
|
88
|
+
self._context = None
|
|
89
|
+
|
|
90
|
+
@classmethod
|
|
91
|
+
def reset(cls) -> None:
|
|
92
|
+
"""
|
|
93
|
+
Reset the singleton instance entirely.
|
|
94
|
+
|
|
95
|
+
Primarily used for testing to ensure a clean state.
|
|
96
|
+
"""
|
|
97
|
+
with cls._lock:
|
|
98
|
+
if cls._instance is not None:
|
|
99
|
+
cls._instance.clear()
|
|
100
|
+
cls._instance = None
|