Skip to content

Commit

Permalink
Merge pull request #2 from NSLS-II-SRX/add-zebra-ioc
Browse files Browse the repository at this point in the history
Add caproto Zebra IOC
  • Loading branch information
mrakitin authored May 17, 2024
2 parents a90fbbe + 9dc73ff commit d5ed90d
Show file tree
Hide file tree
Showing 20 changed files with 1,125 additions and 32 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,4 @@ jobs:
- uses: pypa/gh-action-pypi-publish@release/v1
if: github.event_name == 'release' && github.event.action == 'published'
with:
# Remember to tell (test-)pypi about this repo before publishing
# Remove this line to publish to PyPI
repository-url: https://test.pypi.org/legacy/
packages-dir: ./dist/
64 changes: 52 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ on:
workflow_dispatch:
pull_request:
push:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down Expand Up @@ -34,36 +32,78 @@ jobs:
pipx run nox -s pylint
checks:
# pull requests are a duplicate of a branch push if within the same repo.
if:
github.event_name != 'pull_request' ||
github.event.pull_request.head.repo.full_name != github.repository

name: Check Python ${{ matrix.python-version }} on ${{ matrix.runs-on }}
runs-on: ${{ matrix.runs-on }}
needs: [pre-commit]
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.12"]
runs-on: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11"]
# runs-on: [ubuntu-latest, macos-latest, windows-latest]
runs-on: [ubuntu-latest]

# include:
# - python-version: pypy-3.10
# runs-on: ubuntu-latest
env:
TZ: America/New_York

