Coverage for python/lsst/images/cli/_schemas.py: 94%
27 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-07-22 17:43 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-07-22 17:43 +0000
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 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: # numpydoc ignore=PR01
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 changed = write_frozen_schemas(directory, package)
57 for path in changed:
58 click.echo(f"wrote {path}")
59 if not changed: 59 ↛ 60line 59 didn't jump to line 60 because the condition on line 59 was never true
60 click.echo("all frozen schema files are already up to date")
63@schemas.command(name="check")
64@_DIR_OPTION
65@_PACKAGE_OPTION
66def check(directory: Path, package: str) -> None: # numpydoc ignore=PR01
67 """Exit nonzero if any frozen schema file is missing or stale."""
68 problems = check_frozen_schemas(directory, package)
69 for problem in problems:
70 click.echo(problem)
71 if problems:
72 raise click.ClickException("run 'lsst-images-admin schemas write' and commit the result")