diff --git a/src/griffe/c3linear.py b/src/griffe/c3linear.py index 31282a77..96b1e2e4 100644 --- a/src/griffe/c3linear.py +++ b/src/griffe/c3linear.py @@ -25,7 +25,7 @@ def head(self) -> T | None: @property def tail(self) -> islice: - """Tail od the dependency. + """Tail of the dependency. The `islice` object is sufficient for iteration or testing membership (`in`). """ diff --git a/src/griffe/cli.py b/src/griffe/cli.py index bb195408..b2a4614a 100644 --- a/src/griffe/cli.py +++ b/src/griffe/cli.py @@ -19,6 +19,8 @@ import os import sys from datetime import datetime, timezone +from importlib.metadata import PackageNotFoundError +from importlib.metadata import version as get_dist_version from pathlib import Path from typing import IO, TYPE_CHECKING, Any, Callable, Sequence @@ -42,6 +44,13 @@ logger = get_logger(__name__) +def _get_griffe_version() -> str: + try: + return get_dist_version("griffe") + except PackageNotFoundError: + return "0.0.0" + + def _print_data(data: str, output_file: str | IO | None) -> None: if isinstance(output_file, str): with open(output_file, "w") as fd: @@ -122,6 +131,7 @@ def get_parser() -> argparse.ArgumentParser: global_options = parser.add_argument_group(title="Global options") global_options.add_argument("-h", "--help", action="help", help=main_help) + global_options.add_argument("-V", "--version", action="version", version="%(prog)s " + _get_griffe_version()) def add_common_options(subparser: argparse.ArgumentParser) -> None: common_options = subparser.add_argument_group(title="Common options") diff --git a/src/griffe/mixins.py b/src/griffe/mixins.py index a56e1d2b..42eb30ae 100644 --- a/src/griffe/mixins.py +++ b/src/griffe/mixins.py @@ -247,7 +247,7 @@ def as_json(self, *, full: bool = False, **kwargs: Any) -> str: **kwargs: Additional serialization options passed to encoder. Returns: - A string. + A JSON string. """ from griffe.encoders import JSONEncoder # avoid circular import diff --git a/tests/test_inspector.py b/tests/test_inspector.py index f10aba4c..cd603fae 100644 --- a/tests/test_inspector.py +++ b/tests/test_inspector.py @@ -49,7 +49,7 @@ def test_missing_dependency() -> None: with temporary_pypackage("package", ["module.py"]) as tmp_package: filepath = Path(tmp_package.path, "module.py") filepath.write_text("import missing") - with pytest.raises(ImportError): # noqa: PT012,SIM117 + with pytest.raises(ImportError): # noqa: SIM117 with suppress(ModuleNotFoundError): inspect("package.module", filepath=filepath, import_paths=[tmp_package.tmpdir])