include:
- python-version: pypy-3.10
runs-on: ubuntu-latest
defaults:
run:
shell: bash -l {0}

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-python@v5
- name: Set env vars
run: |
set -x
export REPOSITORY_NAME=${GITHUB_REPOSITORY#*/} # just the repo, as opposed to org/repo
echo "REPOSITORY_NAME=${REPOSITORY_NAME}" >> $GITHUB_ENV
export PYTHONVER=$(echo ${{ matrix.python-version }} | sed 's/\.//g')
echo "PYTHONVER=${PYTHONVER}" >> $GITHUB_ENV
export DATETIME_STRING=$(date +%Y%m%d%H%M%S)
echo "DATETIME_STRING=${DATETIME_STRING}" >> $GITHUB_ENV
# - uses: actions/setup-python@v5
# with:
# python-version: ${{ matrix.python-version }}
# allow-prereleases: true

- name: Set up Python ${{ matrix.python-version }} with conda
uses: mamba-org/setup-micromamba@v1
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
init-shell: bash
environment-name: ${{env.REPOSITORY_NAME}}-py${{matrix.python-version}}
create-args: >-
python=${{ matrix.python-version }} epics-base setuptools<67
- name: Install package
run: python -m pip install .[test]
run: |
set -vxeuo pipefail
which caput
python -m pip install .[test]
- name: Test package
run: >-
python -m pytest -ra --cov --cov-report=xml --cov-report=term
--durations=20
--durations=20 -m "(not hardware) and (not tiled)" -s -vv
- name: Upload test artifacts
uses: actions/upload-artifact@v4
with:
name: ${{env.REPOSITORY_NAME}}-py${{env.PYTHONVER}}-${{env.DATETIME_STRING}}
path: /tmp/srx-caproto-iocs/
retention-days: 14

- name: Upload coverage report
uses: codecov/[email protected]
22 changes: 11 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,27 @@ repos:
- id: rst-inline-touching-normal

- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.1.0"
rev: "v4.0.0-alpha.8"
hooks:
- id: prettier
types_or: [yaml, markdown, html, css, scss, javascript, json]
args: [--prose-wrap=always]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.1.14"
rev: "v0.2.1"
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.8.0"
hooks:
- id: mypy
files: src|tests
args: []
additional_dependencies:
- pytest
# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: "v1.8.0"
# hooks:
# - id: mypy
# files: src|tests
# args: []
# additional_dependencies:
# - pytest

- repo: https://github.com/codespell-project/codespell
rev: "v2.2.6"
Expand All @@ -80,7 +80,7 @@ repos:
additional_dependencies: ["validate-pyproject-schema-store[all]"]

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: "0.27.3"
rev: "0.28.0"
hooks:
- id: check-dependabot
- id: check-github-workflows
Expand Down
28 changes: 22 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["hatchling", "hatch-vcs"]
requires = ["hatchling", "hatch-vcs", "setuptools>=61,<67"]
build-backend = "hatchling.build"


Expand Down Expand Up @@ -30,14 +30,25 @@ classifiers = [
"Typing :: Typed",
]
dynamic = ["version"]
dependencies = []
dependencies = [
"caproto",
"h5py",
"numpy",
"ophyd",
"pyepics", # does not work with 'setuptools' version higher than v66.1.1
"scikit-image[data]",
]

[project.optional-dependencies]
test = [
"pytest >=6",
"pytest-cov >=3",
]
dev = [
"ipython",
"nexpy",
"pre-commit",
"pylint",
"pytest >=6",
"pytest-cov >=3",
]
Expand Down Expand Up @@ -76,7 +87,12 @@ log_cli_level = "INFO"
testpaths = [
"tests",
]

markers = [
"hardware: marks tests as requiring the hardware IOC to be available/running (deselect with '-m \"not hardware\"')",
"tiled: marks tests as requiring tiled",
"cloud_friendly: marks tests to be able to execute in the CI in the cloud",
"needs_epics_core: marks tests as requiring epics-core executables such as caget, caput, etc."
]

[tool.coverage]
run.source = ["srx_caproto_iocs"]
Expand Down Expand Up @@ -108,7 +124,7 @@ src = ["src"]
extend-select = [
"B", # flake8-bugbear
"I", # isort
"ARG", # flake8-unused-arguments
# "ARG", # flake8-unused-arguments
"C4", # flake8-comprehensions
"EM", # flake8-errmsg
"ICN", # flake8-import-conventions
Expand All @@ -119,9 +135,9 @@ extend-select = [
"PT", # flake8-pytest-style
"PTH", # flake8-use-pathlib
"RET", # flake8-return
"RUF", # Ruff-specific
# "RUF", # Ruff-specific
"SIM", # flake8-simplify
"T20", # flake8-print
# "T20", # flake8-print
"UP", # pyupgrade
"YTT", # flake8-2020
"EXE", # flake8-executable
Expand Down
7 changes: 7 additions & 0 deletions scripts/run-act.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

set -vxeuo pipefail

PYTHON_VERSION="${1:-3.11}"

act -W .github/workflows/ci.yml -j checks --matrix python-version:"${PYTHON_VERSION}"
16 changes: 16 additions & 0 deletions scripts/run-caproto-ioc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -vxeuo pipefail

CAPROTO_IOC="${1:-srx_caproto_iocs.base}"
DEFAULT_PREFIX="BASE:{{Dev:Save1}}:"
CAPROTO_IOC_PREFIX="${2:-${DEFAULT_PREFIX}}"
# shellcheck source=/dev/null
if [ -f "/etc/profile.d/epics.sh" ]; then
. /etc/profile.d/epics.sh
fi

export EPICS_CAS_AUTO_BEACON_ADDR_LIST="no"
export EPICS_CAS_BEACON_ADDR_LIST="${EPICS_CA_ADDR_LIST:-127.0.0.255}"

python -m "${CAPROTO_IOC}" --prefix="${CAPROTO_IOC_PREFIX}" --list-pvs
7 changes: 7 additions & 0 deletions scripts/run-caproto-zebra-ioc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

set -vxeuo pipefail

SCRIPT_DIR="$(dirname "$0")"

bash "${SCRIPT_DIR}/run-caproto-ioc.sh" srx_caproto_iocs.zebra.caproto_ioc "XF:05IDD-ES:1{{Dev:Zebra2}}:"
29 changes: 29 additions & 0 deletions scripts/test-file-saving.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

set -euo pipefail

# shellcheck source=/dev/null
if [ -f "/etc/profile.d/epics.sh" ]; then
. /etc/profile.d/epics.sh
fi

num="${1:-50}"

data_dir="/tmp/test/$(date +%Y/%m/%d)"
mkdir -v -p "${data_dir}"

caput "BASE:{Dev:Save1}:write_dir" "${data_dir}"
caput "BASE:{Dev:Save1}:file_name" "saveme_{num:06d}_{uid}.h5"
caput "BASE:{Dev:Save1}:stage" 1
caget -S "BASE:{Dev:Save1}:full_file_path"
for i in $(seq "$num"); do
echo "$i"
sleep 0.1
caput "BASE:{Dev:Save1}:acquire" 1
done

caput "BASE:{Dev:Save1}:stage" 0

caget -S "BASE:{Dev:Save1}:full_file_path"

exit 0
Loading

0 comments on commit d5ed90d

Please sign in to comment.