From 854749f94b1c07d8b7d5b6681a25aacd795c7c7f Mon Sep 17 00:00:00 2001 From: yannachen Date: Sat, 16 Nov 2024 16:15:27 -0600 Subject: [PATCH] IPython startup script now adds all devices to the global namespace. --- src/haven/ipython_startup.ipy | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/haven/ipython_startup.ipy b/src/haven/ipython_startup.ipy index 7b0beff6..fb0d6463 100644 --- a/src/haven/ipython_startup.ipy +++ b/src/haven/ipython_startup.ipy @@ -62,7 +62,11 @@ print(f"Connected to {num_devices} devices in {time.monotonic() - t0:.2f} second # Save references to some commonly used things in the global namespace registry = haven.beamline.registry ion_chambers = registry.findall("ion_chambers", allow_none=True) -energy = registry['energy'] +for cpt in registry._objects_by_name.values(): + # Replace spaces and other illegal characters in variable name + name = haven.sanitize_name(cpt.name) + # Add the device as a variable in module's globals + globals().setdefault(name, cpt) # Print helpful information to the console custom_theme = Theme(