How cogu/autosar works
Project type and purpose
• This is a Python library/toolkit (not a standalone application) for generating and parsing AUTOSAR XML (ARXML) files.
• Primary use case: allow Python scripts to build AUTOSAR XML documents (via autosar.xml.Workspace) and, to a lesser extent, read existing ARXML into Python objects.
• Secondary use case: generate RTE headers from an intermediate model (autosar.generator).
Top-level architecture layers
A. Presentation / Client Layer (User code & examples)
B. Core Library Layer (the “autosar” package)
1. XML API (autosar.xml)
2. Intermediate Model (autosar.model)
3. Code Generator (autosar.generator)
C. Infrastructure Layer (third‐party dependencies, file system, tests, examples)
Main components and their responsibilities
• User Code / Examples / Scripts
• scripts in /examples call into autosar.xml.Workspace and convenience methods in autosar.xml.element.
• run via the CLI wrappers (run_examples.sh / .cmd).
• autosar.xml (XML handling)
• Reader: reader.py parses ARXML into Python objects.
• Writer: writer.py serializes objects to an ARXML document.
• Document & Element factories: builds XML trees.
• Workspace: orchestrates packages, documents, template config, API layers (simple vs advanced).
• autosar.model (Intermediate representation)
• Mirrors key AUTOSAR meta-model elements (element.py, enumeration.py, implementation.py).
• Provides a decoupled model for RTE generation.
• autosar.generator (RTE Type Header Generation)
• Generates C‐header files or other artifacts from the intermediate model (type_generator.py).
• Infrastructure / Utilities
• Third-party libraries: lxml, tomli, cfile.
• Build & Test: pyproject.toml, requirements.txt, GitHub Actions (python‐package.yml), linters (.pylintrc, flake8 config).
• Documentation: /doc/markdown, README, CHANGELOG, LICENSE.
• Unit Tests: /tests covering xml, model, generator.
Interactions & Data Flows
• User Code → Workspace: create package maps, elements → add to workspace
• Workspace → XML Writer: builds ARXML
• XML Reader → Workspace → Model: parsed XML flows into the intermediate model
• Model → Generator: model passed to RTE generator for header output
• Workspace → File System: read/write ARXML and config files (.toml)
• Workspace → Template Engine (advanced API)
• CI/CD & Linters run on the entire codebase
Important patterns & design principles
• Layered architecture: clear separation of XML I/O, in-memory model, and code generation
• Modular design: each XML element type lives in its own module
• Convenience factories: make_… and create_… methods for user simplicity
• Simple vs Advanced API in Workspace—highlight as two parallel sub-flows
• Type hints & Enums: modern Python 3.10+ usage