How mayan2022/autosar works
Project Type and Purpose
• This is an open-source Python library for generating and parsing AUTOSAR XML (ARXML) files.
• There is no GUI/front-end; instead it exposes two primary APIs (simple and advanced) for users to assemble a “Workspace,” define elements, and emit or read XML.
A. Client Layer
– User scripts or CLI wrappers (examples under /examples/…, the run_examples.sh scripts)
– Import entry point: import autosar.xml and other packages
B. API Layer
– Simple API (Workspace.create_package_map, add_element, etc.)
– Advanced API (namespace & config-driven, using .toml templates under examples/template)
C. Core Library
1. autosar.xml
• Reader (xml/reader.py, xml/base.py)
• Writer (xml/writer.py)
• Document model (xml/document.py)
• Element definitions (xml/element.py, xml/enumeration.py, etc.)
• Template support (xml/template.py)
2. autosar.model
• Intermediate model (model/element.py, model/implementation.py, model/enumeration.py)
• Acts as a bridge between pure XML objects and code generation
3. autosar.generator
• RTE type header generator (type_generator.py)
• Operates on the model layer to emit code
D. File System & Output
– ARXML files on disk
– Config TOML (advanced API)
– Example output under /examples/template/generated
E. External Dependencies
– lxml (XML parsing & building)
– tomli (TOML parsing)
– cfile (config file helper)
Relationships and Data Flow
• Client script → calls API Layer (Workspace)
• API Layer → orchestrates Core Library
– Simple API invokes Workspace.add_element → xml.element constructors → packages → xml.writer → ARXML files
– Advanced API reads config (.toml) → instantiates template classes → uses same core readers/writers
• Core Library
– autosar.xml.reader parses existing ARXML → produces autosar.xml.element objects → can be converted into autosar.model objects
– autosar.generator consumes autosar.model objects → produces code artifacts (RTE headers)
• File System: both read and write operations
Architectural Patterns & Design Principles
• Factory/Builder: many make_ and create_ convenience methods on element classes
• Layered Architecture: clear separation between API, XML I/O, model, and code generator
• Template Method: XML writer and reader follow a base class in xml/base.py
• Configuration-driven extension: advanced API via .toml and custom template classes