Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add --version and -V cli flag. #187

Merged
merged 4 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/griffe/c3linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
"""
Expand Down
10 changes: 10 additions & 0 deletions src/griffe/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion src/griffe/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/test_inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down
Loading