Skip to content

Commit

Permalink
--version points to git hash
Browse files Browse the repository at this point in the history
Today ramalama just share version 0.5.5 (as example) but
don't tell users and developer which commit it's using.

Resolves: #754
Signed-off-by: Douglas Schilling Landgraf <[email protected]>
  • Loading branch information
dougsland committed Feb 6, 2025
1 parent 1ab1908 commit 042a3eb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
25 changes: 24 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,29 @@ check_platform() {
return 0
}

setup_version_file() {
local config_dir="$HOME/.config/ramalama"
local version_file="$config_dir/version"

# Ensure ~/.config/ramalama/ exists
mkdir -p "$config_dir"

version="0.0.0"
# Try to get version from Git
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
version=$(git describe --tags --long --always)
# Format version properly (strip 'g' from commit hash)
if [[ "$version" =~ ([0-9]+\.[0-9]+\.[0-9]+)-([0-9]+)-g([a-f0-9]+) ]]; then
version="${BASH_REMATCH[1]}.dev${BASH_REMATCH[2]}+${BASH_REMATCH[3]}"
fi
fi

# Save version to file
echo "$version" > "$version_file"

echo "Saved version: $version in $version_file"
}

setup_ramalama() {
local binfile="ramalama"
local from_file="${binfile}"
Expand Down Expand Up @@ -181,7 +204,7 @@ main() {
trap cleanup EXIT

setup_ramalama "$bindir"
setup_version_file
}

main "$@"

25 changes: 14 additions & 11 deletions ramalama/version.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import importlib.metadata

"""Version of RamaLamaPy."""
import os

CONFIG_DIR = os.path.expanduser("~/.config/ramalama")
VERSION_FILE = os.path.join(CONFIG_DIR, "version")

def version():
try:
return importlib.metadata.version("ramalama")
except importlib.metadata.PackageNotFoundError:
return "0"

return "0"
"""Reads the version from ~/.config/ramalama/version."""
if os.path.exists(VERSION_FILE):
try:
with open(VERSION_FILE, "r") as f:
return f.read().strip()
except (IOError, OSError) as e:
return f"Error reading version file: {VERSION_FILE}. Ensure you have the correct permissions. Details: {e}"

return f"cannot be detected, see if exists {VERSION_FILE}. Please run sudo ./install.sh"

def print_version(args):
print("ramalama version %s" % version())
def print_version(args=None):
"""Prints the current version of the package."""
print(f"ramalama version {version()}")

0 comments on commit 042a3eb

Please sign in to comment.