Skip to content

Commit

Permalink
Add version flag to CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
pkalita-lbl committed Jul 11, 2024
1 parent fbea99f commit 31e25e7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "gocam"
version = "0.1.0"
version = "0.0.0"
description = "GO CAM Data Model (Python)"
authors = ["The Gene Ontology Consortium <[email protected]>"]
license = "BSD-3"
Expand Down
1 change: 1 addition & 0 deletions src/gocam/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from gocam._version import __version__
2 changes: 1 addition & 1 deletion src/gocam/_version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from importlib.metadata import version, PackageNotFoundError

try:
__version__ = version(__name__)
__version__ = version(__package__)
except PackageNotFoundError:
# package not installed
__version__ = "0.0.0"
2 changes: 2 additions & 0 deletions src/gocam/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import click
import yaml

from gocam import __version__
from gocam.translation import MinervaWrapper


Expand All @@ -17,6 +18,7 @@
show_default=True,
help="If set then show full stacktrace on error",
)
@click.version_option(__version__)
def cli(verbose: int, quiet: bool, stacktrace: bool):
"""A CLI for interacting with GO-CAMs."""
if not stacktrace:
Expand Down
9 changes: 8 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import yaml
from click.testing import CliRunner

from gocam.cli import fetch
from gocam import __version__
from gocam.cli import fetch, cli
from tests import INPUT_DIR


Expand Down Expand Up @@ -37,3 +38,9 @@ def test_fetch_json(runner, api_mock):

parsed_output = json.loads(result.output)
assert parsed_output["id"] == "gomodel:5b91dbd100002057"


def test_version(runner):
result = runner.invoke(cli, ["--version"])
assert result.exit_code == 0
assert __version__ in result.output

0 comments on commit 31e25e7

Please sign in to comment.