Skip to content

Commit 306e796

Browse files
committed
feat: add scan customization modules
1 parent d194bc5 commit 306e796

4 files changed

Lines changed: 48 additions & 0 deletions

File tree

template/pyproject.toml.jinja

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ plugin_file_writer = "{{ project_name }}.file_writer"
3939
[project.entry-points."bec.scans"]
4040
plugin_scans = "{{ project_name }}.scans"
4141

42+
[project.entry-points."bec.scans.scan_modifier"]
43+
plugin_scan_modifier = "{{ project_name }}.scans.scan_customization.scan_modifier"
44+
4245
[project.entry-points."bec.scans.metadata_schema"]
4346
plugin_metadata_schema = "{{ project_name }}.scans.metadata_schema"
4447

template/{{project_name}}/scans/scan_customization/__init__.py

Whitespace-only changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""
2+
Scan components for {{ project_name }}.
3+
4+
The scan components module allows you to define custom components that can be used in your scans.
5+
These components can be used to encapsulate reusable logic, interact with devices, or perform specific actions during the scan lifecycle.
6+
"""
7+
8+
from bec_server.scan_server.scans.scan_components import ScanComponents
9+
10+
{% set project_name_pascal = project_name|replace("_", " ")|title|replace(" ", "") %}
11+
class {{ project_name_pascal }}ScanComponents(ScanComponents):
12+
"""Scan components for {{ project_name }}."""
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
Scan modifier plugin for {{ project_name }}.
3+
4+
The scan modifier allows you to modify the scan lifecycle and run custom actions before or after the scan hook or replace the scan hook entirely.
5+
Note that the scan_modifier module must be registered as a plugin in the pyproject.toml file for it to be recognized by the BEC framework and that
6+
there can only be one scan_modifier plugin registered at a time. If you need to run multiple scan modifiers, you can create a single scan
7+
modifier plugin that runs multiple actions in sequence with conditional logic to determine which actions to run based on the scan context.
8+
"""
9+
10+
from bec_server.scan_server.scans.scan_modifier import ScanModifier, scan_hook_impl
11+
12+
{% set project_name_pascal = project_name|replace("_", " ")|title|replace(" ", "") %}
13+
class {{ project_name_pascal }}ScanModifier(ScanModifier):
14+
"""
15+
Scan modifier for {{ project_name }}.
16+
17+
By inheriting from the ScanModifier base class, you get access to currently running scan (self.scan), the devices (self.dev), the scan info (self.scan_info),
18+
the scan components (self.components) and the scan actions (self.actions).
19+
"""
20+
21+
def __init__(self, **kwargs):
22+
"""Initialize the scan modifier."""
23+
super().__init__(**kwargs)
24+
25+
# Example of running code before the scan stage for a specific scan
26+
# @scan_hook_impl("stage", "before")
27+
# def before_stage(self):
28+
# """Run before the stage hook."""
29+
# self.actions.send_client_info("Custom stage logic executed by ScanModifier.")
30+
# if self.scan_info.scan_name == "example_scan":
31+
# self.dev.samx.set(20)
32+
33+

0 commit comments

Comments
 (0)