From 2007f65b295be24b2c6e12055bf695823df1fd00 Mon Sep 17 00:00:00 2001 From: Keith Gaughan Date: Sun, 21 Dec 2025 17:36:15 +0000 Subject: [PATCH] Lean on hatch-vcs for managing the package version --- .github/workflows/release.yml | 18 ------------------ .gitignore | 2 ++ pyproject.toml | 10 ++++++++-- sqlit/__init__.py | 24 +++++------------------- uv.lock | 1 - 5 files changed, 15 insertions(+), 40 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e48f4d0a..1cd849a0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -35,29 +35,11 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Extract version from tag - id: version - run: | - if [ -n "${{ github.event.inputs.version }}" ]; then - echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT - else - # Strip the 'v' prefix from the tag - echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT - fi - - name: Set up Python uses: actions/setup-python@v5 with: python-version: "3.12" - - name: Update version in pyproject.toml - run: | - VERSION=${{ steps.version.outputs.VERSION }} - echo "Setting version to $VERSION" - sed -i "s/^version = .*/version = \"$VERSION\"/" pyproject.toml - echo "Updated pyproject.toml:" - grep "^version" pyproject.toml - - name: Install build tools run: python -m pip install --upgrade build diff --git a/.gitignore b/.gitignore index c73e78a5..7e189998 100644 --- a/.gitignore +++ b/.gitignore @@ -47,6 +47,8 @@ sqlit-notifications/ # Integration test artifacts tests/integration/python_packages/artifacts/ +sqlit/_version.py + # Local assets (except logo for README) assets/* !assets/favorites/ diff --git a/pyproject.toml b/pyproject.toml index f20ed28a..b811a887 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,9 @@ [build-system] -requires = ["hatchling"] +requires = ["hatchling", "hatch-vcs"] build-backend = "hatchling.build" [project] name = "sqlit-tui" -version = "0.5.1" description = "A terminal UI for SQL Server, PostgreSQL, MySQL, SQLite, Oracle, and more" readme = "README.md" license = "MIT" @@ -33,6 +32,7 @@ dependencies = [ "keyring>=24.0.0", "docker>=7.0.0", # Docker container auto-detection (lazy loaded) ] +dynamic = ["version"] [project.optional-dependencies] all = [ @@ -86,6 +86,12 @@ dev = [ "pre-commit>=3.0", ] +[tool.hatch.version] +source = "vcs" + +[tool.hatch.build.hooks.vcs] +version-file = "sqlit/_version.py" + [tool.ruff] target-version = "py310" line-length = 120 diff --git a/sqlit/__init__.py b/sqlit/__init__.py index b1db33a6..2c50d19f 100644 --- a/sqlit/__init__.py +++ b/sqlit/__init__.py @@ -12,6 +12,11 @@ "ConnectionConfig", ] +try: + from ._version import __version__ +except ImportError: + __version__ = "0.0.0.dev" + if TYPE_CHECKING: from .app import SSMSTUI from .cli import main @@ -19,27 +24,8 @@ from importlib.metadata import PackageNotFoundError # noqa: F401 -_VERSION_CACHE: str | None = None - - -def _get_version() -> str: - global _VERSION_CACHE - if _VERSION_CACHE is not None: - return _VERSION_CACHE - try: - from importlib.metadata import PackageNotFoundError, version - - _VERSION_CACHE = version("sqlit-tui") - except PackageNotFoundError: - # Package not installed (development mode without editable install) - _VERSION_CACHE = "0.0.0.dev" - return _VERSION_CACHE - - def __getattr__(name: str) -> Any: """Lazy import for heavy modules to keep package import side-effect free.""" - if name == "__version__": - return _get_version() if name == "main": from .cli import main diff --git a/uv.lock b/uv.lock index d3a67d32..b5c7d16f 100644 --- a/uv.lock +++ b/uv.lock @@ -2959,7 +2959,6 @@ wheels = [ [[package]] name = "sqlit-tui" -version = "0.5.1" source = { editable = "." } dependencies = [ { name = "docker" },