From c04281a0e86291cab1b2645f35fab94814ca9f07 Mon Sep 17 00:00:00 2001 From: Amjith Ramanujam Date: Sun, 24 Nov 2024 18:19:49 -0800 Subject: [PATCH 1/3] Read the version from git tags. --- litecli/__init__.py | 4 +++- litecli/main.py | 15 ++++++++------- pyproject.toml | 11 +++-------- 3 files changed, 14 insertions(+), 16 deletions(-) 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..7a51d44 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) @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 From f8b498b16993c4b32694578c473422fff3b52d80 Mon Sep 17 00:00:00 2001 From: Amjith Ramanujam Date: Sun, 24 Nov 2024 18:21:12 -0800 Subject: [PATCH 2/3] Update changelog. --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) 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 From 79adc64bded7ac3e37a24632386b439e4917b3bf Mon Sep 17 00:00:00 2001 From: Amjith Ramanujam Date: Sun, 24 Nov 2024 18:26:59 -0800 Subject: [PATCH 3/3] Add back the help messaage. --- litecli/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litecli/main.py b/litecli/main.py index 7a51d44..e10212c 100644 --- a/litecli/main.py +++ b/litecli/main.py @@ -833,7 +833,7 @@ def version_callback(ctx: click.Context, param: click.Parameter, value: bool) -> @click.command() -@click.option("-V", "--version", callback=version_callback, expose_value=False, is_eager=True, is_flag=True) +@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",