Skip to content

Commit

Permalink
Merge pull request #110 from dihm/get_shot_globals_deprecation
Browse files Browse the repository at this point in the history
Get shot globals deprecation
  • Loading branch information
dihm authored Oct 12, 2023
2 parents 8151a19 + f003258 commit 418d78a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
1 change: 0 additions & 1 deletion readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ python:
path: .
extra_requirements:
- docs
system_packages: true

30 changes: 12 additions & 18 deletions runmanager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@
import json
import tokenize
import io
import warnings

import labscript_utils.h5_lock
import h5py
import numpy as np

from labscript_utils.ls_zprocess import ProcessTree, zmq_push_multipart
from labscript_utils.labconfig import LabConfig
import labscript_utils.shot_utils
process_tree = ProcessTree.instance()

from .__version__ import __version__
Expand Down Expand Up @@ -915,24 +917,16 @@ def compile_labscript_with_globals_files_async(labscript_file, globals_files, ou
def get_shot_globals(filepath):
"""Returns the evaluated globals for a shot, for use by labscript or lyse.
Simple dictionary access as in dict(h5py.File(filepath).attrs) would be fine
except we want to apply some hacks, so it's best to do that in one place."""
params = {}
with h5py.File(filepath, 'r') as f:
for name, value in f['globals'].attrs.items():
# Convert numpy bools to normal bools:
if isinstance(value, np.bool_):
value = bool(value)
# Convert null HDF references to None:
if isinstance(value, h5py.Reference) and not value:
value = None
# Convert numpy strings to Python ones.
# DEPRECATED, for backward compat with old files.
if isinstance(value, np.str_):
value = str(value)
if isinstance(value, bytes):
value = value.decode()
params[name] = value
return params
except we want to apply some hacks, so it's best to do that in one place.
Deprecated: use identical function `labscript_utils.shot_utils.get_shot_globals`
"""

warnings.warn(
FutureWarning("get_shot_globals has moved to labscript_utils.shot_utils. "
"Please update your code to import it from there."))

return labscript_utils.shot_utils.get_shot_globals(filepath)


def dict_diff(dict1, dict2):
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ install_requires =
desktop-app>=0.1.2
importlib_metadata
labscript>=3.0.0
labscript_utils>=3.0.0
labscript_utils>=3.3.0
pandas>=0.13
qtutils>=2.2.2
matplotlib
Expand Down

0 comments on commit 418d78a

Please sign in to comment.