Skip to content

config

Contains configuration for the diffannotator module

JSONFormat

Bases: Enum

To be used as name of the format, e.g. as value of CLI parameter

Source code in src/diffannotator/config.py
17
18
19
20
21
class JSONFormat(Enum):
    """To be used as name of the format, e.g. as value of CLI parameter"""
    V1 = "v1"
    V1_5 = "v1.5"
    V2 = "v2"

JSONFormatExt

Bases: Enum

To be used as file extension (input or output)

Source code in src/diffannotator/config.py
24
25
26
27
28
class JSONFormatExt(Enum):
    """To be used as file extension (input or output)"""
    V1 = ".json"
    V1_5 = ".json"
    V2 = ".v2.json"

get_version()

Return [installed] version of this module / library

Use version from the installed 'diffannotator' package, if possible, with fallback to global variable __version__. Updates __version__.

:returns: version string

Source code in src/diffannotator/config.py
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
def get_version() -> str:
    """Return [installed] version of this module / library

    Use version from the installed 'diffannotator' package,
    if possible, with fallback to global variable `__version__`.
    Updates `__version__`.

    :returns: version string
    """
    global __version__

    if __package__:
        try:
            __version__ = importlib.metadata.version(__package__)
        except importlib.metadata.PackageNotFoundError:
            pass

    return __version__

guess_format_version(file_path, warn_ambiguous=False)

Guess annotation format schema version based on name of the file

:param file_path: name of the file with annotation data :param warn_ambiguous: whether to log warning on situations where the result is ambiguous; as a side effect makes it less forgiving :return: enum defining the format, or None if there is no match

Source code in src/diffannotator/config.py
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
def guess_format_version(file_path: Path, warn_ambiguous: bool = False) -> Optional[JSONFormat]:
    """Guess annotation format schema version based on name of the file

    :param file_path: name of the file with annotation data
    :param warn_ambiguous: whether to log warning on situations where
        the result is ambiguous; as a side effect makes it less forgiving
    :return: enum defining the format, or None if there is no match
    """
    suffixes_2_list = file_path.suffixes[-2:]
    suffixes_2_str = ''.join(suffixes_2_list)

    if not warn_ambiguous:
        if suffixes_2_str in ext_to_ver:
            return ext_to_ver[suffixes_2_str]
        elif not suffixes_2_list:
            return None
        elif suffixes_2_list[-1] == JSONFormatExt.V1_5.value:
            return JSONFormat.V1_5
        else:
            return None

    else:
        if len(suffixes_2_list) <= 1:
            if suffixes_2_str in ext_to_ver:
                return ext_to_ver[suffixes_2_str]
            else:
                return None
        if len(suffixes_2_list) == 2:
            if suffixes_2_str in ext_to_ver:
                return ext_to_ver[suffixes_2_str]
            elif suffixes_2_list[-1] != JSONFormatExt.V1_5.value:
                # no ambiguity: cannot be V1 or V1_5 (not a JSON format)
                return None
            elif secondary_suffix_regexp.match(suffixes_2_list[-2]):
                # no ambiguity: some unknown version
                return None
            else:
                logger.warning(f"Ambiguous annotation file format detected: '{file_path}'")
                return JSONFormat.V1_5