Skip to content

Commit 1a75a1f

Browse files
committed
add version argument
1 parent e320793 commit 1a75a1f

5 files changed

Lines changed: 42 additions & 8 deletions

File tree

pyproject.toml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "ical2jcal"
3-
version = "0.0.0"
3+
dynamic = ["version"]
44
description = "Convert between iCalendar and jCalendar formats."
55
authors = [
66
{ name = "Nicco Kunzmann", email = "niccokunzmann@rambler.ru" }]
@@ -72,13 +72,14 @@ licenses = [
7272
]
7373

7474
[build-system]
75-
requires = ["uv_build>=0.9.0,<0.10.0"]
76-
build-backend = "uv_build"
75+
requires = ["hatchling", "uv-dynamic-versioning"]
76+
build-backend = "hatchling.build"
7777

78-
# For non-src directory projects, explicitly set top level model name:
79-
#[tool.uv.build-backend]
80-
#module-name = "my-app"
81-
#module-root = ""
78+
[tool.hatch.version]
79+
source = "uv-dynamic-versioning"
80+
81+
[tool.uv-dynamic-versioning]
82+
fallback-version = "0.0.0"
8283

8384
[tool.uv]
8485
default-groups = "all"

src/ical2jcal/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
11
"""Command line package for converting iCalendar files to jCal files."""
2+
3+
import importlib.metadata
4+
5+
try:
6+
__version__ = importlib.metadata.version(__name__)
7+
except importlib.metadata.PackageNotFoundError:
8+
__version__ = "0.0.0" # Fallback for development mode

src/ical2jcal/cli.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,27 @@
77
from rich.console import Console
88
import typer
99

10+
console = Console()
1011
err_console = Console(stderr=True)
1112
ical2jcal = typer.Typer(add_completion=False)
1213

1314

15+
def version_callback(value: bool):
16+
if value:
17+
import ical2jcal
18+
19+
console.print(f"{ical2jcal.__name__}: {ical2jcal.__version__}")
20+
raise typer.Exit()
21+
22+
1423
@ical2jcal.command()
1524
def convert_to_jcal(
1625
ics_path: Annotated[typer.FileText, typer.Argument(exists=True)],
1726
jcal_path: Annotated[typer.FileTextWrite, typer.Argument()],
1827
pretty: Annotated[bool, typer.Option("--pretty", "-p", help="Pretty print json")] = False,
28+
version: Annotated[
29+
bool | None, typer.Option("--version", callback=version_callback, help="Print version")
30+
] = None,
1931
) -> None:
2032
"""Convert an ics file to a jcal file.
2133
@@ -44,6 +56,9 @@ def convert_to_jcal(
4456
def convert_to_ical(
4557
jcal_path: Annotated[typer.FileText, typer.Argument(exists=True)],
4658
ics_path: Annotated[typer.FileBinaryWrite, typer.Argument()],
59+
version: Annotated[
60+
bool | None, typer.Option("--version", callback=version_callback, help="Print version")
61+
] = None,
4762
) -> None:
4863
"""Convert an jcal file to an ics file.
4964

tests/test_version.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from ical2jcal import cli, __version__
2+
import pytest
3+
from typer.testing import CliRunner
4+
5+
6+
@pytest.mark.parametrize("endpoint", [cli.ical2jcal, cli.jcal2ical])
7+
def test_version(endpoint):
8+
runner = CliRunner()
9+
result = runner.invoke(endpoint, ["--version"])
10+
assert result.exit_code == 0, result.output
11+
assert "ical2jcal" in result.stdout
12+
assert __version__ in result.stdout

uv.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)