@@ -53,8 +53,8 @@ from itkwasm import (
53
53
const interfaceType = interfaceJsonTypeToInterfaceType . get ( output . type )
54
54
const isArray = output . itemsExpectedMax > 1
55
55
switch ( interfaceType ) {
56
- case " TextFile" :
57
- case " BinaryFile" :
56
+ case ' TextFile' :
57
+ case ' BinaryFile' :
58
58
if ( isArray ) {
59
59
haveArray = true
60
60
pipelineOutputs += ` *${ snakeCase ( output . name ) } _pipeline_outputs,\n`
@@ -97,12 +97,12 @@ from itkwasm import (
97
97
if ( interfaceJsonTypeToInterfaceType . has ( input . type ) ) {
98
98
const interfaceType = interfaceJsonTypeToInterfaceType . get ( input . type )
99
99
switch ( interfaceType ) {
100
- case " TextFile" :
101
- case " BinaryFile" :
100
+ case ' TextFile' :
101
+ case ' BinaryFile' :
102
102
pipelineInputs += ` PipelineInput(InterfaceTypes.${ interfaceType } , ${ interfaceType } (PurePosixPath(${ snakeCase ( input . name ) } ))),\n`
103
103
break
104
- case " TextStream" :
105
- case " BinaryStream" :
104
+ case ' TextStream' :
105
+ case ' BinaryStream' :
106
106
pipelineInputs += ` PipelineInput(InterfaceTypes.${ interfaceType } , ${ interfaceType } (${ snakeCase ( input . name ) } )),\n`
107
107
break
108
108
default :
@@ -113,7 +113,7 @@ from itkwasm import (
113
113
114
114
let args = ` args: List[str] = ['--memory-io',]\n`
115
115
let inputCount = 0
116
- args += " # Inputs\n"
116
+ args += ' # Inputs\n'
117
117
interfaceJson . inputs . forEach ( ( input ) => {
118
118
const snakeName = snakeCase ( input . name )
119
119
if ( interfaceJsonTypeToInterfaceType . has ( input . type ) ) {
@@ -122,7 +122,9 @@ from itkwasm import (
122
122
args += ` if not Path(${ snakeName } ).exists():\n`
123
123
args += ` raise FileNotFoundError("${ snakeName } does not exist")\n`
124
124
}
125
- const name = interfaceType . includes ( 'File' ) ? `str(PurePosixPath(${ snakeName } ))` : `'${ inputCount . toString ( ) } '`
125
+ const name = interfaceType . includes ( 'File' )
126
+ ? `str(PurePosixPath(${ snakeName } ))`
127
+ : `'${ inputCount . toString ( ) } '`
126
128
args += ` args.append(${ name } )\n`
127
129
inputCount ++
128
130
} else {
@@ -131,7 +133,7 @@ from itkwasm import (
131
133
} )
132
134
133
135
let outputCount = 0
134
- args += " # Outputs\n"
136
+ args += ' # Outputs\n'
135
137
interfaceJson . outputs . forEach ( ( output ) => {
136
138
const snake = snakeCase ( output . name )
137
139
if ( interfaceJsonTypeToInterfaceType . has ( output . type ) ) {
@@ -158,15 +160,15 @@ from itkwasm import (
158
160
}
159
161
} )
160
162
161
- args += " # Options\n"
163
+ args += ' # Options\n'
162
164
args += ` input_count = len(pipeline_inputs)\n`
163
165
interfaceJson . parameters . forEach ( ( parameter ) => {
164
166
if ( parameter . name === 'memory-io' || parameter . name === 'version' ) {
165
167
// Internal
166
168
return
167
169
}
168
170
const snake = snakeCase ( parameter . name )
169
- if ( parameter . type === " BOOL" ) {
171
+ if ( parameter . type === ' BOOL' ) {
170
172
args += ` if ${ snake } :\n`
171
173
args += ` args.append('--${ parameter . name } ')\n`
172
174
} else if ( parameter . itemsExpectedMax > 1 ) {
@@ -177,7 +179,9 @@ from itkwasm import (
177
179
args += ` args.append('--${ parameter . name } ')\n`
178
180
args += ` for value in ${ snake } :\n`
179
181
if ( interfaceJsonTypeToInterfaceType . has ( parameter . type ) ) {
180
- const interfaceType = interfaceJsonTypeToInterfaceType . get ( parameter . type )
182
+ const interfaceType = interfaceJsonTypeToInterfaceType . get (
183
+ parameter . type
184
+ )
181
185
if ( interfaceType . includes ( 'File' ) ) {
182
186
// for files
183
187
args += ` input_file = str(PurePosixPath(value))\n`
@@ -195,12 +199,19 @@ from itkwasm import (
195
199
args += ` input_count += 1\n`
196
200
}
197
201
} else {
202
+ if ( parameter . type . startsWith ( 'TEXT:{' ) ) {
203
+ const choices = parameter . type . split ( '{' ) [ 1 ] . split ( '}' ) [ 0 ] . split ( ',' )
204
+ args += ` if ${ snake } not in (${ choices . map ( ( c ) => `'${ c } '` ) . join ( ',' ) } ):\n`
205
+ args += ` raise ValueError(f'${ snake } must be one of ${ choices . join ( ', ' ) } ')\n`
206
+ }
198
207
args += ` args.append(str(value))\n`
199
208
}
200
209
} else {
201
210
if ( interfaceJsonTypeToInterfaceType . has ( parameter . type ) ) {
202
211
args += ` if ${ snake } is not None:\n`
203
- const interfaceType = interfaceJsonTypeToInterfaceType . get ( parameter . type )
212
+ const interfaceType = interfaceJsonTypeToInterfaceType . get (
213
+ parameter . type
214
+ )
204
215
if ( interfaceType . includes ( 'File' ) ) {
205
216
// for files
206
217
args += ` input_file = str(PurePosixPath(${ snakeCase ( parameter . name ) } ))\n`
@@ -222,6 +233,11 @@ from itkwasm import (
222
233
}
223
234
} else {
224
235
args += ` if ${ snake } :\n`
236
+ if ( parameter . type . startsWith ( 'TEXT:{' ) ) {
237
+ const choices = parameter . type . split ( '{' ) [ 1 ] . split ( '}' ) [ 0 ] . split ( ',' )
238
+ args += ` if ${ snake } not in (${ choices . map ( ( c ) => `'${ c } '` ) . join ( ',' ) } ):\n`
239
+ args += ` raise ValueError(f'${ snake } must be one of ${ choices . join ( ', ' ) } ')\n`
240
+ }
225
241
args += ` args.append('--${ parameter . name } ')\n`
226
242
args += ` args.append(str(${ snake } ))\n`
227
243
}
@@ -234,34 +250,36 @@ from itkwasm import (
234
250
const canonical = canonicalType ( type )
235
251
const pythonType = interfaceJsonTypeToPythonType . get ( canonical )
236
252
switch ( pythonType ) {
237
- case " os.PathLike" :
253
+ case ' os.PathLike' :
238
254
return `Path(${ value } .data.path)`
239
- case " str" :
255
+ case ' str' :
240
256
if ( type === 'TEXT' ) {
241
257
return `${ value } `
242
258
} else {
243
259
return `${ value } .data.data`
244
260
}
245
- case " bytes" :
261
+ case ' bytes' :
246
262
return `${ value } .data.data`
247
- case " int" :
263
+ case ' int' :
248
264
return `int(${ value } )`
249
- case " bool" :
265
+ case ' bool' :
250
266
return `bool(${ value } )`
251
- case " float" :
267
+ case ' float' :
252
268
return `float(${ value } )`
253
- case " Any" :
269
+ case ' Any' :
254
270
return `${ value } .data`
255
271
default :
256
272
return `${ value } .data`
257
273
}
258
274
}
259
275
outputCount = 0
260
276
const jsonOutputs = interfaceJson [ 'outputs' ]
261
- const numOutputs = interfaceJson . outputs . filter ( o => ! o . type . includes ( 'FILE' ) ) . length
277
+ const numOutputs = interfaceJson . outputs . filter (
278
+ ( o ) => ! o . type . includes ( 'FILE' )
279
+ ) . length
262
280
if ( numOutputs > 1 ) {
263
281
postOutput += ' result = (\n'
264
- } else if ( numOutputs === 1 ) {
282
+ } else if ( numOutputs === 1 ) {
265
283
postOutput = ' result = '
266
284
}
267
285
0 commit comments