xactflow 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,28 @@
1
+ from . import ( # noqa: F401 (registers every Annex B rule as an import side effect)
2
+ scr_01,
3
+ scr_02,
4
+ scr_03,
5
+ scr_04,
6
+ scr_05,
7
+ scr_06,
8
+ scr_07,
9
+ scr_08,
10
+ scr_09,
11
+ scr_10,
12
+ scr_11,
13
+ scr_12,
14
+ scr_13,
15
+ scr_14,
16
+ scr_15,
17
+ )
18
+ from .registry import Rule, all_rules, rule, stub
19
+ from .runner import run_post_config_checks, run_single_doc_checks
20
+
21
+ __all__ = [
22
+ "Rule",
23
+ "all_rules",
24
+ "rule",
25
+ "stub",
26
+ "run_post_config_checks",
27
+ "run_single_doc_checks",
28
+ ]
@@ -0,0 +1,89 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+ from typing import Callable, Iterator, List
5
+
6
+ from ..diagnostics import Diagnostic
7
+
8
+
9
+ @dataclass(frozen=True)
10
+ class Rule:
11
+ """One IEEE 1685-2022 Annex B semantic consistency rule (SCR)."""
12
+
13
+ id: str
14
+ table: str
15
+ name: str
16
+ single_doc_check: bool
17
+ post_config: bool
18
+ description: str
19
+ check: Callable[[object], Iterator[Diagnostic]]
20
+ implemented: bool
21
+
22
+
23
+ _REGISTRY: List[Rule] = []
24
+
25
+
26
+ def rule(
27
+ *,
28
+ id: str,
29
+ table: str,
30
+ name: str,
31
+ single_doc_check: bool,
32
+ post_config: bool,
33
+ description: str,
34
+ ) -> Callable[[Callable[[object], Iterator[Diagnostic]]], Callable[[object], Iterator[Diagnostic]]]:
35
+ """Decorator registering a check function as one working Annex B SCR rule."""
36
+
37
+ def decorator(
38
+ check: Callable[[object], Iterator[Diagnostic]]
39
+ ) -> Callable[[object], Iterator[Diagnostic]]:
40
+ _REGISTRY.append(
41
+ Rule(
42
+ id=id,
43
+ table=table,
44
+ name=name,
45
+ single_doc_check=single_doc_check,
46
+ post_config=post_config,
47
+ description=description,
48
+ check=check,
49
+ implemented=True,
50
+ )
51
+ )
52
+ return check
53
+
54
+ return decorator
55
+
56
+
57
+ def _not_yet_implemented(_subject: object) -> Iterator[Diagnostic]:
58
+ return []
59
+
60
+
61
+ def stub(
62
+ *,
63
+ id: str,
64
+ table: str,
65
+ name: str,
66
+ single_doc_check: bool,
67
+ post_config: bool,
68
+ description: str,
69
+ ) -> None:
70
+ """Register an Annex B rule that is tracked (discoverable via all_rules()) but has no check
71
+ logic implemented yet. Its check always reports nothing; `implemented` is False so callers
72
+ can tell it apart from a working rule registered through @rule.
73
+ """
74
+ _REGISTRY.append(
75
+ Rule(
76
+ id=id,
77
+ table=table,
78
+ name=name,
79
+ single_doc_check=single_doc_check,
80
+ post_config=post_config,
81
+ description=description,
82
+ check=_not_yet_implemented,
83
+ implemented=False,
84
+ )
85
+ )
86
+
87
+
88
+ def all_rules() -> List[Rule]:
89
+ return list(_REGISTRY)
xactflow/SCR/runner.py ADDED
@@ -0,0 +1,28 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import List
4
+
5
+ from ..diagnostics import Diagnostic
6
+ from .registry import all_rules
7
+
8
+
9
+ def run_single_doc_checks(document: object) -> List[Diagnostic]:
10
+ """Run every SCR rule checkable on one IP-XACT document alone (single_doc_check rules)."""
11
+ diagnostics: List[Diagnostic] = []
12
+ for r in all_rules():
13
+ if r.single_doc_check:
14
+ diagnostics.extend(r.check(document))
15
+ return diagnostics
16
+
17
+
18
+ def run_post_config_checks(elaborated: object) -> List[Diagnostic]:
19
+ """Run every SCR rule that needs the relationships between documents.
20
+
21
+ Takes an elaborate.ElaboratedDesign (accepted as object here to avoid a circular import
22
+ between xactflow.SCR and xactflow.elaborate, since elaborate.resolver itself calls this).
23
+ """
24
+ diagnostics: List[Diagnostic] = []
25
+ for r in all_rules():
26
+ if not r.single_doc_check:
27
+ diagnostics.extend(r.check(elaborated))
28
+ return diagnostics