Skip to content

Commit

Permalink
fix: Fixed behaviour of ConstantSchema and EnumSchema in python executor
Browse files Browse the repository at this point in the history
  • Loading branch information
beneboy committed Sep 2, 2019
1 parent e4dbe3d commit c50d5ac
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions py/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class Executor:
globals: typing.Optional[typing.Dict[str, typing.Any]]

def parse(self, source: Article) -> None:
# todo: this traverses the article twice. Make it less hard coded, maybe pass through a lookup table that maps
# a found type to its destination
self.handle_item(source, Parameter, self.parameters, None)
self.handle_item(source, (CodeChunk, CodeExpression), self.code, {'language': 'python'})

Expand Down Expand Up @@ -134,7 +136,8 @@ def parse_cli_args(self, cli_args: typing.List[str]) -> None:
param_parser = argparse.ArgumentParser(description='Parse Parameters')

for param in self.parameters.values():
param_parser.add_argument('--' + param.name, dest=param.name, required=param.default is None)
if not isinstance(param.schema, ConstantSchema):
param_parser.add_argument('--' + param.name, dest=param.name, required=param.default is None)

args, _ = param_parser.parse_known_args(cli_args)

Expand All @@ -152,12 +155,12 @@ def deserialize_parameter(parameter: Parameter, value: typing.Any) -> typing.Any
# Lots of TODOs here, might not care as passing this off to encoda soon

if isinstance(parameter.schema, ConstantSchema):
# TODO: not sure about this one
raise NotImplementedError
return parameter.schema.value

if isinstance(parameter.schema, EnumSchema):
# TODO: not sure about this one
raise NotImplementedError
if value not in parameter.schema.values:
raise TypeError('{} not found in enum values for {}'.format(value, parameter.name))
return value

if isinstance(parameter.schema, BooleanSchema):
return value.lower() in ('true', 'yes', '1' 't')
Expand Down

0 comments on commit c50d5ac

Please sign in to comment.