-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge: Modeling rules and validation (#428)
- Loading branch information
Showing
10 changed files
with
1,488 additions
and
16 deletions.
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.