diff --git a/.gitignore b/.gitignore index 550f1cd..88f69e2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ data/tension_chart_13934.pdf data/*.png docs/api/ panel/app.html +_version.py uv.lock diff --git a/docs/dev.md b/docs/dev.md index a1e76c1..6e067bf 100644 --- a/docs/dev.md +++ b/docs/dev.md @@ -23,3 +23,18 @@ Build the docs: ```sh uv run sphinx-build docs docs/_build/html ``` + +Check the version: + +```sh +uv run stringcalc --version +``` + +After adding a new annotated version tag, +you may need to touch one of the files +in order for uv/hatch to detect that a rebuild is needed, +or use: + +```sh +uv run --reinstall-package stringcalc stringcalc --version +``` diff --git a/panel/app.py b/panel/app.py index 9088310..7961cd9 100644 --- a/panel/app.py +++ b/panel/app.py @@ -6,14 +6,11 @@ from stringcalc.frets import distances, length_from_distance from stringcalc.tension import DENSITY_LB_IN, gauge, load_data, suggest_gauge -try: - from stringcalc.util import get_version -except ImportError: - def get_version(*, git: bool = True) -> str: - import stringcalc +def get_version() -> str: + import stringcalc - return getattr(stringcalc, "__version__", "?") + return getattr(stringcalc, "__version__", "?") WIDTH = 450 diff --git a/pyproject.toml b/pyproject.toml index f118fa2..a78a252 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [build-system] -requires = ["flit_core >=3.2,<4"] -build-backend = "flit_core.buildapi" +requires = ["hatchling", "hatch-vcs"] +build-backend = "hatchling.build" [project] name = "stringcalc" @@ -59,8 +59,25 @@ panel = [ [project.scripts] stringcalc = "stringcalc.cli:app" -[tool.flit.sdist] -exclude = ["data/", ".github/", "panel/", ".gitignore"] +[tool.hatch.version] +source = "vcs" + +[tool.hatch.build.hooks.vcs] +version-file = "stringcalc/_version.py" + +[tool.hatch.build.targets.sdist] +exclude = [ + ".flake8", + ".gitignore", + ".pre-commit-config.yaml", + ".readthedocs.yaml", + ".github/", + "data/", + "panel/", +] + +[tool.hatch.build.targets.wheel] +only-packages = true [tool.black] line-length = 100 diff --git a/stringcalc/__init__.py b/stringcalc/__init__.py index 43bd200..7d8d590 100644 --- a/stringcalc/__init__.py +++ b/stringcalc/__init__.py @@ -2,4 +2,7 @@ Calculations for instrument strings """ -__version__ = "0.1.0.dev18" +try: + from ._version import __version__ +except ImportError: + __version__ = "0.0.0" diff --git a/stringcalc/cli.py b/stringcalc/cli.py index 600e179..272a136 100644 --- a/stringcalc/cli.py +++ b/stringcalc/cli.py @@ -99,18 +99,15 @@ def inner(*args, **kwargs): def _version_callback(show: bool): if show: - import subprocess - from . import __version__ v = f"[rgb(184,115,51)]stringcalc[/] [bold blue]{__version__}[/]" try: - cmd = ["git", "-C", HERE.as_posix(), "rev-parse", "--verify", "--short", "HEAD"] - cp = subprocess.run(cmd, text=True, capture_output=True, check=True) - except Exception: + i = v.index("+") + except ValueError: pass else: - v += f" [rgb(100,100,100)]({cp.stdout.strip()})[/]" + v = v[:i] + "[rgb(100,100,100)]" + v[i:] + "[/]" console.print(v, highlight=False) diff --git a/stringcalc/data/daddario-stp.csv b/stringcalc/data/daddario-stp.csv index 36e6b8d..33666e5 100644 --- a/stringcalc/data/daddario-stp.csv +++ b/stringcalc/data/daddario-stp.csv @@ -588,12 +588,14 @@ XTNW042,0.00031405,0.042,Electric Guitar,Nickel Plated Steel,XTNW XTNW046,0.00036969,0.046,Electric Guitar,Nickel Plated Steel,XTNW XTNW049,0.00041459,0.049,Electric Guitar,Nickel Plated Steel,XTNW XTNW052,0.00046223,0.052,Electric Guitar,Nickel Plated Steel,XTNW +XTNW059,0.00061817,0.059,Electric Guitar,Nickel Plated Steel,XTNW XTPB022,9.7982e-05,0.022,Acoustic Guitar,Phosphor Bronze,XTPB XTPB023,0.0001078,0.023,Acoustic Guitar,Phosphor Bronze,XTPB XTPB024,0.00011612,0.024,Acoustic Guitar,Phosphor Bronze,XTPB XTPB025,0.00012678,0.025,Acoustic Guitar,Phosphor Bronze,XTPB XTPB026,0.0001358,0.026,Acoustic Guitar,Phosphor Bronze,XTPB XTPB027,0.00014707,0.027,Acoustic Guitar,Phosphor Bronze,XTPB +XTPB028,0.00015901,0.028,Acoustic Guitar,Phosphor Bronze,XTPB XTPB029,0.00017107,0.029,Acoustic Guitar,Phosphor Bronze,XTPB XTPB032,0.00020607,0.032,Acoustic Guitar,Phosphor Bronze,XTPB XTPB035,0.00024692,0.035,Acoustic Guitar,Phosphor Bronze,XTPB diff --git a/stringcalc/util.py b/stringcalc/util.py deleted file mode 100644 index 3f7955e..0000000 --- a/stringcalc/util.py +++ /dev/null @@ -1,32 +0,0 @@ -from __future__ import annotations - - -def get_version(*, git: bool = True) -> str: - """ - Parameters - ---------- - git - Include the short version of the Git hash in the returned version string. - """ - from . import __version__ - - ver = __version__ - if git: - import subprocess - import warnings - from pathlib import Path - - repo = Path(__file__).parent.parent - - try: - cmd = ["git", "-C", repo.as_posix(), "rev-parse", "--verify", "--short", "HEAD"] - cp = subprocess.run(cmd, text=True, capture_output=True, check=True) - except Exception: - warnings.warn(f"Could not get Git hash using command `{' '.join(cmd)}`.") - hsh = "" - else: - hsh = f" ({cp.stdout.strip()})" - - return f"{ver}{hsh}" - else: - return ver