Extract project parameters¶
extract_json(project_path, to_file, all=False)
¶
Extract the input parameter out of the given OneCode project and dump it to the specified file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project_path |
str
|
Path to the root of the OneCode project. |
required |
to_file |
str
|
Path of the output file to dump the JSON to. |
required |
all |
Optional[bool]
|
If False, extract only the values of the parameter, otherwise extract values and
associated data such as |
False
|
main(cli=True)
¶
usage: onecode-extract [-h] [--all] [--modules [MODULES [MODULES ...]]] [--path PATH]
output_file
Extract OneCode project parameters to JSON file.
positional arguments:
output_file Path to the output JSON file
optional arguments:
-h, --help show this help message and exit
--all Extract parameters with their full info set
--modules [MODULES [MODULES ...]]
Optional list of modules to import first
--path PATH Path to the project root directory if not the current working directory
process(calls)
¶
Evaluate the given calls such as:
- only ElementType.INPUT
are considered.
- result of evaluation is interpreted as (key, value) and aggregated in the final
dictionnary returned by this function.
Ensure the proper Project().mode
is set before calling this function (as it will control
the evaluation of the code call). This function is typically used for InputElement
JSON
extraction. Although the extract_json()
function directly pipes the calls from the code
call graph (through process_call_graph()
), you may input your own code calls (see example
below).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
calls |
List[Dict[str, str]]
|
List of |
required |
Returns:
Type | Description |
---|---|
Dict
|
A dictionnary containing the results of the code evaluation associated to their key id. |
Example
Project().mode = Mode.EXTRACT_ALL
# processing a single call of Slider element
process([{"func": "onecode.slider", "loc": "onecode.slider('my_slider', 0.4)"}])
# => returns the JSON for this parameter, i-e:
# { kind: Slider, value: 0.4, label: 'my_slider', ... }
# processing a single call of a custom MyBox element
process([{"func": "onecode_ext.my_box", "loc": "onecode_ext.my_box('my_box', 'X')"}])
# => returns the JSON for this parameter, i-e:
# { kind: MyBox, value: 'X', label: 'my_box', ... }
# piping the entire call graph of a OneCode Project
statements = process_call_graph(project_path)
for v in statements.values():
p = process(v["calls"])
# ...