Skip to content

Config

sereto.config

add_dates_config(report, settings)

Add date to the configuration for a report.

Parameters:

Name Type Description Default
report Report

Report's representation.

required
settings Settings

Global settings.

required
Source code in sereto/config.py
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
@validate_call
def add_dates_config(report: Report, settings: Settings) -> None:
    """Add date to the configuration for a report.

    Args:
        report: Report's representation.
        settings: Global settings.
    """
    cfg = report.config
    dates: list[Date] = cfg.dates if len(cfg.updates) == 0 else cfg.updates[-1].dates

    date_type: DateType = load_enum(enum=DateType, prompt="Type")
    new_date = prompt_user_for_date(date_type=date_type)
    dates.append(Date(type=date_type, date=new_date))

    write_config(config=report.config, settings=settings)

add_people_config(report, settings)

Add person to the configuration for a report.

Parameters:

Name Type Description Default
report Report

Report's representation.

required
settings Settings

Global settings.

required
Source code in sereto/config.py
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
@validate_call
def add_people_config(report: Report, settings: Settings) -> None:
    """Add person to the configuration for a report.

    Args:
        report: Report's representation.
        settings: Global settings.
    """
    cfg = report.config
    people: list[Person] = cfg.people if len(cfg.updates) == 0 else cfg.updates[-1].people

    person_type: PersonType = load_enum(enum=PersonType, prompt="Type")
    new_person = prompt_user_for_person(person_type=person_type)
    people.append(new_person)

    write_config(config=report.config, settings=settings)

add_targets_config(report, settings)

Add target to the configuration for a report.

Parameters:

Name Type Description Default
report Report

Report's representation.

required
settings Settings

Global settings.

required
Source code in sereto/config.py
324
325
326
327
328
329
330
331
332
333
334
335
336
337
@validate_call
def add_targets_config(report: Report, settings: Settings) -> None:
    """Add target to the configuration for a report.

    Args:
        report: Report's representation.
        settings: Global settings.
    """
    cfg = report.config
    targets: list[Target] = cfg.targets if len(cfg.updates) == 0 else cfg.updates[-1].targets
    targets.append(prompt_user_for_target(settings=settings))
    write_config(config=cfg, settings=settings)
    report.load_runtime_vars(settings=settings)
    report_create_missing(report=report, settings=settings, version=cfg.last_version())

delete_dates_config(report, settings, index)

Delete date from the configuration by its index.

Parameters:

Name Type Description Default
report Report

Report's representation.

required
settings Settings

Global settings.

required
index int

Index to item which should be deleted. First item is 1.

required
Source code in sereto/config.py
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
@validate_call
def delete_dates_config(report: Report, settings: Settings, index: int) -> None:
    """Delete date from the configuration by its index.

    Args:
        report: Report's representation.
        settings: Global settings.
        index: Index to item which should be deleted. First item is 1.
    """
    cfg = report.config
    dates: list[Date] = cfg.dates if len(cfg.updates) == 0 else cfg.updates[-1].dates
    index -= 1
    if not 0 <= index <= len(dates) - 1:
        raise SeretoValueError("invalid index, not in allowed range")
    del dates[index]
    write_config(config=cfg, settings=settings)

delete_people_config(report, settings, index)

Delete person from the configuration by its index.

Parameters:

Name Type Description Default
report Report

Report's representation.

required
settings Settings

Global settings.

required
index int

Index to item which should be deleted. First item is 1.

required
Source code in sereto/config.py
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
@validate_call
def delete_people_config(report: Report, settings: Settings, index: int) -> None:
    """Delete person from the configuration by its index.

    Args:
        report: Report's representation.
        settings: Global settings.
        index: Index to item which should be deleted. First item is 1.
    """
    cfg = report.config
    people: list[Person] = cfg.people if len(cfg.updates) == 0 else cfg.updates[-1].people
    index -= 1
    if not 0 <= index <= len(people) - 1:
        raise SeretoValueError("invalid index, not in allowed range")
    del people[index]
    write_config(config=cfg, settings=settings)

delete_targets_config(report, settings, index)

Delete target from the configuration by its index.

Parameters:

Name Type Description Default
report Report

Report's representation.

required
settings Settings

Global settings.

required
index int

Index to item which should be deleted. First item is 1.

required
Source code in sereto/config.py
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
@validate_call
def delete_targets_config(report: Report, settings: Settings, index: int) -> None:
    """Delete target from the configuration by its index.

    Args:
        report: Report's representation.
        settings: Global settings.
        index: Index to item which should be deleted. First item is 1.
    """
    cfg = report.config
    targets: list[Target] = cfg.targets if len(cfg.updates) == 0 else cfg.updates[-1].targets
    index -= 1
    if not 0 <= index <= len(targets) - 1:
        raise SeretoValueError("invalid index, not in allowed range")
    target_path = targets[index].path
    del targets[index]
    write_config(config=cfg, settings=settings)

    if (
        target_path is not None
        and target_path.is_dir()
        and Confirm.ask(
            f'[yellow]Delete "{target_path}" from the filesystem?',
            console=Console(),
            default=False,
        )
    ):
        shutil.rmtree(target_path)

edit_config(settings)

Edit the configuration file in default CLI editor.

Parameters:

Name Type Description Default
settings Settings

Global settings.

required
Source code in sereto/config.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
@validate_call
def edit_config(settings: Settings) -> None:
    """Edit the configuration file in default CLI editor.

    Args:
        settings: Global settings.
    """
    sereto_ver = importlib.metadata.version("sereto")

    if not (path := Report.get_config_path(dir_subtree=settings.reports_path)).is_file():
        write_config(
            config=Config(
                sereto_version=SeretoVersion.from_str(sereto_ver),
                id="",
                name="",
                report_version=ReportVersion.from_str("v1.0"),
            ),
            settings=settings,
        )

    click.edit(filename=str(path))

show_config(report, output_format, all=False, version=None)

Display the configuration for a report.

Parameters:

Name Type Description Default
report Report

Report's representation.

required
output_format OutputFormat

Format of the output.

required
all bool

Whether to show values from all versions or just the last one.

False
version ReportVersion | None

Show config at specific version, e.g. 'v1.0'.

None
Source code in sereto/config.py
 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
@validate_call
def show_config(
    report: Report,
    output_format: OutputFormat,
    all: bool = False,
    version: ReportVersion | None = None,
) -> None:
    """Display the configuration for a report.

    Args:
        report: Report's representation.
        output_format: Format of the output.
        all: Whether to show values from all versions or just the last one.
        version: Show config at specific version, e.g. 'v1.0'.
    """
    if version is None:
        version = report.config.last_version()

    cfg = report.config if all else report.config.at_version(version)

    match output_format:
        case OutputFormat.table:
            Console().print(f"\n\n[blue]{cfg.id} - {cfg.name}\n", justify="center")
            show_targets_config(
                report=report,
                output_format=OutputFormat.table,
                all=all,
                version=version,
            )
            show_dates_config(
                report=report,
                output_format=OutputFormat.table,
                all=all,
                version=version,
            )
            show_people_config(
                report=report,
                output_format=OutputFormat.table,
                all=all,
                version=version,
            )
        case OutputFormat.json:
            Console().print_json(cfg.model_dump_json())

show_dates_config(report, output_format, all, version)

Display the configured dates.

By default, if neither of version and all arguments are used, dates from the latest version are displayed.

Parameters:

Name Type Description Default
report Report

Report's representation.

required
output_format OutputFormat

Select format of the output.

required
all bool

Show dates from all versions.

required
version ReportVersion | None

Show dates from specific version.

required
Source code in sereto/config.py
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
@validate_call
def show_dates_config(
    report: Report,
    output_format: OutputFormat,
    all: bool,
    version: ReportVersion | None,
) -> None:
    """Display the configured dates.

    By default, if neither of `version` and `all` arguments are used, dates from the latest version are displayed.

    Args:
        report: Report's representation.
        output_format: Select format of the output.
        all: Show dates from all versions.
        version: Show dates from specific version.
    """
    if version is None:
        version = report.config.last_version()

    match output_format:
        case OutputFormat.table:
            for report_version in report.config.versions() if all else [version]:
                Console().line()
                table = Table(
                    "%",
                    "Type",
                    "From",
                    "To",
                    title=f"Dates {report_version}",
                    box=box.MINIMAL,
                )

                for ix, date in enumerate(report.config.at_version(version=report_version).dates, start=1):
                    match date.date:
                        case SeretoDate():
                            table.add_row(str(ix), date.type.value, str(date.date), "[yellow]n/a")
                        case DateRange():
                            table.add_row(
                                str(ix),
                                date.type.value,
                                str(date.date.start),
                                str(date.date.end),
                            )
                Console().print(table, justify="center")
        case OutputFormat.json:
            if all:
                all_dates = RootModel(dict[str, DatesList]).model_validate(
                    {str(ver): report.config.at_version(version=ver).dates for ver in report.config.versions()}
                )
                Console().print_json(all_dates.model_dump_json())
            else:
                Console().print_json(
                    DatesList.model_validate(report.config.at_version(version).dates).model_dump_json()
                )

