diff --git a/.gitignore b/.gitignore index 2ae6d11..46a9883 100644 --- a/.gitignore +++ b/.gitignore @@ -156,3 +156,5 @@ cython_debug/ # PyCharm .idea/ + +src/tidocs/VERSION diff --git a/pyproject.toml b/pyproject.toml index da715cb..e8e4cee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,3 +37,4 @@ includes = ["src/tidocs/"] [tool.pdm.version] source = "scm" +write_to = "tidocs/VERSION" diff --git a/src/tidocs/__version__.py b/src/tidocs/__version__.py new file mode 100644 index 0000000..07e4f88 --- /dev/null +++ b/src/tidocs/__version__.py @@ -0,0 +1,14 @@ +import importlib.metadata +import importlib.resources + + +def read_version() -> str: + try: + return importlib.metadata.version(__package__ or "tidocs") + except importlib.metadata.PackageNotFoundError: + return ( + importlib.resources.files("tidocs").joinpath("VERSION").read_text().strip() + ) + + +__version__ = read_version() diff --git a/src/tidocs/cli.py b/src/tidocs/cli.py index 4d79c95..e00b54f 100644 --- a/src/tidocs/cli.py +++ b/src/tidocs/cli.py @@ -8,6 +8,7 @@ from hypercorn.config import Config from tidocs.pandoc_wrapper import Pandoc +from tidocs.__version__ import __version__ APPS = {"merge": "Merge Release Notes"} @@ -38,7 +39,7 @@ def launch_marimo_app(appname: str, host: str, port: int) -> None: @click.command(no_args_is_help=True) -@click.version_option(version="1.0.6") +@click.version_option(version=__version__) @click.argument("appname", type=click.Choice(list(APPS.keys())), required=True) @click.option( "--host",