Coverage for python/lsst/images/cli/_schemas.py: 90%
31 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-09-09 02:31 -0700
« prev ^ index » next coverage.py v7.15.4, created at 2026-09-09 02:31 -0700
1# This file is part of lsst-images.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# Use of this source code is governed by a 3-clause BSD-style
10# license that can be found in the LICENSE file.
11from __future__ import annotations
13__all__ = ("schemas",)
15from pathlib import Path
17import click
19from ..serialization import FrozenSchemaError, check_frozen_schemas, write_frozen_schemas
21_DIR_OPTION = click.option(
22 "--dir",
23 "directory",
24 type=click.Path(file_okay=False, path_type=Path),
25 default=Path("schemas"),
26 show_default=True,
27 help="Directory holding the frozen schema files.",
28)
30_PACKAGE_OPTION = click.option(
31 "--package",
32 default="lsst.images",
33 show_default=True,
34 help="Freeze only schemas whose model classes are defined in this package; "
35 "external packages providing schemas through the 'lsst.images.schemas' "
36 "entry point group can use this to freeze their own schemas for their "
37 "own documentation site.",
38)
41@click.group(name="schemas")
42def schemas() -> None:
43 """Manage the frozen JSON schema files committed to the repository."""
46@schemas.command(name="write")
47@_DIR_OPTION
48@_PACKAGE_OPTION
49def write(directory: Path, package: str) -> None:
50 """Write the JSON schema file for every current schema.
52 Overwrites a stale file for the same schema version (schemas evolve in
53 place until the first data release) and never touches files for
54 superseded versions.
55 """
56 try:
57 changed = write_frozen_schemas(directory, package)
58 except FrozenSchemaError as exc:
59 raise click.ClickException(str(exc)) from exc
60 for path in changed:
61 click.echo(f"wrote {path}")
62 if not changed: 62 ↛ 63line 62 didn't jump to line 63 because the condition on line 62 was never true
63 click.echo("all frozen schema files are already up to date")
64 else:
65 click.echo(
66 "if any of the above is a newly finalized schema, now run "
67 "'lsst-images-admin fixtures freeze' to pair its fixture"
68 )
71@schemas.command(name="check")
72@_DIR_OPTION
73@_PACKAGE_OPTION
74def check(directory: Path, package: str) -> None:
75 """Exit nonzero if any frozen schema file is missing or stale."""
76 problems = check_frozen_schemas(directory, package)
77 for problem in problems:
78 click.echo(problem)
79 if problems:
80 raise click.ClickException("run 'lsst-images-admin schemas write' and commit the result")