Skip to content

Commit

Permalink
Add optional debug info to ophydobj with inspect
Browse files Browse the repository at this point in the history
  • Loading branch information
mrakitin committed Jan 22, 2021
1 parent 03585f0 commit 12e15ed
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ophyd/ophydobj.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from enum import IntFlag
import functools
from itertools import count
Expand All @@ -8,6 +9,11 @@
from .log import control_layer_logger


OPHYD_DEBUG_WITH_INSPECT = os.getenv('OPHYD_DEBUG_WITH_INSPECT')
if OPHYD_DEBUG_WITH_INSPECT:
import inspect


def select_version(cls, version):
"""Select closest compatible version to requested version
Expand Down Expand Up @@ -136,6 +142,10 @@ class OphydObject:

def __init__(self, *, name=None, attr_name='', parent=None, labels=None,
kind=None):

if OPHYD_DEBUG_WITH_INSPECT:
self._stack_init = inspect.stack()

if labels is None:
labels = set()
self._ophyd_labels_ = set(labels)
Expand Down Expand Up @@ -216,6 +226,11 @@ def __register_instance(cls, instance):
def __init_subclass__(cls, version=None, version_of=None,
version_type=None, **kwargs):
'This is called automatically in Python for all subclasses of OphydObject'

if OPHYD_DEBUG_WITH_INSPECT:
print(f'Subclassing {cls.__name__}...')
cls._stack_subclass = inspect.stack()

super().__init_subclass__(**kwargs)

if version is None:
Expand Down

0 comments on commit 12e15ed

Please sign in to comment.