Skip to content

Commit

Permalink
MNT #984 refactor the ad_creator() signature
Browse files Browse the repository at this point in the history
  • Loading branch information
prjemian committed Aug 25, 2024
1 parent df38db6 commit 4cfab1a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
29 changes: 17 additions & 12 deletions apstools/devices/area_detector_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
Just the camera plugin (uses CamBase, the most basic features)::
from apstools.devices import ad_creator
det = ad_creator("MySimpleAD", "ad:", "det", ["cam",])
det = ad_creator("ad:", name="det", class_name="MySimpleAD", ["cam",])
View ADSimDetector image with CA and PVA::
from ophyd.areadetector import SimDetectorCam
from apstools.devices import ad_creator
det = ad_creator(
"MySimDetector", "ad:", "det",
"ad:", name="det", class_name="MySimDetector",
[
{"cam": {"class": SimDetectorCam}},
"image",
Expand All @@ -36,7 +36,7 @@
from apstools.devices import ad_creator
det = ad_creator(
"MyEiger", "ad:", "det",
"ad:", name="det", class_name"MyEiger",
[
{"cam": {"class": EigerDetectorCam}},
"image",
Expand All @@ -56,7 +56,7 @@
plugin_defaults["hdf1"].pop("write_path_template", None)
det = ad_creator(
"MyEiger", "ad:", "det",
"ad:", name="det", class_name"MyEiger",
[
{"cam": {"class": EigerDetectorCam}},
"image",
Expand All @@ -67,6 +67,7 @@
"""

import logging
import uuid

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -212,29 +213,32 @@ def ad_class_factory(name, bases=None, plugins=None, plugin_defaults=None):


def ad_creator(
class_name: str,
prefix: str,
name: str,
plugins,
bases=None,
prefix:str,
*,
ad_setup: object = None,
bases=None,
class_name: str=None,
name: str=None,
plugin_defaults: dict = None,
plugins=None,
**kwargs,
):
"""
Create an area detector object from a custom class.
PARAMETERS
class_name
*str*:
Name of the class to be created.
prefix
*str*:
EPICS PV prefix.
name
*str*:
Name of the ophyd object.
class_name
*str*:
Name of the class to be created.
(default: ``"ADclass_HEX7"`` where HEX is a random
7-digit hexadecimal string)
plugins
*list*:
Description of the plugins used.
Expand All @@ -254,6 +258,7 @@ def ad_creator(
Any additional keyword arguments for the new class definition.
(default: ``{}``)
"""
class_name = class_name or f"ADclass_{str(uuid.uuid4())[:7]}"
ad_class = ad_class_factory(
class_name,
bases,
Expand Down
12 changes: 6 additions & 6 deletions apstools/devices/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ def adsimdet():
"""EPICS ADSimDetector."""

adsimdet = ad_creator(
"MySimDet",
IOC_AD,
"adsimdet",
[
name="adsimdet",
class_name="MySimDet",
plugins=[
{"cam": {"class": SimDetectorCam_V34}},
"image",
"pva",
Expand Down Expand Up @@ -140,10 +140,10 @@ class MyHDF5(HDF5Plugin):
plugin_defaults["hdf1"].pop("write_path_template", None)

det = ad_creator(
"MyAdSingle",
IOC_AD,
"adsingle",
[
name="adsingle",
class_name="MyAdSingle",
plugins=[
{"cam": {"class": SimDetectorCam_V34}},
"image",
"pva",
Expand Down

0 comments on commit 4cfab1a

Please sign in to comment.