Skip to content

Commit 865ac0a

Browse files
authored
Lean on hatch-vcs for managing the package version (#28)
1 parent 37ba8d9 commit 865ac0a

File tree

5 files changed

+15
-40
lines changed

5 files changed

+15
-40
lines changed

.github/workflows/release.yml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,11 @@ jobs:
3535
steps:
3636
- uses: actions/checkout@v4
3737

38-
- name: Extract version from tag
39-
id: version
40-
run: |
41-
if [ -n "${{ github.event.inputs.version }}" ]; then
42-
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
43-
else
44-
# Strip the 'v' prefix from the tag
45-
echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
46-
fi
47-
4838
- name: Set up Python
4939
uses: actions/setup-python@v5
5040
with:
5141
python-version: "3.12"
5242

53-
- name: Update version in pyproject.toml
54-
run: |
55-
VERSION=${{ steps.version.outputs.VERSION }}
56-
echo "Setting version to $VERSION"
57-
sed -i "s/^version = .*/version = \"$VERSION\"/" pyproject.toml
58-
echo "Updated pyproject.toml:"
59-
grep "^version" pyproject.toml
60-
6143
- name: Install build tools
6244
run: python -m pip install --upgrade build
6345

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ sqlit-notifications/
4747
# Integration test artifacts
4848
tests/integration/python_packages/artifacts/
4949

50+
sqlit/_version.py
51+
5052
# Local assets (except logo for README)
5153
assets/*
5254
!assets/favorites/

pyproject.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
[build-system]
2-
requires = ["hatchling"]
2+
requires = ["hatchling", "hatch-vcs"]
33
build-backend = "hatchling.build"
44

55
[project]
66
name = "sqlit-tui"
7-
version = "0.5.1"
87
description = "A terminal UI for SQL Server, PostgreSQL, MySQL, SQLite, Oracle, and more"
98
readme = "README.md"
109
license = "MIT"
@@ -33,6 +32,7 @@ dependencies = [
3332
"keyring>=24.0.0",
3433
"docker>=7.0.0", # Docker container auto-detection (lazy loaded)
3534
]
35+
dynamic = ["version"]
3636

3737
[project.optional-dependencies]
3838
all = [
@@ -86,6 +86,12 @@ dev = [
8686
"pre-commit>=3.0",
8787
]
8888

89+
[tool.hatch.version]
90+
source = "vcs"
91+
92+
[tool.hatch.build.hooks.vcs]
93+
version-file = "sqlit/_version.py"
94+
8995
[tool.ruff]
9096
target-version = "py310"
9197
line-length = 120

sqlit/__init__.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,20 @@
1212
"ConnectionConfig",
1313
]
1414

15+
try:
16+
from ._version import __version__
17+
except ImportError:
18+
__version__ = "0.0.0.dev"
19+
1520
if TYPE_CHECKING:
1621
from .app import SSMSTUI
1722
from .cli import main
1823
from .config import AuthType, ConnectionConfig
1924
from importlib.metadata import PackageNotFoundError # noqa: F401
2025

2126

22-
_VERSION_CACHE: str | None = None
23-
24-
25-
def _get_version() -> str:
26-
global _VERSION_CACHE
27-
if _VERSION_CACHE is not None:
28-
return _VERSION_CACHE
29-
try:
30-
from importlib.metadata import PackageNotFoundError, version
31-
32-
_VERSION_CACHE = version("sqlit-tui")
33-
except PackageNotFoundError:
34-
# Package not installed (development mode without editable install)
35-
_VERSION_CACHE = "0.0.0.dev"
36-
return _VERSION_CACHE
37-
38-
3927
def __getattr__(name: str) -> Any:
4028
"""Lazy import for heavy modules to keep package import side-effect free."""
41-
if name == "__version__":
42-
return _get_version()
4329
if name == "main":
4430
from .cli import main
4531

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)