From 5aef1eee1c5728e637a27959f0a5cff1d1e4e939 Mon Sep 17 00:00:00 2001 From: thomasht86 Date: Mon, 18 Nov 2024 08:43:12 +0100 Subject: [PATCH] add version generated to not rely on paths --- vespacli/pyproject.toml | 2 +- vespacli/utils/update_version.py | 6 +++++ vespacli/vespacli/__init__.py | 32 ++----------------------- vespacli/vespacli/_version_generated.py | 2 ++ 4 files changed, 11 insertions(+), 31 deletions(-) create mode 100644 vespacli/vespacli/_version_generated.py diff --git a/vespacli/pyproject.toml b/vespacli/pyproject.toml index 21dedd74..4441dc03 100644 --- a/vespacli/pyproject.toml +++ b/vespacli/pyproject.toml @@ -8,7 +8,7 @@ description = "A Python wrapper for Vespa CLI tools, supporting multiple platfor keywords = [ "vespa", "cli", "wrapper",] name = "vespacli" readme = "README.md" -version = "8.dev" +version = "8.0.dev" [[project.authors]] name = "Thomas Thoresen" email = "thomas@vespa.ai" diff --git a/vespacli/utils/update_version.py b/vespacli/utils/update_version.py index 4a522d72..015b3e3f 100644 --- a/vespacli/utils/update_version.py +++ b/vespacli/utils/update_version.py @@ -6,6 +6,7 @@ import argparse PYPROJECT_TOML_PATH = Path(__file__).parent.parent / "pyproject.toml" +VERSION_FILE_PATH = Path(__file__).parent.parent / "vespacli" / "_version_generated.py" def update_version(new_version: str): @@ -16,6 +17,11 @@ def update_version(new_version: str): with open("pyproject.toml", "w") as f: toml.dump(data, f) + # Also update version in vespacli/_version_generated.py + with open(VERSION_FILE_PATH, "w") as f: + # Write comment about auto-generation + f.write("# This file is auto-generated by utils/update_version.py\n") + f.write(f'__version__ = "{new_version}"\n') print(f"Updated version to {new_version}") diff --git a/vespacli/vespacli/__init__.py b/vespacli/vespacli/__init__.py index dbb14383..cd3c1e00 100644 --- a/vespacli/vespacli/__init__.py +++ b/vespacli/vespacli/__init__.py @@ -2,34 +2,9 @@ import sys import platform import subprocess -import re +from ._version_generated import __version__ - -def get_version(): - # Get binary path first - base_path = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) - go_binaries_path = os.path.join(base_path, "vespacli", "go-binaries") - - # List directories and find vespa-cli directory - try: - dirs = os.listdir(go_binaries_path) - version_dirs = [d for d in dirs if d.startswith("vespa-cli_")] - if not version_dirs: - raise FileNotFoundError("No vespa-cli directory found") - - # Extract version from directory name (format: vespa-cli_X.YYY.Z_os_arch) - version = version_dirs[0].split("_")[1] - - # Validate version format - if not re.match(r"^\d+\.\d{3}\.\d{1,3}$", version): - raise ValueError(f"Invalid version format: {version}") - - return version - except (FileNotFoundError, IndexError): - raise FileNotFoundError("Cannot determine version from binary path") - - -vespa_version = get_version() +vespa_version = __version__ def get_binary_path(): @@ -67,6 +42,3 @@ def run_vespa_cli(): full_cmd = [binary_path, *args] _result = subprocess.run(full_cmd) return - - -__version__ = vespa_version diff --git a/vespacli/vespacli/_version_generated.py b/vespacli/vespacli/_version_generated.py new file mode 100644 index 00000000..321462aa --- /dev/null +++ b/vespacli/vespacli/_version_generated.py @@ -0,0 +1,2 @@ +# This file is auto-generated by utils/update_version.py +__version__ = "8.0.dev"