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

Use setup scm #194

Merged
merged 3 commits into from
Nov 25, 2024
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion litecli/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
__version__ = "1.13.0"
import importlib.metadata

__version__ = importlib.metadata.version("litecli")
15 changes: 8 additions & 7 deletions litecli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@click.version_option() will probably do what you want. It uses importlib and assumes that the top-level name is your project name.

Impl at https://github.com/pallets/click/blob/fde47b4b4f978f179b9dff34583cb2b99021f482/src/click/decorators.py#L422

@click.option("-D", "--database", "dbname", help="Database to use.")
@click.option(
"-R",
Expand Down Expand Up @@ -859,7 +866,6 @@ def get_last_query(self):
def cli(
database,
dbname,
version,
prompt,
logfile,
auto_vertical_output,
Expand All @@ -876,11 +882,6 @@ def cli(
- litecli lite_database

"""

if version:
print("Version:", __version__)
sys.exit(0)

litecli = LiteCli(
prompt=prompt,
logfile=logfile,
Expand Down
11 changes: 3 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]"}
]
license = { text = "BSD" }
authors = [{ name = "dbcli", email = "[email protected]" }]
urls = { "homepage" = "https://github.com/dbcli/litecli" }
dependencies = [
"cli-helpers[styles]>=2.2.1",
Expand All @@ -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]
Expand All @@ -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
Loading