7 Commits

Author SHA1 Message Date
2de399d6ca Resolve template update merge conflict
All checks were successful
CI for tomcat_bec / test (pull_request) Successful in 48s
CI for tomcat_bec / test (push) Successful in 47s
2026-02-27 16:18:43 +01:00
51e9dc169c Update repo with template version v1.2.8
Some checks failed
CI for tomcat_bec / test (push) Failing after 6s
CI for tomcat_bec / test (pull_request) Failing after 6s
2026-02-27 15:49:26 +01:00
938401432d Update repo with template version v1.2.7
Some checks failed
CI for tomcat_bec / test (push) Failing after 0s
CI for tomcat_bec / test (pull_request) Failing after 0s
2026-02-27 12:11:40 +01:00
354557262b ci: install dev dependencies
All checks were successful
CI for tomcat_bec / test (pull_request) Successful in 48s
CI for tomcat_bec / test (push) Successful in 48s
2025-11-17 20:36:51 +01:00
1896cc2fe0 fix: add support for additional kwargs in fakeredis
Some checks failed
CI for tomcat_bec / test (push) Failing after 37s
CI for tomcat_bec / test (pull_request) Failing after 37s
2025-11-17 20:33:08 +01:00
c415cbd806 feat: update repo with copier template for gitea migration 2025-09-11 17:15:04 +02:00
76b5e0f5e3 fix(std daq status): improvements to the status callbacks 2025-06-26 17:41:28 +02:00
10 changed files with 209 additions and 27 deletions

View File

@@ -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.0.0
_commit: v1.2.8
_src_path: https://github.com/bec-project/plugin_copier_template.git
make_commit: false
project_name: tomcat_bec

102
.gitea/workflows/ci.yml Normal file
View File

@@ -0,0 +1,102 @@
name: CI for tomcat_bec
on:
push:
pull_request:
workflow_dispatch:
inputs:
BEC_WIDGETS_BRANCH:
description: "Branch of BEC Widgets to install"
required: false
type: string
default: "main"
BEC_CORE_BRANCH:
description: "Branch of BEC Core to install"
required: false
type: string
default: "main"
OPHYD_DEVICES_BRANCH:
description: "Branch of Ophyd Devices to install"
required: false
type: string
default: "main"
BEC_PLUGIN_REPO_BRANCH:
description: "Branch of the BEC Plugin Repository to install"
required: false
type: string
default: "main"
PYTHON_VERSION:
description: "Python version to use"
required: false
type: string
default: "3.12"
permissions:
pull-requests: write
jobs:
test:
runs-on: ubuntu-latest
env:
QTWEBENGINE_DISABLE_SANDBOX: 1
QT_QPA_PLATFORM: "offscreen"
steps:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "${{ inputs.PYTHON_VERSION || '3.12' }}"
- name: Checkout BEC Plugin Repository
uses: actions/checkout@v4
with:
repository: bec/tomcat_bec
ref: "${{ inputs.BEC_PLUGIN_REPO_BRANCH || github.head_ref || github.sha }}"
path: ./tomcat_bec
- 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
with:
repository: bec/bec
ref: "${{ inputs.BEC_CORE_BRANCH || 'main' }}"
path: ./bec
- name: Checkout Ophyd Devices
uses: actions/checkout@v4
with:
repository: bec/ophyd_devices
ref: "${{ inputs.OPHYD_DEVICES_BRANCH || 'main' }}"
path: ./ophyd_devices
- name: Checkout BEC Widgets
uses: actions/checkout@v4
with:
repository: bec/bec_widgets
ref: "${{ inputs.BEC_WIDGETS_BRANCH || 'main' }}"
path: ./bec_widgets
- name: Install dependencies
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y libgl1 libegl1 x11-utils libxkbcommon-x11-0 libdbus-1-3 xvfb
sudo apt-get -y install libnss3 libxdamage1 libasound2t64 libatomic1 libxcursor1
- name: Install Python dependencies
shell: bash
run: |
pip install uv
uv pip install --system -e ./ophyd_devices
uv pip install --system -e ./bec/bec_lib[dev]
uv pip install --system -e ./bec/bec_ipython_client
uv pip install --system -e ./bec/bec_server[dev]
uv pip install --system -e ./bec_widgets[dev,pyside6]
uv pip install --system -e ./tomcat_bec[dev]
- name: Run Pytest with Coverage
id: coverage
run: pytest --random-order --cov=./tomcat_bec --cov-config=./tomcat_bec/pyproject.toml --cov-branch --cov-report=xml --no-cov-on-fail ./tomcat_bec/tests/ || test $? -eq 5

