Skip to content

fprime-community/fprime-python-model

Repository files navigation

F Prime Python Model

F Prime Python Model is a utility for translating fpp-to-json AST, Location Map, and Analysis JSON to Python data structures. For more information on the fpp-to-json tool, see the FPP User's Guide.

Installation

git clone https://github.com/fprime-community/fprime-python-model.git
cd fprime-python-model
pip install .

Usage

In order to use this utility, you must first run the fpp-to-json tool to generate the AST, Location Map, and Analysis JSON files for a given FPP model. For specific steps on how to run fpp-to-json, see the FPP User's Guide.

Note: When running the fpp-to-json tool, ensure that you do not include the -s option as that will prevent the Analysis JSON from being generated.

Once the AST, Location Map, and Analysis JSON files have been generated, you can translate the model JSON to it's Python representation by doing:

from fprime_python_model.model import FprimePythonModel

model = FprimePythonModel(
    ast_file_path, # Path to AST JSON file
    locations_file_path, # Path to Location Map JSON file
    analysis_json_file_path # Path to Analysis JSON file
)

Once an FprimePythonModel is constructed, you can access the python data structures that represent the FPP AST, Location Map, and Analysis of the model:

model.ast # Model AST
model.locations # Location map
model.analysis # Model Analysis data structure

Traversing AST

You can traverse AST nodes by writing an AST visitor, which can be used to query or search the AST of a model. An AST visitor base class (AstVisitor) is provided in fprime_python_model/utils/fpp_ast_visitor.py.

Examples of how the AstVistor is used in this project are:

  • fprime_python_model/utils/fpp_ast_writer.py, which is used to print the AST to the console
  • fprime_python_model/translators/construct_ast_id_map.py, which is used to create a mapping from AST IDs to AST nodes.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages