Skip to content

Commit a706494

Browse files
dihmNMFolks
andcommitted
Configure labscript-profile-create to compile the default connection table.
This will allow BLACS to run immediately using dummy devices, without manual compilation required from the user. Co-authored-by: NMFolks <[email protected]>
1 parent 3ab11ce commit a706494

File tree

1 file changed

+56
-3
lines changed

1 file changed

+56
-3
lines changed

labscript_profile/create.py

+56-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pathlib import Path
66
from subprocess import check_output
77
from labscript_profile import LABSCRIPT_SUITE_PROFILE, default_labconfig_path
8+
import argparse
89

910
_here = os.path.dirname(os.path.abspath(__file__))
1011
DEFAULT_PROFILE_CONTENTS = os.path.join(_here, 'default_profile')
@@ -21,7 +22,8 @@ def make_shared_secret(directory):
2122
raise RuntimeError("Could not parse output of zprocess.makesecret")
2223

2324

24-
def make_labconfig_file():
25+
def make_labconfig_file(apparatus_name):
26+
2527
source_path = os.path.join(LABSCRIPT_SUITE_PROFILE, 'labconfig', 'example.ini')
2628
target_path = default_labconfig_path()
2729
if os.path.exists(target_path):
@@ -47,16 +49,58 @@ def make_labconfig_file():
4749
'%(labscript_suite)s', shared_secret.relative_to(LABSCRIPT_SUITE_PROFILE)
4850
)
4951
config.set('security', 'shared_secret', str(shared_secret_entry))
52+
if apparatus_name is not None:
53+
config.set('DEFAULT', 'apparatus_name', apparatus_name)
5054

5155
with open(target_path, 'w') as f:
5256
config.write(f)
5357

58+
def compile_connection_table():
59+
60+
try:
61+
import runmanager
62+
except ImportError:
63+
# if runmanager doesn't import, skip compilation
64+
return
65+
66+
config = configparser.ConfigParser(defaults = {'labscript_suite': str(LABSCRIPT_SUITE_PROFILE)})
67+
config.read(default_labconfig_path())
68+
69+
# The path to the user's connection_table.py script
70+
script_path = config['paths']['connection_table_py']
71+
# path to the connection_table.h5 destination
72+
output_h5_path = config['paths']['connection_table_h5']
73+
# create output directory, if needed
74+
Path(output_h5_path).parent.mkdir(parents=True, exist_ok=True)
75+
# compile the h5 file
76+
runmanager.new_globals_file(output_h5_path)
77+
78+
def dummy_callback(success):
79+
pass
80+
81+
runmanager.compile_labscript_async(labscript_file = script_path,
82+
run_file = output_h5_path,
83+
stream_port = None,
84+
done_callback = dummy_callback)
5485

5586
def create_profile():
87+
88+
# capture CMD arguments
89+
parser = argparse.ArgumentParser(prog='labscript-profile-create',
90+
description='Initialises a default labscript profile'
91+
)
92+
93+
parser.add_argument('-n', '--apparatus_name',
94+
type = str,
95+
help = 'Sets the apparatus_name in the labconfig file. Defaults to example_apparatus',
96+
)
97+
98+
args = parser.parse_args()
99+
56100
src = Path(DEFAULT_PROFILE_CONTENTS)
57101
dest = Path(LABSCRIPT_SUITE_PROFILE)
58102
# Profile directory may exist already, but we will error if it contains any of the
59-
# files or directories we want to copy into it:
103+
# sub-directories we want to copy into it:
60104
os.makedirs(dest, exist_ok=True)
61105
# Preferable to raise errors if anything exists before copying anything, rather than
62106
# do a partial copy before hitting an error:
@@ -71,4 +115,13 @@ def create_profile():
71115
else:
72116
shutil.copy2(src_file, dest_file)
73117

74-
make_labconfig_file()
118+
make_labconfig_file(args.apparatus_name)
119+
120+
# rename apparatus directories
121+
if args.apparatus_name is not None:
122+
for path in dest.glob('**/example_apparatus/'):
123+
new_path = Path(str(path).replace('example_apparatus', args.apparatus_name))
124+
path.rename(new_path)
125+
126+
# compile the initial example connection table
127+
compile_connection_table()

0 commit comments

Comments
 (0)