Skip to content

Commit 434d15f

Browse files
committed
Move devIocStats to the root and support ioc.template direct loading
1 parent 3584f8a commit 434d15f

8 files changed

Lines changed: 62 additions & 39 deletions

File tree

‎.gitmodules‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "iocStats"]
2-
path = softioc/iocStats
2+
path = iocStats
33
url = https://github.com/epics-modules/iocStats.git

‎setup.cfg‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ classifiers =
1616
Programming Language :: Python :: 3.8
1717

1818
[options]
19-
packages = find:
20-
21-
[options.packages.find]
22-
# Don't include our test directory in the distribution
23-
exclude = tests
19+
packages = softioc
2420

2521
[options.entry_points]
2622
# Include a command line script
@@ -29,10 +25,10 @@ console_scripts =
2925

3026
[options.package_data]
3127
softioc =
32-
softioc/access.acf
33-
softioc/device.dbd
34-
softioc/iocStats/devIocStats/src/devIocStats.dbd
35-
softioc/iocStats/iocAdmin/Db/*.template
28+
access.acf
29+
device.dbd
30+
devIocStats.dbd
31+
iocStatsDb/*
3632

3733
[flake8]
3834
max-line-length = 80
@@ -43,8 +39,8 @@ extend-ignore =
4339

4440
[tool:pytest]
4541
# Run pytest with all our checkers, and don't spam us with massive tracebacks on error
46-
addopts = --tb=native -vv --flake8 --doctest-modules
42+
addopts = --tb=native -vv --flake8 --doctest-modules --ignore=iocStats --ignore=epicscorelibs
4743

4844
[coverage:run]
4945
# This is covered in the versiongit test suite so exclude it here
50-
omit = */_version_git.py
46+
omit = */_version_git.py

‎setup.py‎

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from setuptools.command.develop import develop
55
import epicscorelibs.path
66
import epicscorelibs.version
7-
from setuptools_dso import DSO, Extension, setup
7+
from setuptools_dso import Extension, setup
88
from epicscorelibs.config import get_config_var
99

1010
# Place the directory containing _version_git on the path
@@ -15,12 +15,15 @@
1515

1616
from _version_git import __version__, get_cmdclass # noqa
1717

18+
sources = ['softioc/extension.c']
19+
1820
devIocStats_OSI = [
1921
"devIocStatsAnalog.c",
2022
"devIocStatsString.c",
2123
"devIocStatsWaveform.c",
2224
"devIocStatsSub.c",
23-
"devIocStatsTest.c"
25+
"devIocStatsTest.c",
26+
"devIocStats.h",
2427
]
2528

2629
devIocStats_OSD = [
@@ -36,32 +39,35 @@
3639
"osdSystemInfo.c",
3740
"osdHostInfo.c",
3841
"osdPIDInfo.c",
42+
"devIocStatsOSD.h",
3943
]
4044

41-
devIocStats_srcs = []
42-
devIocStats_src = os.path.join("softioc", "iocStats", "devIocStats")
43-
devIocStats_default = os.path.join(devIocStats_src, "os", "default")
45+
devIocStats_src = os.path.join("iocStats", "devIocStats")
4446
devIocStats_os = os.path.join(devIocStats_src, "os", get_config_var('OS_CLASS'))
47+
devIocStats_default = os.path.join(devIocStats_src, "os", "default")
48+
49+
def _add_file(f):
50+
if f.endswith(".h"):
51+
# Only add header files if making an sdist
52+
# https://github.com/pypa/packaging-problems/issues/84#issuecomment-383718492
53+
should_add = "sdist" in sys.argv
54+
else:
55+
should_add = True
56+
if should_add:
57+
sources.append(f)
4558

4659
for f in devIocStats_OSI:
47-
devIocStats_srcs.append(os.path.join(devIocStats_src, f))
60+
_add_file(os.path.join(devIocStats_src, f))
4861
for f in devIocStats_OSD:
4962
if os.path.exists(os.path.join(devIocStats_os, f)):
50-
devIocStats_srcs.append(os.path.join(devIocStats_os, f))
63+
_add_file(os.path.join(devIocStats_os, f))
5164
else:
52-
devIocStats_srcs.append(os.path.join(devIocStats_default, f))
53-
54-
#dso = DSO(
55-
# 'softioc.lib.devIocStats',
56-
# devIocStats_srcs,
57-
# include_dirs=[epicscorelibs.path.include_path, devIocStats_src, devIocStats_os, devIocStats_default],
58-
# dsos=['epicscorelibs.lib.Com']
59-
#)
65+
_add_file(os.path.join(devIocStats_default, f))
6066

