Skip to content

Commit c9a5e13

Browse files
committed
Separate labscript-profile-create into a separate CLI interface and the
actual creation function `create_profile`, which is automatically called when labscript_utils is imported and the profile does not already exist. Separation ensures that argparse doesn't consume erroneous CLI arguments just because a command incidentally imports labscript_utils (like on RTD).
1 parent be08cee commit c9a5e13

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

labscript_profile/create.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ def dummy_callback(success):
9696
done_callback = dummy_callback)
9797
print(f'\tOutput written to {output_h5_path}')
9898

99-
def create_profile():
99+
def create_profile_cli():
100100
"""Function that defines the labscript-profile-create command
101+
102+
Parses CLI arguments and calls :func:`~.create_profile`.
101103
"""
102104

103105
# capture CMD arguments
@@ -116,6 +118,21 @@ def create_profile():
116118

117119
args = parser.parse_args()
118120

121+
create_profile(args.apparatus_name, args.compile)
122+
123+
def create_profile(apparatus_name = None, compile_table = False):
124+
"""Function that creates a labscript config profile from the default config
125+
126+
Parameters
127+
----------
128+
appratus_name: str, optional
129+
apparatus_name to define in the config.
130+
If None, defaults to example_apparatus (set in default config file)
131+
compile_table: bool, optional
132+
Whether to compile to example connection table defined by the default config file
133+
Default is False.
134+
"""
135+
119136
src = Path(DEFAULT_PROFILE_CONTENTS)
120137
dest = Path(LABSCRIPT_SUITE_PROFILE)
121138
print(f'Creating labscript profile at {LABSCRIPT_SUITE_PROFILE}')
@@ -136,15 +153,15 @@ def create_profile():
136153
shutil.copy2(src_file, dest_file)
137154

138155
print('Writing labconfig file')
139-
make_labconfig_file(args.apparatus_name)
156+
make_labconfig_file(apparatus_name)
140157

141158
# rename apparatus directories
142-
if args.apparatus_name is not None:
159+
if apparatus_name is not None:
143160
print('\tRenaming apparatus directories')
144161
for path in dest.glob('**/example_apparatus/'):
145-
new_path = Path(str(path).replace('example_apparatus', args.apparatus_name))
162+
new_path = Path(str(path).replace('example_apparatus', apparatus_name))
146163
path.rename(new_path)
147164

148-
if args.compile:
165+
if compile_table:
149166
print('Compiling the example connection table')
150167
compile_connection_table()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@ docs = [
6969
]
7070

7171
[project.scripts]
72-
labscript-profile-create = "labscript_profile.create:create_profile"
72+
labscript-profile-create = "labscript_profile.create:create_profile_cli"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy