Skip to content

Commit

Permalink
Merge pull request #13 from prjemian/12-warn_duplicates
Browse files Browse the repository at this point in the history
Support warn_duplicates setting with auto_register by adding class-level attribute
  • Loading branch information
canismarko authored Nov 22, 2024
2 parents 921f1b8 + 07127ed commit 6b895df
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/ophydregistry/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,15 @@ class Registry:
If false, items will be dropped from this registry if the only
reference comes from this registry. Relies on the garbage
collector, so to force cleanup use ``gc.collect()``.
warn_duplicates
If true, a warning will be issued if this device is
overwriting a previous device with the same name.
"""

use_typhos: bool
keep_references: bool
warn_duplicates: bool
_auto_register: bool
_valid_classes: Tuple[type] = (
ophydobj.OphydObject,
Expand All @@ -141,6 +145,7 @@ def __init__(
auto_register: bool = True,
use_typhos: bool = False,
keep_references: bool = True,
warn_duplicates: bool = True,
):
# Check that Typhos is installed if needed
if use_typhos and not typhos_available:
Expand All @@ -150,6 +155,7 @@ def __init__(
self.use_typhos = use_typhos
self.clear()
self.auto_register = auto_register
self.warn_duplicates = warn_duplicates

@property
def auto_register(self):
Expand Down Expand Up @@ -522,7 +528,7 @@ def register(
self,
component: ophydobj.OphydObject,
labels: Optional[Sequence] = None,
warn_duplicates=True,
warn_duplicates=None,
) -> ophydobj.OphydObject:
"""Register a device, component, etc so that it can be retrieved later.
Expand All @@ -540,8 +546,11 @@ def register(
warn_duplicates
If true, a warning will be issued if this device is
overwriting a previous device with the same name.
If None, defaults to the value of the same-named class attribute.
"""
if warn_duplicates is None:
warn_duplicates = self.warn_duplicates
# Determine how to register the device
if isinstance(component, type):
# A class was given, so instances should be auto-registered
Expand Down

0 comments on commit 6b895df

Please sign in to comment.