class openalea.oalab.model.parse.InputObj(string='')[source]

Bases: object

Inputs object with:
  • an attribute name: name of the input obj (str) (mandatory)
  • an attribute interface: interface/type of the input obj (str) (optional)
  • an attribute default: default value of the input obj (str) (optional)
>>> from openalea.oalab.model.parse import InputObj
>>> obj = InputObj('a:float=1')
>>> obj.name
'a'
>>> obj.default
'1'
>>> obj.interface
IFloat
>>> obj
InputObj('a:IFloat=1')
Parameters:string -- string object with format "input_name:input_type=input_default_value" or "input_name=input_default_value" or "input_name:input_type" or "input_name"
repr_code()[source]
class openalea.oalab.model.parse.OutputObj(string='')[source]

Bases: openalea.oalab.model.parse.InputObj

openalea.oalab.model.parse.ast_parse(string)[source]
openalea.oalab.model.parse.extract_functions(codestring, filename='tmp')[source]

parse the code codestring and detect what are the functions defined inside :return: dict name -> code

openalea.oalab.model.parse.get_docstring(string)[source]

Get a docstring from a string

openalea.oalab.model.parse.get_docstring_r(code)[source]

Get a docstring from a code text

openalea.oalab.model.parse.parse_doc(docstring)[source]

Parse a docstring.

Returns:model, inputs, outputs
openalea.oalab.model.parse.parse_docstring(string)[source]

parse a string (not a docstring), get the docstring and return information on the model.

Use:model, inputs, outputs = parse_docstring(multiline_string_to_parse)
Parameters:string -- docstring to parse (string)
Returns:model, inputs, outputs
openalea.oalab.model.parse.parse_docstring_r(code)[source]

parse a string (not a docstring), get the docstring and return information on the model.

Use:model, inputs, outputs = parse_docstring_r(multiline_string_to_parse)
Parameters:string -- docstring to parse (string)
Returns:model, inputs, outputs
openalea.oalab.model.parse.parse_function(docstring)[source]
Parse a docstring with format:
my_model(a:int=4, b)->r:int

Unused.

Returns:model, inputs, outputs
openalea.oalab.model.parse.parse_functions(codestring)[source]

parse the code codestring and detect what are the functions defined inside (search init, step, animate and run) :return: init, step, animate, run functions (code or False)

openalea.oalab.model.parse.parse_functions_r(docstring)[source]
Parse a docstring with format:
my_model(a:int=4, b)->r:int

Unused.

Returns:model, inputs, outputs
openalea.oalab.model.parse.parse_input_and_output(docstring)[source]
Parse a docstring with format:
inputs = input_name:input_type=input_default_value, ... outputs = output_name:output_type, ...
Use:
>>> from openalea.oalab.model.parse import parse_input_and_output
>>> comment = '''
... input = a:int=4, b
... output = r:float'''
>>> inputs, outputs = parse_input_and_output(comment)
>>> inputs
['a:int=4', 'b']
>>> outputs
['r:float']
Returns:

inputs, outputs

openalea.oalab.model.parse.parse_lpy(string)[source]

Take a lpy string_file, parse it and return only the docstring of the file.

Parameters:

string -- string representation of lpy file

Returns:

docstring of the file if exists (must be a multiline docstring!). If not found, return None.

Use:
>>> f = open(lpyfilename, "r") 
>>> lpystring = f.read() 
>>> f.close() 
>>>
>>> docstring = parse_lpy(lpystring) 
>>>
>>> from openalea.oalab.model.parse import parse_doc 
>>> if docstring is not None: 
...     model, inputs, outputs = parse_doc(docstring) 
...     print "model : ", model 
...     print "inputs : ", inputs 
...     print "outputs : ", outputs 
openalea.oalab.model.parse.prepare_inputs(inputs_info, *args, **kwargs)[source]
>>> from openalea.oalab.model.parse import InputObj
>>> inputs_info = [InputObj('a:int=1'), InputObj('b:int=2')]
>>> prepare_inputs(inputs_info) 
{'a':1, 'b':2}
>>> prepare_inputs(inputs_info, 10) 
{'a':10, 'b':2}
>>> prepare_inputs(inputs_info, 10, 20) 
{'a':10, 'b':20}
openalea.oalab.model.parse.set_interface(input_obj)[source]

Previous topic

openalea.oalab.model package

Next topic

<no title>

This Page