6167
# Extension with all our C code
6268
ext = Extension(
6369
name='softioc._extension',
64-
sources = ['softioc/extension.c'] + devIocStats_srcs,
70+
sources = sources,
6571
include_dirs=[epicscorelibs.path.include_path, devIocStats_src, devIocStats_os, devIocStats_default],
6672
dsos = ['epicscorelibs.lib.dbCore', 'epicscorelibs.lib.Com'],
6773
define_macros = get_config_var('CPPFLAGS'),
@@ -85,11 +91,10 @@ def install_for_development(self):
8591
version=__version__,
8692
ext_modules = [ext],
8793
install_requires = [
88-
"epicscorelibs==7.0.4.99.1.0a1",
89-
#epicscorelibs.version.abi_requires(),
94+
# Dependency declared in pyproject.toml
95+
epicscorelibs.version.abi_requires(),
9096
"numpy>=1.18",
9197
"epicsdbbuilder>=1.4"
9298
],
93-
#x_dsos = [dso],
9499
zip_safe = False, # setuptools_dso is not compatible with eggs!
95100
)

‎softioc/builder.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010

1111
iocshRegisterCommon()
1212
dbLoadDatabase("base.dbd", os.path.join(path.base_path, "dbd"))
13-
14-
dbd_dir = os.path.join(os.path.dirname(__file__), "iocStats", "devIocStats")
15-
dbLoadDatabase("devIocStats.dbd", dbd_dir)
13+
dbLoadDatabase("devIocStats.dbd", os.path.dirname(__file__))
1614

1715
if registerRecordDeviceDriver(pdbbase):
1816
raise RuntimeError('Error registering')

‎softioc/devIocStats.dbd‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../iocStats/devIocStats/devIocStats.dbd

‎softioc/iocStats‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎softioc/iocStatsDb‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../iocStats/iocAdmin/Db

‎softioc/softioc.py‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import sys
55
from ctypes import *
66

7+
from epicsdbbuilder.recordset import recordset
8+
79
from . import imports
810

911
__all__ = ['dbLoadDatabase', 'iocInit', 'interactive_ioc']
@@ -155,11 +157,32 @@ def dbLoadDatabase(database, path = None, substitutions = None):
155157
'''Loads a database file and applies any given substitutions.'''
156158
imports.dbLoadDatabase(database, path, substitutions)
157159

160+
def _add_records_from_file(dir, file, macros):
161+
# This is very naive, for instance macros are added to but never removed,
162+
# but it works well enough for devIocStats
163+
with open(os.path.join(dir, file)) as f:
164+
for line in f.readlines():
165+
line = line.rstrip()
166+
if line.startswith('substitute'):
167+
# substitute "QUEUE=scanOnce, QUEUE_CAPS=SCANONCE
168+
for sub in line.split('"')[1].split(','):
169+
k, v = sub.split('=')
170+
macros[k.strip()] = v.strip()
171+
elif line.startswith('include'):
172+
# include "iocQueue.db"
173+
_add_records_from_file(dir, line.split('"')[1], macros)
174+
else:
175+
# A record line
176+
for k, v in macros.items():
177+
line = line.replace('$(%s)' % k, v)
178+
recordset.AddBodyLine(line)
179+
180+
158181
def devIocStats(ioc_name):
159-
dbLoadDatabase(
160-
"ioc.template",
161-
os.path.join(os.path.dirname(__file__), "iocStats", "iocAdmin", "Db"),
162-
'IOCNAME=' + ioc_name + ',TODFORMAT=%m/%d/%Y %H:%M:%S')
182+
macros = dict(IOCNAME=ioc_name, TODFORMAT='%m/%d/%Y %H:%M:%S')
183+
iocstats_dir = os.path.join(os.path.dirname(__file__), 'iocStatsDb')
184+
_add_records_from_file(iocstats_dir, 'ioc.template', macros)
185+
163186

164187
def interactive_ioc(context = {}, call_exit = True):
165188
'''Fires up the interactive IOC prompt with the given context.'''

0 commit comments

Comments
 (0)