4
4
if sys .version_info < (3 , 6 ):
5
5
raise RuntimeError ('Magic only supported for Python version 3.6 and up' )
6
6
7
+
7
8
@magics_class
8
9
class QCoDeSMagic (Magics ):
9
10
"""Magics related to code management (loading, saving, editing, ...)."""
@@ -82,11 +83,10 @@ def measurement(self, line, cell=None):
82
83
data_name = options .get ('d' , 'data' )
83
84
loop_name = options .get ('l' , 'loop' )
84
85
85
-
86
86
lines = cell .splitlines ()
87
87
assert lines [0 ][:3 ] == 'for' , "Measurement must start with for loop"
88
88
89
- contents = f 'import qcodes\n { loop_name } = '
89
+ contents = 'import qcodes\n {} = ' . format ( loop_name )
90
90
previous_level = 0
91
91
for k , line in enumerate (lines ):
92
92
line , level = line .lstrip (), int ((len (line )- len (line .lstrip ())) / 4 )
@@ -99,7 +99,7 @@ def measurement(self, line, cell=None):
99
99
continue
100
100
else :
101
101
line_representation = ' ' * level * 4
102
- if level < previous_level :
102
+ if level < previous_level :
103
103
# Exiting inner loop, close bracket
104
104
line_representation += '),' * (previous_level - level )
105
105
line_representation += '\n ' + ' ' * level * 4
@@ -109,13 +109,16 @@ def measurement(self, line, cell=None):
109
109
for_opts , for_code = self .parse_options (line [4 :- 1 ], 'd:' )
110
110
if 'd' in for_opts :
111
111
# Delay option provided
112
- line_representation += f'qcodes.Loop({ for_code } , ' \
113
- f'delay={ for_opts ["d" ]} ).each(\n '
112
+ line_representation += ('qcodes.Loop({}, '
113
+ 'delay={}).each(\n '
114
+ '' .format (for_code ,
115
+ for_opts ["d" ]))
114
116
else :
115
- line_representation += f'qcodes.Loop({ for_code } ).each(\n '
117
+ line_representation += ('qcodes.Loop({}).each(\n '
118
+ '' .format (for_code ))
116
119
else :
117
120
# Action in current loop
118
- line_representation += f' { line } ,\n '
121
+ line_representation += '{ },\n '. format ( line )
119
122
contents += line_representation
120
123
121
124
# Remember level for next iteration (might exit inner loop)
@@ -124,7 +127,9 @@ def measurement(self, line, cell=None):
124
127
# Add closing brackets for any remaining loops
125
128
contents += ')' * previous_level + '\n '
126
129
# Add dataset
127
- contents += f"{ data_name } = { loop_name } .get_data_set(name='{ msmt_name } ')"
130
+ contents += "{} = {}.get_data_set(name='{}')" .format (data_name ,
131
+ loop_name ,
132
+ msmt_name )
128
133
129
134
for line in lines [k + 1 :]:
130
135
contents += '\n ' + line
@@ -154,6 +159,6 @@ def register_magic_class(cls=QCoDeSMagic, magic_commands=True):
154
159
if magic_commands is not True :
155
160
# filter out any magic commands that are not in magic_commands
156
161
cls .magics = {line_cell : {key : val for key , val in magics .items ()
157
- if key in magic_commands }
162
+ if key in magic_commands }
158
163
for line_cell , magics in cls .magics .items ()}
159
- ip .magics_manager .register (cls )
164
+ ip .magics_manager .register (cls )
0 commit comments