Coverage for python/lsst/images/cli/_inspect.py: 93%

28 statements  

« prev     ^ index     » next       coverage.py v7.14.1, created at 2026-06-24 01:50 -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 

12 

13__all__ = ("inspect",) 

14 

15import click 

16 

17from lsst.utils.introspection import get_full_type_name 

18 

19from ..serialization import ArchiveReadError, backend_for_path, public_type_for_schema 

20 

21 

22@click.command(name="inspect") 

23@click.argument("file", type=click.Path(exists=True, dir_okay=False)) 

24def inspect(file: str) -> None: 

25 """Print basic information about an lsst.images file. 

26 

27 Reports the schema URL, container format version, and the public 

28 Python class registered for the file's schema (when known) without 

29 deserializing pixel data. 

30 """ 

31 try: 

32 backend = backend_for_path(file) 

33 except ValueError as err: 

34 raise click.ClickException(str(err)) from None 

35 try: 

36 info = backend.input_archive.get_basic_info(file) 

37 except (ArchiveReadError, ValueError) as err: 

38 raise click.ClickException(f"Could not read {file}: {err}") from None 

39 fmt = "n/a" if info.format_version is None else str(info.format_version) 

40 public_cls = public_type_for_schema(info.schema_name) 

41 if public_cls is not None: 

42 python_class = get_full_type_name(public_cls) 

43 else: 

44 python_class = f"<unregistered: {info.schema_name}>" 

45 click.echo(f"path: {file}") 

46 click.echo(f"format: {backend.name}") 

47 click.echo(f"schema name: {info.schema_name}") 

48 click.echo(f"schema version: {info.schema_version}") 

49 click.echo(f"schema URL: {info.schema_url}") 

50 click.echo(f"format version: {fmt}") 

51 click.echo(f"python class: {python_class}")