View File

@@ -0,0 +1,62 @@
name: Create template upgrade PR for tomcat_bec
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: Install tools
run: |
pip install copier PySide6
- name: Checkout
uses: actions/checkout@v4
- name: Perform update
run: |
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\"
}"

View File

@@ -1,7 +0,0 @@
include:
- file: /templates/plugin-repo-template.yml
inputs:
name: tomcat_bec
target: tomcat_bec
branch: $CHILD_PIPELINE_BRANCH
project: bec/awi_utils

View File

@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
name = "tomcat_bec"
version = "0.0.0"
description = "The TOMCAT plugin repository for BEC"
requires-python = ">=3.10"
requires-python = ">=3.11"
classifiers = [
"Development Status :: 3 - Alpha",
"Programming Language :: Python :: 3",

View File

@@ -11,7 +11,7 @@ from typeguard import TypeCheckError
from tomcat_bec.devices.std_daq.std_daq_live_processing import StdDaqLiveProcessing
def fake_redis_server(host, port):
def fake_redis_server(host, port, **kwargs):
redis = fakeredis.FakeRedis()
return redis

View File

@@ -3,8 +3,12 @@ Pre-startup script for BEC client. This script is executed before the BEC client
is started. It can be used to add additional command line arguments.
"""
import os
from bec_lib.service_config import ServiceConfig
import tomcat_bec
def extend_command_line_args(parser):
"""
@@ -16,8 +20,13 @@ def extend_command_line_args(parser):
return parser
# def get_config() -> ServiceConfig:
# """
# Create and return the service configuration.
# """
# return ServiceConfig(redis={"host": "localhost", "port": 6379})
def get_config() -> ServiceConfig:
"""
Create and return the ServiceConfig for the plugin repository
"""
deployment_path = os.path.dirname(os.path.dirname(os.path.dirname(tomcat_bec.__file__)))
files = os.listdir(deployment_path)
if "bec_config.yaml" in files:
return ServiceConfig(config_path=os.path.join(deployment_path, "bec_config.yaml"))
else:
return ServiceConfig(redis={"host": "localhost", "port": 6379})

View File

@@ -468,11 +468,15 @@ class StdDaqClient:
Run the count callbacks with the given count.
The callbacks will be called with the count as argument.
"""
for cb in self._count_callbacks.values():
callbacks_ids = list(self._count_callbacks.keys())
for cb_id in callbacks_ids:
if cb_id not in self._count_callbacks:
continue
cb = self._count_callbacks[cb_id]
try:
cb(count)
except Exception as exc:
logger.error(f"Error in StdDAQ count callback: {exc}")
logger.error(f"Error in StdDAQ count callback with ID {cb_id}: {exc}")
def _run_status_callbacks(self):
"""
@@ -481,19 +485,25 @@ class StdDaqClient:
or exception, respectively and removed from the list of callbacks.
"""
status = self._status
completed_callbacks = []
for dev_status, success, error in self._status_callbacks.values():
if dev_status.done:
logger.warning("Status object already resolved. Skipping StdDaq callback.")
status_callbacks_ids = list(self._status_callbacks.keys())
for status_id in status_callbacks_ids:
dev_status, success, error = self._status_callbacks.get(status_id, (None, [], []))
if dev_status is None:
continue
if dev_status.done:
logger.info("Status object already resolved. Skipping StdDaq callback.")
self._status_callbacks.pop(status_id)
continue
if status in success:
dev_status.set_finished()
logger.info(f"StdDaq status is {status}")
completed_callbacks.append(dev_status)
elif status in error:
self._status_callbacks.pop(status_id)
continue
if status in error:
logger.warning(f"StdDaq status is {status}")
dev_status.set_exception(StdDaqError(f"StdDaq status is {status}"))
completed_callbacks.append(dev_status)
for cb in completed_callbacks:
self._status_callbacks.pop(id(cb))
self._status_callbacks.pop(status_id)

View File

@@ -0,0 +1,6 @@
# Macros
This directory is intended to store macros which will be loaded automatically when starting BEC.
Macros are small functions to make repetitive tasks easier. Functions defined in python files in this directory will be accessible from the BEC console.
Please do not put any code outside of function definitions here. If you wish for code to be automatically run when starting BEC, see the startup script at tomcat_bec/bec_ipython_client/startup/post_startup.py
For a guide on writing macros, please see: https://bec.readthedocs.io/en/latest/user/command_line_interface.html#how-to-write-a-macro

View File