@@ -53,8 +53,8 @@ from itkwasm import (
5353 const interfaceType = interfaceJsonTypeToInterfaceType . get ( output . type )
5454 const isArray = output . itemsExpectedMax > 1
5555 switch ( interfaceType ) {
56- case " TextFile" :
57- case " BinaryFile" :
56+ case ' TextFile' :
57+ case ' BinaryFile' :
5858 if ( isArray ) {
5959 haveArray = true
6060 pipelineOutputs += ` *${ snakeCase ( output . name ) } _pipeline_outputs,\n`
@@ -97,12 +97,12 @@ from itkwasm import (
9797 if ( interfaceJsonTypeToInterfaceType . has ( input . type ) ) {
9898 const interfaceType = interfaceJsonTypeToInterfaceType . get ( input . type )
9999 switch ( interfaceType ) {
100- case " TextFile" :
101- case " BinaryFile" :
100+ case ' TextFile' :
101+ case ' BinaryFile' :
102102 pipelineInputs += ` PipelineInput(InterfaceTypes.${ interfaceType } , ${ interfaceType } (PurePosixPath(${ snakeCase ( input . name ) } ))),\n`
103103 break
104- case " TextStream" :
105- case " BinaryStream" :
104+ case ' TextStream' :
105+ case ' BinaryStream' :
106106 pipelineInputs += ` PipelineInput(InterfaceTypes.${ interfaceType } , ${ interfaceType } (${ snakeCase ( input . name ) } )),\n`
107107 break
108108 default :
@@ -113,7 +113,7 @@ from itkwasm import (
113113
114114 let args = ` args: List[str] = ['--memory-io',]\n`
115115 let inputCount = 0
116- args += " # Inputs\n"
116+ args += ' # Inputs\n'
117117 interfaceJson . inputs . forEach ( ( input ) => {
118118 const snakeName = snakeCase ( input . name )
119119 if ( interfaceJsonTypeToInterfaceType . has ( input . type ) ) {
@@ -122,7 +122,9 @@ from itkwasm import (
122122 args += ` if not Path(${ snakeName } ).exists():\n`
123123 args += ` raise FileNotFoundError("${ snakeName } does not exist")\n`
124124 }
125- const name = interfaceType . includes ( 'File' ) ? `str(PurePosixPath(${ snakeName } ))` : `'${ inputCount . toString ( ) } '`
125+ const name = interfaceType . includes ( 'File' )
126+ ? `str(PurePosixPath(${ snakeName } ))`
127+ : `'${ inputCount . toString ( ) } '`
126128 args += ` args.append(${ name } )\n`
127129 inputCount ++
128130 } else {
@@ -131,7 +133,7 @@ from itkwasm import (
131133 } )
132134
133135 let outputCount = 0
134- args += " # Outputs\n"
136+ args += ' # Outputs\n'
135137 interfaceJson . outputs . forEach ( ( output ) => {
136138 const snake = snakeCase ( output . name )
137139 if ( interfaceJsonTypeToInterfaceType . has ( output . type ) ) {
@@ -158,15 +160,15 @@ from itkwasm import (
158160 }
159161 } )
160162
161- args += " # Options\n"
163+ args += ' # Options\n'
162164 args += ` input_count = len(pipeline_inputs)\n`
163165 interfaceJson . parameters . forEach ( ( parameter ) => {
164166 if ( parameter . name === 'memory-io' || parameter . name === 'version' ) {
165167 // Internal
166168 return
167169 }
168170 const snake = snakeCase ( parameter . name )
169- if ( parameter . type === " BOOL" ) {
171+ if ( parameter . type === ' BOOL' ) {
170172 args += ` if ${ snake } :\n`
171173 args += ` args.append('--${ parameter . name } ')\n`
172174 } else if ( parameter . itemsExpectedMax > 1 ) {
@@ -177,7 +179,9 @@ from itkwasm import (
177179 args += ` args.append('--${ parameter . name } ')\n`
178180 args += ` for value in ${ snake } :\n`
179181 if ( interfaceJsonTypeToInterfaceType . has ( parameter . type ) ) {
180- const interfaceType = interfaceJsonTypeToInterfaceType . get ( parameter . type )
182+ const interfaceType = interfaceJsonTypeToInterfaceType . get (
183+ parameter . type
184+ )
181185 if ( interfaceType . includes ( 'File' ) ) {
182186 // for files
183187 args += ` input_file = str(PurePosixPath(value))\n`
@@ -195,12 +199,19 @@ from itkwasm import (
195199 args += ` input_count += 1\n`
196200 }
197201 } 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+ }
198207 args += ` args.append(str(value))\n`
199208 }
200209 } else {
201210 if ( interfaceJsonTypeToInterfaceType . has ( parameter . type ) ) {
202211 args += ` if ${ snake } is not None:\n`
203- const interfaceType = interfaceJsonTypeToInterfaceType . get ( parameter . type )
212+ const interfaceType = interfaceJsonTypeToInterfaceType . get (
213+ parameter . type
214+ )
204215 if ( interfaceType . includes ( 'File' ) ) {
205216 // for files
206217 args += ` input_file = str(PurePosixPath(${ snakeCase ( parameter . name ) } ))\n`
@@ -222,6 +233,11 @@ from itkwasm import (
222233 }
223234 } else {
224235 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+ }
225241 args += ` args.append('--${ parameter . name } ')\n`
226242 args += ` args.append(str(${ snake } ))\n`
227243 }
@@ -234,34 +250,36 @@ from itkwasm import (
234250 const canonical = canonicalType ( type )
235251 const pythonType = interfaceJsonTypeToPythonType . get ( canonical )
236252 switch ( pythonType ) {
237- case " os.PathLike" :
253+ case ' os.PathLike' :
238254 return `Path(${ value } .data.path)`
239- case " str" :
255+ case ' str' :
240256 if ( type === 'TEXT' ) {
241257 return `${ value } `
242258 } else {
243259 return `${ value } .data.data`
244260 }
245- case " bytes" :
261+ case ' bytes' :
246262 return `${ value } .data.data`
247- case " int" :
263+ case ' int' :
248264 return `int(${ value } )`
249- case " bool" :
265+ case ' bool' :
250266 return `bool(${ value } )`
251- case " float" :
267+ case ' float' :
252268 return `float(${ value } )`
253- case " Any" :
269+ case ' Any' :
254270 return `${ value } .data`
255271 default :
256272 return `${ value } .data`
257273 }
258274 }
259275 outputCount = 0
260276 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
262280 if ( numOutputs > 1 ) {
263281 postOutput += ' result = (\n'
264- } else if ( numOutputs === 1 ) {
282+ } else if ( numOutputs === 1 ) {
265283 postOutput = ' result = '
266284 }
267285
0 commit comments