Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional debug info to ophydobj with inspect #961

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions ophyd/ophydobj.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
import functools
import inspect
import time
import weakref

Expand All @@ -10,6 +12,9 @@
from .log import control_layer_logger


OPHYD_DEBUG = os.getenv("OPHYD_DEBUG", "").lower() in ("y", "yes", "1")


def select_version(cls, version):
"""Select closest compatible version to requested version

Expand Down Expand Up @@ -148,6 +153,12 @@ class OphydObject:

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

if OPHYD_DEBUG:
print(f"Initializing {self.__class__.__name__}...")
stack = inspect.stack()
self._stack_init = [f'{s.filename}:{s.lineno}' for s in stack]

if labels is None:
labels = set()
self._ophyd_labels_ = set(labels)
Expand Down Expand Up @@ -228,6 +239,13 @@ 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:
if not cls.__module__.startswith("ophyd."):
print(f'Subclassing {cls.__name__}...')
stack = inspect.stack()
cls._stack_subclass = [f'{s.filename}:{s.lineno}' for s in stack]

super().__init_subclass__(**kwargs)

if version is None:
Expand Down