-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement modelling rules and validation
Note that this feature is distinct from the "Validate Model" option in the Capella GUI. Validation in capellambse uses its own custom set of rules. Also note that this is only an initial version, which still has a lot of limitations. In future iterations, the applied ruleset may be extended, modified, or made more configurable from a user's perspective. Co-authored-by: Ernst Würger <ernst.wuerger@deutschebahn.com> Co-authored-by: Martin Lehmann <martin.lehmann@deutschebahn.com> Co-authored-by: Viktor Kravchenko <viktor.kravchenko@deutschebahn.com>
- Loading branch information
1 parent
610da1b
commit add991f
Showing
10 changed files
with
1,469 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# SPDX-FileCopyrightText: Copyright DB InfraGO AG | ||
# SPDX-License-Identifier: Apache-2.0 | ||
"""The module provides management and evaluation of validation rules. | ||
Validation rules are conditions ensuring that specific modeling | ||
guidelines are followed. These rules apply to particular types of model | ||
elements or to diagrams, and values of metrics. By evaluating each rule, | ||
the module generates validation results, indicating whether the | ||
corresponding guideline has been satisfied or not. This way, the module | ||
helps maintain the quality and consistency of the model. | ||
""" | ||
|
||
from ._validate import * | ||
|
||
from . import rules # isort: skip | ||
|
||
|
||
def init() -> None: | ||
# pylint: disable=redefined-outer-name # false-positive | ||
import capellambse | ||
from capellambse.model import common as c | ||
|
||
c.set_accessor( | ||
capellambse.MelodyModel, | ||
"validation", | ||
c.AlternateAccessor(ModelValidation), | ||
) | ||
capellambse.MelodyModel.validate = property( # type: ignore[attr-defined] | ||
lambda self: self.validation.validate | ||
) | ||
|
||
c.set_accessor( | ||
c.GenericElement, "validation", c.AlternateAccessor(ElementValidation) | ||
) | ||
c.GenericElement.validate = property( # type: ignore[attr-defined] | ||
lambda self: self.validation.validate | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# SPDX-FileCopyrightText: Copyright DB InfraGO AG | ||
# SPDX-License-Identifier: Apache-2.0 | ||
from __future__ import annotations | ||
|
||
import logging | ||
import typing as t | ||
|
||
import click | ||
import jinja2 | ||
|
||
import capellambse | ||
|
||
|
||
@click.command() | ||
@click.option("-m", "--model", required=True, type=capellambse.ModelCLI()) | ||
@click.option( | ||
"-o", | ||
"--output", | ||
type=click.File("w", atomic=True), | ||
required=True, | ||
help="Output file to render the template into", | ||
) | ||
@click.option("-t", "--template", help="An optional custom template to render") | ||
def _main( | ||
model: capellambse.MelodyModel, | ||
template: str | None, | ||
output: t.IO[str], | ||
) -> None: | ||
logging.basicConfig() | ||
|
||
loader: jinja2.BaseLoader | ||
if template is None: | ||
loader = jinja2.PackageLoader("capellambse", "extensions/validation") | ||
template = "report-template.html.jinja" | ||
else: | ||
loader = jinja2.FileSystemLoader(".") | ||
env = jinja2.Environment(loader=loader) | ||
|
||
with output: | ||
env.get_template(template).stream( | ||
model=model, | ||
results=model.validation.validate(), | ||
).dump(output) | ||
|
||
|
||
if __name__ == "__main__": | ||
_main() |
Oops, something went wrong.