show_people_config(report, output_format, all, version)

Display the configured people.

By default, if neither of version and all arguments are used, people from the latest version are displayed.

Parameters:

Name Type Description Default
report Report

Report's representation.

required
output_format OutputFormat

Select format of the output.

required
all bool

Show people from all versions.

required
version ReportVersion | None

Show people from specific version.

required
Source code in sereto/config.py
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
@validate_call
def show_people_config(
    report: Report,
    output_format: OutputFormat,
    all: bool,
    version: ReportVersion | None,
) -> None:
    """Display the configured people.

    By default, if neither of `version` and `all` arguments are used, people from the latest version are displayed.

    Args:
        report: Report's representation.
        output_format: Select format of the output.
        all: Show people from all versions.
        version: Show people from specific version.
    """
    if version is None:
        version = report.config.last_version()

    match output_format:
        case OutputFormat.table:
            for report_version in report.config.versions() if all else [version]:
                Console().line()
                table = Table(
                    "%",
                    "Type",
                    "Name",
                    "BU",
                    "Email",
                    "Role",
                    title=f"People {report_version}",
                    box=box.MINIMAL,
                )
                for ix, person in enumerate(report.config.at_version(version=report_version).people, start=1):
                    table.add_row(
                        str(ix),
                        person.type,
                        person.name if person.name is not None else "[yellow]n/a",
                        (person.business_unit if person.business_unit is not None else "[yellow]n/a"),
                        person.email if person.email is not None else "[yellow]n/a",
                        person.role if person.role is not None else "[yellow]n/a",
                    )
                Console().print(table, justify="center")
        case OutputFormat.json:
            if all:
                all_people = RootModel(dict[str, PersonList]).model_validate(
                    {str(ver): report.config.at_version(version=ver).people for ver in report.config.versions()}
                )
                Console().print_json(all_people.model_dump_json())
            else:
                Console().print_json(
                    PersonList.model_validate(report.config.at_version(version).people).model_dump_json()
                )

show_targets_config(report, output_format, all, version)

Display the configured targets.

By default, if neither of version and all arguments are used, targets from the latest version are displayed.

Parameters:

Name Type Description Default
report Report

Report's representation.

required
output_format OutputFormat

Select format of the output.

required
all bool

Show targets from all versions.

required
version ReportVersion | None

Show targets from the specified report's version.

required
Source code in sereto/config.py
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
@validate_call
def show_targets_config(
    report: Report,
    output_format: OutputFormat,
    all: bool,
    version: ReportVersion | None,
) -> None:
    """Display the configured targets.

    By default, if neither of `version` and `all` arguments are used, targets from the latest version are displayed.

    Args:
        report: Report's representation.
        output_format: Select format of the output.
        all: Show targets from all versions.
        version: Show targets from the specified report's version.
    """
    if version is None:
        version = report.config.last_version()

    match output_format:
        case OutputFormat.table:
            for report_version in report.config.versions() if all else [version]:
                Console().line()
                table = Table(
                    "%",
                    "Category",
                    "Name",
                    title=f"Targets {report_version}",
                    box=box.MINIMAL,
                )
                for ix, target in enumerate(report.config.at_version(version=report_version).targets, start=1):
                    table.add_row(str(ix), target.category, target.name)
                Console().print(table, justify="center")
        case OutputFormat.json:
            if all:
                all_targets = RootModel(dict[str, TargetList]).model_validate(
                    {str(ver): report.config.at_version(version=ver).targets for ver in report.config.versions()}
                )
                Console().print_json(all_targets.model_dump_json())
            else:
                Console().print_json(
                    TargetList.model_validate(report.config.at_version(version).targets).model_dump_json()
                )

write_config(config, settings)

Write report configuration to a file.

Parameters:

Name Type Description Default
config Config

Report's configuration.

required
settings Settings

Global settings.

required

Raises:

Type Description
SeretoPathError

If the report directory cannot be found.

Source code in sereto/config.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
@validate_call
def write_config(config: Config, settings: Settings) -> None:
    """Write report configuration to a file.

    Args:
        config: Report's configuration.
        settings: Global settings.

    Raises:
        SeretoPathError: If the report directory cannot be found.
    """
    config_path = Report.get_config_path(dir_subtree=settings.reports_path)

    with config_path.open("w", encoding="utf-8") as f:
        f.write(config.model_dump_json(indent=2))
        f.write("\n")