• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aas-core-works / aas-core-codegen / 25098769931

29 Apr 2026 08:30AM UTC coverage: 83.966% (-0.02%) from 83.987%
25098769931

Pull #615

github

web-flow
Merge 1321aff3e into c752b149a
Pull Request #615: Discontinue RDF+SHACL and JSON-LD generators

30593 of 36435 relevant lines covered (83.97%)

3.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

79.41
/aas_core_codegen/specific_implementations.py
1
"""Handle implementation snippets regardless for all implementation languages."""
2

3
import pathlib
4✔
4
import re
4✔
5
from typing import cast, Mapping, Tuple, Optional, List
4✔
6

7
from icontract import require, ensure
4✔
8

9
from aas_core_codegen.common import Stripped
4✔
10

11
# noinspection RegExpSimplifiable
12
IMPLEMENTATION_KEY_RE = re.compile("[a-zA-Z_][a-zA-Z_0-9.]*(/[a-zA-Z_][a-zA-Z_0-9.]*)*")
4✔
13

14

15
class ImplementationKey(str):
4✔
16
    """Represent a key in the map of specific implementations."""
17

18
    @require(lambda key: IMPLEMENTATION_KEY_RE.fullmatch(key))
4✔
19
    def __new__(cls, key: str) -> "ImplementationKey":
4✔
20
        return cast(ImplementationKey, key)
4✔
21

22

23
SpecificImplementations = Mapping[ImplementationKey, Stripped]
4✔
24

25

26
@ensure(lambda result: (result[0] is not None) ^ (result[1] is not None))
4✔
27
def read_from_directory(
4✔
28
    snippets_dir: pathlib.Path,
29
) -> Tuple[Optional[SpecificImplementations], Optional[List[str]]]:
30
    """
31
    Read all the implementation-specific code snippets from the ``snippets_dir``.
32

33
    :return: either the map of the implementations, or the errors
34
    """
35
    mapping = dict()  # pylint: disable=use-dict-literal
4✔
36

37
    errors = []  # type: List[str]
4✔
38
    for pth in snippets_dir.glob("**/*"):
4✔
39
        # NOTE (mristin, 2022-08-25):
40
        # Ignore hidden or special files. In particular, we do not want Git-related
41
        # files such as ``.gitignore`` to be included as snippets.
42
        if pth.name.startswith("."):
4✔
43
            continue
×
44

45
        if pth.is_dir():
4✔
46
            continue
4✔
47

48
        maybe_key = (pth.relative_to(snippets_dir).parent / pth.name).as_posix()
4✔
49
        if IMPLEMENTATION_KEY_RE.fullmatch(maybe_key) is None:
4✔
50
            errors.append(
×
51
                f"The snippet key is not valid "
52
                f"according to {IMPLEMENTATION_KEY_RE.pattern}: {maybe_key}"
53
            )
54
            continue
×
55

56
        key = ImplementationKey(maybe_key)
4✔
57

58
        try:
4✔
59
            value = Stripped(pth.read_text(encoding="utf-8").strip())
4✔
60
        except UnicodeDecodeError as error:
×
61
            errors.append(
×
62
                f"The snippet file is not a valid UTF-8: {pth}. "
63
                f"This was the decoding error: {error}"
64
            )
65
            continue
×
66

67
        mapping[key] = value
4✔
68

69
    if errors:
4✔
70
        return None, errors
×
71

72
    return mapping, None
4✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc