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

safl / senfd / 13566383609

27 Feb 2025 12:28PM UTC coverage: 96.402% (-1.9%) from 98.268%
13566383609

push

github

mbrsamsung
fix(example): update based on schema changes

Signed-off-by: Simon A. F. Lund <os@safl.dk>

777 of 806 relevant lines covered (96.4%)

0.96 hits per line

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

97.83
/src/senfd/cli.py
1
"""
2
Command-Line Interface
3
======================
4

5
Produces organized and semantically enriched ``.json`` documents from
6
"""
7

8
import json
1✔
9
from argparse import ArgumentParser, Namespace, RawTextHelpFormatter
1✔
10
from pathlib import Path
1✔
11
from typing import List
1✔
12

13
import senfd
1✔
14
import senfd.pipeline
1✔
15
import senfd.schemas
1✔
16
from senfd.documents import get_document_classes
1✔
17
from senfd.documents.base import to_file
1✔
18
from senfd.documents.merged import FromFolder
1✔
19
from senfd.errors import Error
1✔
20

21
PARSEARGS_EPILOG = """\
1✔
22
Senfd
23
=====
24

25
The --skip-figures flag specifies a path to a TOML file containing a list of
26
figures to be skipped during processing.
27

28
The TOML file must follow this format:
29

30
[[skip]]
31
regex = "^Decimal.and.Binary.Units$"
32
matches = 1
33
description = ""
34

35
[[skip]]
36
regex = "^Byte, Word, and Dword Relationships$"
37
matches = 1
38
description = ""
39

40

41
Each entry under [[skip]] consists of:
42
  - regex: A regular expression matching the figure description.
43
  - matches: The expected number of occurrences of this figure in the document.
44
  - description: An optional text field describing the reason for skipping.
45

46
This allows flexible and pattern-based skipping of figures during execution.
47
"""
48

49

50
def to_log_file(errors: List[Error], filename: str, output: Path) -> Path:
1✔
51
    content = json.dumps(
1✔
52
        [{"type": type(error).__name__, **error.model_dump()} for error in errors],
53
        indent=4,
54
    )
55

56
    return to_file(content, f"{filename}.error.log", output)
1✔
57

58

59
def parse_args() -> Namespace:
1✔
60
    """Return command-line arguments"""
61

62
    parser = ArgumentParser(
1✔
63
        description="Semantically organize and enrich figures",
64
        epilog=PARSEARGS_EPILOG,
65
        formatter_class=RawTextHelpFormatter,
66
    )
67
    parser.add_argument(
1✔
68
        "document", nargs="*", type=Path, help="path to one or more document(s)"
69
    )
70
    parser.add_argument(
1✔
71
        "--output",
72
        type=Path,
73
        help="directory where the output will be saved",
74
        default=Path("output"),
75
    )
76
    parser.add_argument(
1✔
77
        "--dump-schema",
78
        action="store_true",
79
        help="dump schema(s) and exit",
80
    )
81
    parser.add_argument(
1✔
82
        "--skip-figures",
83
        type=Path,
84
        help="Path to toml file that contains list of figure classifiers to skip",
85
    )
86
    parser.add_argument(
1✔
87
        "--version",
88
        action="store_true",
89
        help="print the version and exit",
90
    )
91
    args = parser.parse_args()
1✔
92
    if not args.document and not args.dump_schema and not args.version:
1✔
93
        parser.error("the following arguments are required: document")
1✔
94

95
    return args
1✔
96

97

98
def main() -> int:
1✔
99
    """Command-line entrypoint"""
100

101
    args = parse_args()
1✔
102
    args.output.mkdir(parents=True, exist_ok=True)
1✔
103

104
    if args.version:
1✔
105
        print(senfd.__version__)
1✔
106
        return 0
1✔
107

108
    if args.dump_schema:
1✔
109
        for docclass in get_document_classes():
1✔
110
            docclass.to_schema_file(args.output)
1✔
111
        return 0
1✔
112

113
    for count, path in enumerate(sorted(args.document), 1):
1✔
114
        args.output.mkdir(parents=True, exist_ok=True)
1✔
115

116
        errors = senfd.pipeline.process(path, args.output, args)
1✔
117
        to_log_file(errors, path.stem, args.output)
1✔
118

119
    if FromFolder.is_applicable(args.output):  # Merge ModelDocuments
1✔
120
        merged, errors = FromFolder.convert(args.output, args)
1✔
121
        merged.to_json_file(args.output / merged.json_filename())
1✔
122

123
    return 0
1✔
124

125

126
if __name__ == "__main__":
1✔
127
    main()
×
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