diff --git a/.copier-answers.yml b/.copier-answers.yml index 39bfe07..96cb909 100644 --- a/.copier-answers.yml +++ b/.copier-answers.yml @@ -2,7 +2,7 @@ # It is needed to track the repo template version, and editing may break things. # This file will be overwritten by copier on template updates. -_commit: v1.2.2 +_commit: v1.4.0 _src_path: https://github.com/bec-project/plugin_copier_template.git make_commit: true project_name: bec_testing_plugin diff --git a/.gitea/workflows/create_update_pr.yml b/.gitea/workflows/create_update_pr.yml new file mode 100644 index 0000000..71ec645 --- /dev/null +++ b/.gitea/workflows/create_update_pr.yml @@ -0,0 +1,70 @@ +name: Create template upgrade PR for bec_testing_plugin +on: + workflow_dispatch: + +permissions: + pull-requests: write + +jobs: + create_update_branch_and_pr: + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + + steps: + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Checkout + uses: actions/checkout@v4 + + - name: Create virtualenv + run: | + python -m virtualenv .venv + + - name: Install tools + run: | + source .venv/bin/activate + pip install copier PySide6 bec_lib + + - name: Perform update + run: | + source .venv/bin/activate + git config --global user.email "bec_ci_staging@psi.ch" + git config --global user.name "BEC automated CI" + + branch="chore/update-template-$(python -m uuid)" + echo "switching to branch $branch" + git checkout -b $branch + + echo "Running copier update..." + copier update --trust --defaults --conflict inline 2>&1 | tee copier.log + status=${PIPESTATUS[0]} + output="$(cat copier.log)" + echo $output + msg="$(printf '%s\n' "$output" | head -n 1)" + + if ! grep -q "make_commit: true" .copier-answers.yml ; then + echo "Autocommit not made, committing..." + git add -A + git commit -a -m "$msg" + fi + + if diff-index --quiet HEAD ; then + echo "No changes detected" + exit 0 + fi + + git push -u origin $branch + curl -X POST "https://gitea.psi.ch/api/v1/repos/${{ gitea.repository }}/pulls" \ + -H "Authorization: token ${{ secrets.CI_REPO_WRITE }}" \ + -H "Content-Type: application/json" \ + -d "{ + \"title\": \"Template: $(echo $msg)\", + \"body\": \"This PR was created by Gitea Actions\", + \"head\": \"$(echo $branch)\", + \"base\": \"main\" + }" diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 1cbc65b..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,7 +0,0 @@ -include: -- file: /templates/plugin-repo-template.yml - inputs: - name: bec_testing_plugin - target: bec_testing_plugin - branch: $CHILD_PIPELINE_BRANCH - project: bec/awi_utils diff --git a/bec_testing_plugin/scans/scan_customization/__init__.py b/bec_testing_plugin/scans/scan_customization/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bec_testing_plugin/scans/scan_customization/scan_components.py b/bec_testing_plugin/scans/scan_customization/scan_components.py new file mode 100644 index 0000000..97d9728 --- /dev/null +++ b/bec_testing_plugin/scans/scan_customization/scan_components.py @@ -0,0 +1,12 @@ +""" +Scan components for bec_testing_plugin. + +The scan components module allows you to define custom components that can be used in your scans. +These components can be used to encapsulate reusable logic, interact with devices, or perform specific actions during the scan lifecycle. +""" + +from bec_server.scan_server.scans.scan_components import ScanComponents + + +class BecTestingPluginScanComponents(ScanComponents): + """Scan components for bec_testing_plugin.""" diff --git a/bec_testing_plugin/scans/scan_customization/scan_modifier.py b/bec_testing_plugin/scans/scan_customization/scan_modifier.py new file mode 100644 index 0000000..646bde1 --- /dev/null +++ b/bec_testing_plugin/scans/scan_customization/scan_modifier.py @@ -0,0 +1,33 @@ +""" +Scan modifier plugin for bec_testing_plugin. + +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. +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 +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 +modifier plugin that runs multiple actions in sequence with conditional logic to determine which actions to run based on the scan context. +""" + +from bec_server.scan_server.scans.scan_modifier import ScanModifier, scan_hook_impl + + +class BecTestingPluginScanModifier(ScanModifier): + """ + Scan modifier for bec_testing_plugin. + + 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), + the scan components (self.components) and the scan actions (self.actions). + """ + + def __init__(self, **kwargs): + """Initialize the scan modifier.""" + super().__init__(**kwargs) + + # Example of running code before the scan stage for a specific scan + # @scan_hook_impl("stage", "before") + # def before_stage(self): + # """Run before the stage hook.""" + # self.actions.send_client_info("Custom stage logic executed by ScanModifier.") + # if self.scan_info.scan_name == "example_scan": + # self.dev.samx.set(20) + + diff --git a/pyproject.toml b/pyproject.toml index 7efea83..d4f9692 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" name = "bec_testing_plugin" version = "0.3.1" description = "A plugin repository for BEC" -requires-python = ">=3.10" +requires-python = ">=3.11" classifiers = [ "Development Status :: 3 - Alpha", "Programming Language :: Python :: 3", @@ -39,6 +39,9 @@ plugin_file_writer = "bec_testing_plugin.file_writer" [project.entry-points."bec.scans"] plugin_scans = "bec_testing_plugin.scans" +[project.entry-points."bec.scans.scan_modifier"] +plugin_scan_modifier = "bec_testing_plugin.scans.scan_customization.scan_modifier" + [project.entry-points."bec.scans.metadata_schema"] plugin_metadata_schema = "bec_testing_plugin.scans.metadata_schema"