Skip to content

Commit 5345e6d

Browse files
committed
Initial work centered around refactoring the Device and compiler classes, and updating code to take advantage of more modern Python (3.6+) features.
1 parent 01cc205 commit 5345e6d

File tree

4 files changed

+387
-215
lines changed

4 files changed

+387
-215
lines changed

labscript/compiler.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import builtins
2+
3+
from labscript_utils.labconfig import LabConfig
4+
5+
_builtins_dict = builtins.__dict__
6+
7+
# Extract settings from labconfig
8+
_SAVE_HG_INFO = LabConfig().getboolean("labscript", "save_hg_info", fallback=False)
9+
_SAVE_GIT_INFO = LabConfig().getboolean("labscript", "save_git_info", fallback=False)
10+
11+
12+
class Compiler(object):
13+
"""Compiler singleton that saves relevant parameters during compilation of each shot"""
14+
15+
_instance = None
16+
17+
_existing_builtins_dict = None
18+
19+
def __new__(cls):
20+
if cls._instance is None:
21+
cls._instance = super().__new__(cls)
22+
# Save initial builtins state so that we (and possibly someone else) can
23+
# call ``reset()`` at any time.
24+
cls._instance.save_builtins_state()
25+
# Initialise state
26+
cls._instance.reset()
27+
return cls._instance
28+
29+
def save_builtins_state(self):
30+
self._existing_builtins_dict = _builtins_dict.copy()
31+
32+
def reset(self):
33+
"""restores builtins and the labscript module to its state before
34+
labscript_init() was called"""
35+
# Reset builtins
36+
for name in _builtins_dict.copy():
37+
if name not in self._existing_builtins_dict:
38+
del _builtins_dict[name]
39+
else:
40+
_builtins_dict[name] = self._existing_builtins_dict[name]
41+
42+
# Reset other variables
43+
44+
# The labscript file being compiled:
45+
self.labscript_file = None
46+
# All defined devices:
47+
self.inventory = []
48+
# The filepath of the h5 file containing globals and which will
49+
# contain compilation output:
50+
self.hdf5_filename = None
51+
52+
self.start_called = False
53+
self.wait_table = {}
54+
self.wait_monitor = None
55+
self.master_pseudoclock = None
56+
self.all_pseudoclocks = None
57+
self.trigger_duration = 0
58+
self.wait_delay = 0
59+
self.time_markers = {}
60+
self._PrimaryBLACS = None
61+
self.save_hg_info = _SAVE_HG_INFO
62+
self.save_git_info = _SAVE_GIT_INFO
63+
self.shot_properties = {}
64+
65+
compiler = Compiler()
66+
"""The compiler instance"""

0 commit comments

Comments
 (0)