Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
name: p4p_ext

on: [push, pull_request, workflow_dispatch]
on:
push:
branches-ignore:
- "documentation"
pull_request:
branches-ignore:
- "documentation"
workflow_dispatch:
# Allow manual triggering of workflow

jobs:
lint:
Expand All @@ -23,7 +31,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest] #, mac-latest]
python-version: ["3.10", "3.11", "3.12"]
python-version: ["3.10", "3.11", "3.12", "3.13"]
runs-on: ${{ matrix.os }}
continue-on-error: true
steps:
Expand All @@ -34,10 +42,8 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install git+https://github.com/ISISNeutronMuon/p4p
pip install .[test]
PIP_PATH=$(which pip)
$PIP_PATH install .[test]
- name: Run tests
run: |
PYTHON_PATH=$(which python)
Expand All @@ -60,6 +66,7 @@ jobs:
name: Build distribution 📦
needs:
- test
if: github.ref == 'refs/heads/main' # Only build dist on main
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
1 change: 0 additions & 1 deletion .python-version

This file was deleted.

2 changes: 1 addition & 1 deletion examples/thread/mailbox_sharedntenum.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from p4p.nt import NTEnum
from p4p.server import Server

from p4p_ext.nt import NTEnum
from p4p_ext.thread.sharednt import SharedNT

pv = SharedNT(
Expand Down
3 changes: 1 addition & 2 deletions p4p_ext/asyncio/pvrecipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

from __future__ import annotations

from p4p.server.asyncio import SharedPV

from p4p_ext.definitions import PVTypes
from p4p_ext.nthandlers import NTEnumRulesHandler, NTScalarArrayRulesHandler, NTScalarRulesHandler
from p4p_ext.pvrecipe import BasePVRecipe
from p4p_ext.pvrecipe import PVScalarRecipe as _PVScalarRecipe
from p4p_ext.server.asyncio import SharedPV


class PVScalarRecipe(_PVScalarRecipe):
Expand Down
3 changes: 2 additions & 1 deletion p4p_ext/composite_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

from p4p import Value
from p4p.server import ServerOperation
from p4p.server.raw import Handler, SharedPV

from p4p_ext.server.raw import Handler, SharedPV


class HandlerException(Exception):
Expand Down
10 changes: 10 additions & 0 deletions p4p_ext/nt/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""
Monkey patch in required changes to NTEnum
"""

from p4p.nt import * # type: ignore # noqa: F403
from p4p.nt import NTBase, NTEnum # noqa: F401

from p4p_ext.nt.enum import NTEnum as _NTEnum

NTEnum = _NTEnum # noqa: F811
50 changes: 50 additions & 0 deletions p4p_ext/nt/enum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""
Monkey patch in required changes to NTEnum
"""

# pylint: disable=unused-wildcard-import, wildcard-import
from p4p import version as __p4p_version
from p4p.nt.enum import * # pyright: ignore[reportWildcardImportFromLibrary] # noqa: F403
from p4p.nt.enum import NTEnum
from p4p.nt.scalar import ntwrappercommon
from p4p.wrapper import Value

if __p4p_version > "4.2.1":
pass
else:

def __wrap(self, value, choices=None, **kws):
"""Pack python value into Value

Accepts dict to explicitly initialize fields by name.
Any other type is assigned to the 'value' field via
the self.assign() method.
"""
if isinstance(value, Value):
pass
elif isinstance(value, ntwrappercommon):
kws.setdefault("timestamp", value.timestamp)
value = value.raw
elif isinstance(value, dict):
# if index, choices not in value.keys(), then
# use value dict to initalize fields by name
if {"index", "choices"}.isdisjoint(value):
value = self.Value(self.type, value)
# if value = {'index': ..., 'choices': ...}, then
# assign these to value.index, value.choices
else:
value = self.Value(self.type, {"value": value})
else:
# index or string
V = self.type()
if choices is not None:
V["value.choices"] = choices
self.assign(V, value)
value = V

# pylint: disable=W0212
self._choices = value["value.choices"] or self._choices # pyright: ignore[reportOptionalSubscript]
return self._annotate(value, **kws) # pylint: disable=W0212

NTEnum.Value = Value # pyright: ignore[reportAttributeAccessIssue]
NTEnum.wrap = __wrap
2 changes: 1 addition & 1 deletion p4p_ext/nthandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

from p4p import Value
from p4p.server import ServerOperation
from p4p.server.raw import Handler, SharedPV

from p4p_ext.composite_handler import AbortHandlerException
from p4p_ext.server.raw import Handler, SharedPV
from p4p_ext.utils import overwrite_unmarked

from .rules import (
Expand Down
7 changes: 3 additions & 4 deletions p4p_ext/pvrecipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
from typing import Generic, TypeVar
from typing import SupportsFloat as Numeric # Hack to type hint number types

from p4p.nt import NTEnum, NTScalar
from p4p.server.asyncio import SharedPV as SharedPV_asyncio
from p4p.server.thread import SharedPV as SharedPV_threaded

from p4p_ext.nt import NTEnum, NTScalar
from p4p_ext.server.asyncio import SharedPV as SharedPV_asyncio
from p4p_ext.server.thread import SharedPV as SharedPV_threaded
from p4p_ext.thread.sharednt import SharedNT

from .definitions import (
Expand Down
Empty file added p4p_ext/server/__init__.py
Empty file.
24 changes: 24 additions & 0 deletions p4p_ext/server/asyncio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
Monkey patch in required changes to Handlers and SharedPVs
"""

####
# First override the base class of p4p_ext.server.thread.SharedPV with
# p4p_ext.server.raw.SharedPV. This requires us to perform the imports
# in a very specific order, which means overriding Linter checks
import p4p.server.raw

from p4p_ext.server.raw import SharedPV as _SharedPV

p4p.server.raw.SharedPV = _SharedPV

# pylint: disable=unused-import, wrong-import-order, wrong-import-position
from p4p.server.thread import Handler, SharedPV # noqa: E402, F401,

#####
# Monkey patching the Handler is a simpler operation as it's a straight
# substitution with our new version.
# pylint: disable=ungrouped-imports
from p4p_ext.server.raw import Handler as _Handler # noqa: E402

Handler = _Handler # noqa: F811
Loading