From 65519f950adc6754f9cf0585afd989f88f7e6362 Mon Sep 17 00:00:00 2001 From: koennecke Date: Fri, 21 Aug 2020 14:31:34 +0200 Subject: [PATCH] pyDevSup working as a module in require system --- GNUMakefile | 27 +++++++++++++++++++++++++++ README.module | 30 ++++++++++++++++++++++++++++++ devsupApp/src/dbapi.c | 4 +++- devsupApp/src/devsup/__init__.py | 4 ++++ testApp/test6.py | 2 +- testmodule.cmd | 27 +++++++++++++++++++++++++++ 6 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 GNUMakefile create mode 100644 README.module create mode 100755 testmodule.cmd diff --git a/GNUMakefile b/GNUMakefile new file mode 100644 index 0000000..cbe5739 --- /dev/null +++ b/GNUMakefile @@ -0,0 +1,27 @@ +# This build the sinq extensions for the PSI EPICS setup +include /ioc/tools/driver.makefile + +MODULE=pyDevSup +LIBVERSION=koennecke +BUILDCLASSES=Linux + +# See README.module for more instructions + +DBDS += pyIocApp/pyDevSup.dbd + +SOURCES += pyIocApp/setup.c +SOURCES += devsupApp/src/dbapi.c +SOURCES += devsupApp/src/dbdset.c +SOURCES += devsupApp/src/dbfield.c +SOURCES += devsupApp/src/dbrec.c +SOURCES += devsupApp/src/utest.c +#SOURCES += devsupApp/src/pyDevSupCommon_registerRecordDeviceDriver.cpp + + +USR_CFLAGS += -I/usr/include/python3.6m -DHAVE_NUMPY +USR_CFLAGS += -DXEPICS_ARCH=\"RHEL7-x86_64\" -DXEPICS_BASE=\"/usr/local/epics\" +USR_CFLAGS += -DXPYDEV_BASE=\"$(INSTALL_LOCATION)\" -DPYDIR=\"python3.6\" +USR_LDFLAGS += -L/usr/local/epics/base-3.14.12/lib/RHEL7-x86_64 +LIB_SYS_LIBS += python3.6m +#LIB_SYS_LIBS += python3.6m recIoc softDevIoc miscIoc rsrvIoc dbtoolsIoc asIoc dbIoc registryIoc dbStaticIoc +# MISCS would be the place to keep the stream device template files diff --git a/README.module b/README.module new file mode 100644 index 0000000..418a34b --- /dev/null +++ b/README.module @@ -0,0 +1,30 @@ +# pyDevSup as a module loadable via require + +pyDevSup is not you standard EPICS extension in that it tightly interacts with the +python interpreter. This causes some issues with Dirk Zimochs module system which +allows to load support modules through the require command. Most importantly, +reuire does not know about python and its modules at all. + + +The good news is that it can be made to work but requires a few manual steps. + +1) Build the pyDevSup extension in the normal EPICS way. + +2) This generates a pythonXX/$(EPICS_ARCH)/devsup directory. Copy this directory to + a safe place. + +3) Build the module using the GNUMakefile as normal and install it + +4) Copy the saved devsup directory in some place into pyDevSup's module hierarchy. + For example: /ioc/modules/pyDevSup/koennecke/R3.14.12/lib/devsup + +5) In order to successfuly load pyDevSup with require the directory underneath + where ypu placed pydevsup needs to be on the python path. For example: + /ioc/modules/pyDevSup/koennecke/R3.14.12/lib/ + +With this, one can at least run the testmodule.cmd script and it workd at least +for me. + +Please use the module branch, I had to hack the initialisation of pyDevSup to make +it work as a module. + diff --git a/devsupApp/src/dbapi.c b/devsupApp/src/dbapi.c index 2dab153..14241e3 100644 --- a/devsupApp/src/dbapi.c +++ b/devsupApp/src/dbapi.c @@ -27,7 +27,7 @@ initHookState pyInitLastState; -extern int pyDevSupCommon_registerRecordDeviceDriver(DBBASE *pbase); +/* extern int pyDevSupCommon_registerRecordDeviceDriver(DBBASE *pbase); */ typedef struct { const initHookState state; @@ -264,9 +264,11 @@ PyObject *py_iocInit(PyObject *unused, PyObject *args, PyObject *kws) static PyObject *py_pyDevSupCommon(PyObject *unused) { + /* Py_BEGIN_ALLOW_THREADS { pyDevSupCommon_registerRecordDeviceDriver(pdbbase); } Py_END_ALLOW_THREADS + */ Py_RETURN_NONE; } diff --git a/devsupApp/src/devsup/__init__.py b/devsupApp/src/devsup/__init__.py index dd8da5a..fc093d5 100644 --- a/devsupApp/src/devsup/__init__.py +++ b/devsupApp/src/devsup/__init__.py @@ -46,6 +46,10 @@ from ._dbapi import (EPICS_VERSION_STRING, __all__ = [] def _init(iocMain=False): + _dbapi._dbd_setup() + return + +def _initOld(iocMain=False): if not iocMain: # we haven't read/register base.dbd _dbapi.dbReadDatabase(os.path.join(XEPICS_BASE, "dbd", "base.dbd"), diff --git a/testApp/test6.py b/testApp/test6.py index 81ad4f3..9378b15 100644 --- a/testApp/test6.py +++ b/testApp/test6.py @@ -19,7 +19,7 @@ class SumTable(PT.TableBase): @inputs.anynotvalid def inval(self): - print self.A.isvalid, self.B.isvalid + print(self.A.isvalid, self.B.isvalid) LOG.debug("%s.update inputs not valid", self.name) self.S.value = None self.S.notify() diff --git a/testmodule.cmd b/testmodule.cmd new file mode 100755 index 0000000..e4a8042 --- /dev/null +++ b/testmodule.cmd @@ -0,0 +1,27 @@ +#! /usr/local/bin/iocsh + +require pyDevSup, koennecke + +py "import logging" +py "logging.basicConfig(level=logging.DEBUG)" + +py "import sys; sys.path.insert(0,'${PWD}/testApp')" +py "print(sys.path)" + +#py "import devsup.hooks" +#py "devsup.hooks.debugHooks()" + +py "import test2" +py "test2.addDrv('AAAA')" +py "test2.addDrv('BBBB')" + +py "import test6" +py "test6.SumTable(name='tsum')" + +dbLoadRecords("db/test.db","P=md:") +dbLoadRecords("db/test6.db","P=tst:,TNAME=tsum") + +iocInit() + +# Start Reference tracker +#py "from devsup import disect; disect.periodic(10)"