Skip to content

Commit

Permalink
add version generated to not rely on paths
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasht86 committed Nov 18, 2024
1 parent 220724f commit 5aef1ee
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 31 deletions.
2 changes: 1 addition & 1 deletion vespacli/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]"
Expand Down
6 changes: 6 additions & 0 deletions vespacli/utils/update_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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}")


Expand Down
32 changes: 2 additions & 30 deletions vespacli/vespacli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -67,6 +42,3 @@ def run_vespa_cli():
full_cmd = [binary_path, *args]
_result = subprocess.run(full_cmd)
return


__version__ = vespa_version
2 changes: 2 additions & 0 deletions vespacli/vespacli/_version_generated.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This file is auto-generated by utils/update_version.py
__version__ = "8.0.dev"

0 comments on commit 5aef1ee

Please sign in to comment.