diff --git a/CHANGELOG.md b/CHANGELOG.md index dece75f..27c79cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 1.13.1 - 2024-11-24 + +### Internal + +* Read the version from the git tag using setuptools-scm + ## 1.13.0 - 2024-11-23 ### Features diff --git a/litecli/__init__.py b/litecli/__init__.py index 9a34ccc..b3ce20e 100644 --- a/litecli/__init__.py +++ b/litecli/__init__.py @@ -1 +1,3 @@ -__version__ = "1.13.0" +import importlib.metadata + +__version__ = importlib.metadata.version("litecli") diff --git a/litecli/main.py b/litecli/main.py index e3e6cc7..e10212c 100644 --- a/litecli/main.py +++ b/litecli/main.py @@ -825,8 +825,15 @@ def get_last_query(self): return self.query_history[-1][0] if self.query_history else None +def version_callback(ctx: click.Context, param: click.Parameter, value: bool) -> None: + if not value or ctx.resilient_parsing: + return + click.echo(f"Version: {__version__}", color=ctx.color) + ctx.exit() + + @click.command() -@click.option("-V", "--version", is_flag=True, help="Output litecli's version.") +@click.option("-V", "--version", callback=version_callback, expose_value=False, is_eager=True, is_flag=True, help="Show version.") @click.option("-D", "--database", "dbname", help="Database to use.") @click.option( "-R", @@ -859,7 +866,6 @@ def get_last_query(self): def cli( database, dbname, - version, prompt, logfile, auto_vertical_output, @@ -876,11 +882,6 @@ def cli( - litecli lite_database """ - - if version: - print("Version:", __version__) - sys.exit(0) - litecli = LiteCli( prompt=prompt, logfile=logfile, diff --git a/pyproject.toml b/pyproject.toml index 55dc144..6ee919d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,10 +4,8 @@ dynamic = ["version"] description = "CLI for SQLite Databases with auto-completion and syntax highlighting." readme = "README.md" requires-python = ">=3.7" -license = {text = "BSD"} -authors = [ - {name = "dbcli", email = "litecli-users@googlegroups.com"} -] +license = { text = "BSD" } +authors = [{ name = "dbcli", email = "litecli-users@googlegroups.com" }] urls = { "homepage" = "https://github.com/dbcli/litecli" } dependencies = [ "cli-helpers[styles]>=2.2.1", @@ -19,7 +17,7 @@ dependencies = [ ] [build-system] -requires = ["setuptools >= 61.0"] +requires = ["setuptools>=64.0", "setuptools-scm>=8"] build-backend = "setuptools.build_meta" [project.scripts] @@ -42,8 +40,5 @@ exclude = ["screenshots", "tests*"] [tool.setuptools.package-data] litecli = ["liteclirc", "AUTHORS"] -[tool.setuptools.dynamic] -version = {attr = "litecli.__version__"} - [tool.ruff] line-length = 140