From 0c5a9861a04eef0cfe6cbf72e1532d5e610150d6 Mon Sep 17 00:00:00 2001 From: David Perl Date: Tue, 19 May 2026 15:27:59 +0200 Subject: [PATCH 01/13] Update repo with template version v1.3.0 --- .copier-answers.yml | 2 +- .gitea/workflows/ci.yml | 23 +++++---- .gitea/workflows/create_update_pr.yml | 50 ++++++++++++++++++- .gitlab-ci.yml | 7 --- .../scans/scan_customization/__init__.py | 0 .../scan_customization/scan_components.py | 12 +++++ .../scans/scan_customization/scan_modifier.py | 33 ++++++++++++ pyproject.toml | 5 +- 8 files changed, 113 insertions(+), 19 deletions(-) delete mode 100644 .gitlab-ci.yml create mode 100644 bec_testing_plugin/scans/scan_customization/__init__.py create mode 100644 bec_testing_plugin/scans/scan_customization/scan_components.py create mode 100644 bec_testing_plugin/scans/scan_customization/scan_modifier.py diff --git a/.copier-answers.yml b/.copier-answers.yml index 39bfe07..49b84df 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.3.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/ci.yml b/.gitea/workflows/ci.yml index ab4aa4c..63a9e47 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -28,7 +28,7 @@ on: description: "Python version to use" required: false type: string - default: "3.11" + default: "3.12" permissions: pull-requests: write @@ -44,7 +44,19 @@ jobs: - name: Setup Python uses: actions/setup-python@v5 with: - python-version: "${{ inputs.PYTHON_VERSION || '3.11' }}" + python-version: "${{ inputs.PYTHON_VERSION || '3.12' }}" + + - name: Checkout BEC Plugin Repository + uses: actions/checkout@v4 + with: + repository: bec/bec_testing_plugin + ref: "${{ inputs.BEC_PLUGIN_REPO_BRANCH || github.head_ref || github.sha }}" + path: ./bec_testing_plugin + + - name: Lint for merge conflicts from template updates + shell: bash + # Find all Copier conflicts except this line + run: '! grep -r "<<<<<<< before updating" | grep -v "grep -r \"<<<<<<< before updating"' - name: Checkout BEC Core uses: actions/checkout@v4 @@ -67,13 +79,6 @@ jobs: ref: "${{ inputs.BEC_WIDGETS_BRANCH || 'main' }}" path: ./bec_widgets - - name: Checkout BEC Plugin Repository - uses: actions/checkout@v4 - with: - repository: bec/bec_testing_plugin - ref: "${{ inputs.BEC_PLUGIN_REPO_BRANCH || github.head_ref || github.sha }}" - path: ./bec_testing_plugin - - name: Install dependencies shell: bash run: | diff --git a/.gitea/workflows/create_update_pr.yml b/.gitea/workflows/create_update_pr.yml index b05543a..7148989 100644 --- a/.gitea/workflows/create_update_pr.yml +++ b/.gitea/workflows/create_update_pr.yml @@ -6,8 +6,16 @@ permissions: pull-requests: write jobs: +<<<<<<< before updating test: runs-on: ubuntu-latest +======= + create_update_branch_and_pr: + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write +>>>>>>> after updating steps: - name: Setup Python @@ -17,16 +25,56 @@ jobs: - name: Install tools run: | +<<<<<<< before updating pip install copier +======= + pip install copier PySide6 +>>>>>>> after updating - name: Checkout uses: actions/checkout@v4 - name: Perform update run: | +<<<<<<< before updating branch="chore/update-template-$(python -m uuid)" git checkout -b $branch msg = $(copier update --trust --defaults --conflict inline 2>&1 | sed -n 1p) git add -A git diff-index --quiet HEAD || git commit -a -m $msg - git push -u origin $branch \ No newline at end of file + git push -u origin $branch +======= + 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..." + output="$(copier update --trust --defaults --conflict inline 2>&1)" + 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\" + }" +>>>>>>> after updating 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 0d540c9..a812d2a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" name = "bec_testing_plugin" version = "0.0.0" 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" -- 2.52.0 From 633552307eb6d3e11be59abb77e6dfc7dc83edac Mon Sep 17 00:00:00 2001 From: David Perl Date: Tue, 19 May 2026 15:30:41 +0200 Subject: [PATCH 02/13] fix: resolve conflicts --- .gitea/workflows/create_update_pr.yml | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/.gitea/workflows/create_update_pr.yml b/.gitea/workflows/create_update_pr.yml index 7148989..4373205 100644 --- a/.gitea/workflows/create_update_pr.yml +++ b/.gitea/workflows/create_update_pr.yml @@ -6,16 +6,11 @@ permissions: pull-requests: write jobs: -<<<<<<< before updating - test: - runs-on: ubuntu-latest -======= create_update_branch_and_pr: runs-on: ubuntu-latest permissions: contents: write pull-requests: write ->>>>>>> after updating steps: - name: Setup Python @@ -25,25 +20,13 @@ jobs: - name: Install tools run: | -<<<<<<< before updating - pip install copier -======= pip install copier PySide6 ->>>>>>> after updating - name: Checkout uses: actions/checkout@v4 - name: Perform update run: | -<<<<<<< before updating - branch="chore/update-template-$(python -m uuid)" - git checkout -b $branch - msg = $(copier update --trust --defaults --conflict inline 2>&1 | sed -n 1p) - git add -A - git diff-index --quiet HEAD || git commit -a -m $msg - git push -u origin $branch -======= git config --global user.email "bec_ci_staging@psi.ch" git config --global user.name "BEC automated CI" @@ -77,4 +60,3 @@ jobs: \"head\": \"$(echo $branch)\", \"base\": \"main\" }" ->>>>>>> after updating -- 2.52.0 From dceb5bf029c7f2438bd9d485e49221e160c9c9e2 Mon Sep 17 00:00:00 2001 From: David Perl Date: Tue, 19 May 2026 15:32:17 +0200 Subject: [PATCH 03/13] Update repo with template version v1.3.1 --- .copier-answers.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.copier-answers.yml b/.copier-answers.yml index 49b84df..0dbbd29 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.3.0 +_commit: v1.3.1 _src_path: https://github.com/bec-project/plugin_copier_template.git make_commit: true project_name: bec_testing_plugin -- 2.52.0 From 8d7713aae28c75bd1a748e5e7d84304f6eecf12f Mon Sep 17 00:00:00 2001 From: David Perl Date: Tue, 19 May 2026 15:36:29 +0200 Subject: [PATCH 04/13] test... --- .gitea/workflows/create_update_pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/create_update_pr.yml b/.gitea/workflows/create_update_pr.yml index 4373205..940bf24 100644 --- a/.gitea/workflows/create_update_pr.yml +++ b/.gitea/workflows/create_update_pr.yml @@ -20,7 +20,7 @@ jobs: - name: Install tools run: | - pip install copier PySide6 + pip install bec_lib copier PySide6 - name: Checkout uses: actions/checkout@v4 -- 2.52.0 From 60f67f7c63cab71ae73cc1c42a72c45f0610a3c2 Mon Sep 17 00:00:00 2001 From: David Perl Date: Tue, 19 May 2026 15:40:51 +0200 Subject: [PATCH 05/13] test tee... --- .gitea/workflows/create_update_pr.yml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/.gitea/workflows/create_update_pr.yml b/.gitea/workflows/create_update_pr.yml index 940bf24..00befae 100644 --- a/.gitea/workflows/create_update_pr.yml +++ b/.gitea/workflows/create_update_pr.yml @@ -1,4 +1,4 @@ -name: Create template upgrade PR for bec_testing_plugin +name: Create template upgrade PR for {{ project_name }} on: workflow_dispatch: @@ -17,14 +17,14 @@ jobs: uses: actions/setup-python@v5 with: python-version: '3.12' - + - name: Install tools run: | - pip install bec_lib copier PySide6 + pip install copier PySide6 bec_lib - name: Checkout uses: actions/checkout@v4 - + - name: Perform update run: | git config --global user.email "bec_ci_staging@psi.ch" @@ -35,8 +35,10 @@ jobs: git checkout -b $branch echo "Running copier update..." - output="$(copier update --trust --defaults --conflict inline 2>&1)" - echo "$output" + 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 @@ -51,8 +53,8 @@ jobs: 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 }}" \ + 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)\", -- 2.52.0 From f51e7dbd5b0deeb543dcd7b072b9aa4b9abbc6f1 Mon Sep 17 00:00:00 2001 From: David Perl Date: Tue, 19 May 2026 15:45:31 +0200 Subject: [PATCH 06/13] test set version one back --- .copier-answers.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.copier-answers.yml b/.copier-answers.yml index 0dbbd29..49b84df 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.3.1 +_commit: v1.3.0 _src_path: https://github.com/bec-project/plugin_copier_template.git make_commit: true project_name: bec_testing_plugin -- 2.52.0 From 89d6e9148fe6c5c0bee7e83ab777141ff8228866 Mon Sep 17 00:00:00 2001 From: David Perl Date: Tue, 19 May 2026 15:54:17 +0200 Subject: [PATCH 07/13] double check bec_lib installation --- .gitea/workflows/create_update_pr.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/create_update_pr.yml b/.gitea/workflows/create_update_pr.yml index 00befae..9cecb9b 100644 --- a/.gitea/workflows/create_update_pr.yml +++ b/.gitea/workflows/create_update_pr.yml @@ -16,12 +16,12 @@ jobs: - name: Setup Python uses: actions/setup-python@v5 with: - python-version: '3.12' + python-version: "3.12" - name: Install tools run: | pip install copier PySide6 bec_lib - + python -c "import bec_lib; print(bec_lib.__file__)" - name: Checkout uses: actions/checkout@v4 @@ -33,7 +33,7 @@ jobs: branch="chore/update-template-$(python -m uuid)" echo "switching to branch $branch" git checkout -b $branch - + python -c "import bec_lib; print(bec_lib.__file__)" echo "Running copier update..." copier update --trust --defaults --conflict inline 2>&1 | tee copier.log status=${PIPESTATUS[0]} -- 2.52.0 From 679da87ca261aa3d1f155b238df088f4ed05fb90 Mon Sep 17 00:00:00 2001 From: David Perl Date: Tue, 19 May 2026 16:00:36 +0200 Subject: [PATCH 08/13] use selected python to pip install --- .gitea/workflows/create_update_pr.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/create_update_pr.yml b/.gitea/workflows/create_update_pr.yml index 9cecb9b..96637af 100644 --- a/.gitea/workflows/create_update_pr.yml +++ b/.gitea/workflows/create_update_pr.yml @@ -20,7 +20,10 @@ jobs: - name: Install tools run: | - pip install copier PySide6 bec_lib + echo $(which python) + echo $(python -m pip list) + python -m pip install copier PySide6 bec_lib + echo $(which copier) python -c "import bec_lib; print(bec_lib.__file__)" - name: Checkout uses: actions/checkout@v4 @@ -33,9 +36,9 @@ jobs: branch="chore/update-template-$(python -m uuid)" echo "switching to branch $branch" git checkout -b $branch - python -c "import bec_lib; print(bec_lib.__file__)" + echo "Running copier update..." - copier update --trust --defaults --conflict inline 2>&1 | tee copier.log + python -m copier update --trust --defaults --conflict inline 2>&1 | tee copier.log status=${PIPESTATUS[0]} output="$(cat copier.log)" echo $output -- 2.52.0 From c66182ce734e008e7a5175ae57538a6bd94eb3a0 Mon Sep 17 00:00:00 2001 From: David Perl Date: Tue, 19 May 2026 16:07:36 +0200 Subject: [PATCH 09/13] use venv --- .gitea/workflows/create_update_pr.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.gitea/workflows/create_update_pr.yml b/.gitea/workflows/create_update_pr.yml index 96637af..cbad696 100644 --- a/.gitea/workflows/create_update_pr.yml +++ b/.gitea/workflows/create_update_pr.yml @@ -18,8 +18,13 @@ jobs: with: python-version: "3.12" + - name: Create env + run: | + python -m virtualenv .venv + - name: Install tools run: | + source .venv/bin/activate echo $(which python) echo $(python -m pip list) python -m pip install copier PySide6 bec_lib @@ -30,6 +35,7 @@ jobs: - 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" -- 2.52.0 From 02db4aca5c13ce7ff5f0a85d9f56e257786f88c3 Mon Sep 17 00:00:00 2001 From: David Perl Date: Tue, 19 May 2026 16:09:36 +0200 Subject: [PATCH 10/13] debug --- .gitea/workflows/create_update_pr.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitea/workflows/create_update_pr.yml b/.gitea/workflows/create_update_pr.yml index cbad696..1a37e12 100644 --- a/.gitea/workflows/create_update_pr.yml +++ b/.gitea/workflows/create_update_pr.yml @@ -35,6 +35,7 @@ jobs: - name: Perform update run: | + tree ../.. source .venv/bin/activate git config --global user.email "bec_ci_staging@psi.ch" git config --global user.name "BEC automated CI" -- 2.52.0 From 6296b3d809550813f4a2ed4d1a41bd29d7d60042 Mon Sep 17 00:00:00 2001 From: David Perl Date: Tue, 19 May 2026 16:11:15 +0200 Subject: [PATCH 11/13] ... --- .gitea/workflows/create_update_pr.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/create_update_pr.yml b/.gitea/workflows/create_update_pr.yml index 1a37e12..8f81f0b 100644 --- a/.gitea/workflows/create_update_pr.yml +++ b/.gitea/workflows/create_update_pr.yml @@ -18,7 +18,10 @@ jobs: with: python-version: "3.12" - - name: Create env + - name: Checkout + uses: actions/checkout@v4 + + - name: Create virtualenv run: | python -m virtualenv .venv @@ -30,12 +33,9 @@ jobs: python -m pip install copier PySide6 bec_lib echo $(which copier) python -c "import bec_lib; print(bec_lib.__file__)" - - name: Checkout - uses: actions/checkout@v4 - name: Perform update run: | - tree ../.. source .venv/bin/activate git config --global user.email "bec_ci_staging@psi.ch" git config --global user.name "BEC automated CI" -- 2.52.0 From 39ea9ea20b658d68bc5e2b68aa17c2ae9f970ded Mon Sep 17 00:00:00 2001 From: David Perl Date: Tue, 19 May 2026 16:14:49 +0200 Subject: [PATCH 12/13] fix syntax --- .gitea/workflows/create_update_pr.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/create_update_pr.yml b/.gitea/workflows/create_update_pr.yml index 8f81f0b..cb7957c 100644 --- a/.gitea/workflows/create_update_pr.yml +++ b/.gitea/workflows/create_update_pr.yml @@ -63,8 +63,8 @@ jobs: 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 }}" }}" \ + 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)\", -- 2.52.0 From eeee1696c758dd6c74af9c9b7c6ef582f68b0aef Mon Sep 17 00:00:00 2001 From: BEC automated CI Date: Tue, 19 May 2026 14:16:06 +0000 Subject: [PATCH 13/13] Update repo with template version v1.3.1 --- .copier-answers.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.copier-answers.yml b/.copier-answers.yml index 49b84df..0dbbd29 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.3.0 +_commit: v1.3.1 _src_path: https://github.com/bec-project/plugin_copier_template.git make_commit: true project_name: bec_testing_plugin -- 2.52.0