fix: use importlib.metadata.version() for version check — avoids import aisbf...

fix: use importlib.metadata.version() for version check — avoids import aisbf crash before config is set up
parent 5e7a5ca9
......@@ -165,16 +165,23 @@ except:
fi
}
# Return the installed aisbf version without importing the package
# (importing aisbf triggers config loading which may fail before setup completes).
_aisbf_version() {
python3 -c "import importlib.metadata; print(importlib.metadata.version('aisbf'))" 2>/dev/null || echo "unknown"
}
# Function to check if package was upgraded
check_package_upgrade() {
local INSTALLED_VERSION_FILE="$VENV_DIR/.aisbf_version"
local CURRENT_VERSION=$(python3 -c "import aisbf; print(aisbf.__version__)" 2>/dev/null || echo "unknown")
local CURRENT_VERSION
CURRENT_VERSION=$(_aisbf_version)
local SAVED_VERSION=""
if [ -f "$INSTALLED_VERSION_FILE" ]; then
SAVED_VERSION=$(cat "$INSTALLED_VERSION_FILE")
fi
if [ "$SAVED_VERSION" != "$CURRENT_VERSION" ]; then
return 0 # Needs update
fi
......@@ -253,7 +260,7 @@ ensure_venv() {
fi
[ "$DEBUG" = "true" ] && echo "=== DEBUG: Saving version info ==="
python3 -c "import aisbf; print(aisbf.__version__)" > "$VENV_DIR/.aisbf_version" 2>/dev/null || echo "unknown" > "$VENV_DIR/.aisbf_version"
_aisbf_version > "$VENV_DIR/.aisbf_version"
else
[ "$DEBUG" = "true" ] && echo "=== DEBUG: Venv already exists, checking for upgrades ==="
......@@ -279,7 +286,7 @@ ensure_venv() {
[ "$DEBUG" = "true" ] && echo "=== DEBUG: Force reinstalling uvicorn ==="
"$VENV_DIR/bin/pip" install --force-reinstall uvicorn
fi
python3 -c "import aisbf; print(aisbf.__version__)" > "$VENV_DIR/.aisbf_version" 2>/dev/null || echo "unknown" > "$VENV_DIR/.aisbf_version"
_aisbf_version > "$VENV_DIR/.aisbf_version"
echo "Virtual environment updated successfully"
else
[ "$DEBUG" = "true" ] && echo "=== DEBUG: No package upgrade detected ==="
......
......@@ -165,16 +165,23 @@ except:
fi
}
# Return the installed aisbf version without importing the package
# (importing aisbf triggers config loading which may fail before setup completes).
_aisbf_version() {
python3 -c "import importlib.metadata; print(importlib.metadata.version('aisbf'))" 2>/dev/null || echo "unknown"
}
# Function to check if package was upgraded
check_package_upgrade() {
local INSTALLED_VERSION_FILE="$VENV_DIR/.aisbf_version"
local CURRENT_VERSION=$(python3 -c "import aisbf; print(aisbf.__version__)" 2>/dev/null || echo "unknown")
local CURRENT_VERSION
CURRENT_VERSION=$(_aisbf_version)
local SAVED_VERSION=""
if [ -f "$INSTALLED_VERSION_FILE" ]; then
SAVED_VERSION=$(cat "$INSTALLED_VERSION_FILE")
fi
if [ "$SAVED_VERSION" != "$CURRENT_VERSION" ]; then
return 0 # Needs update
fi
......@@ -253,7 +260,7 @@ ensure_venv() {
fi
[ "$DEBUG" = "true" ] && echo "=== DEBUG: Saving version info ==="
python3 -c "import aisbf; print(aisbf.__version__)" > "$VENV_DIR/.aisbf_version" 2>/dev/null || echo "unknown" > "$VENV_DIR/.aisbf_version"
_aisbf_version > "$VENV_DIR/.aisbf_version"
else
[ "$DEBUG" = "true" ] && echo "=== DEBUG: Venv already exists, checking for upgrades ==="
......@@ -279,7 +286,7 @@ ensure_venv() {
[ "$DEBUG" = "true" ] && echo "=== DEBUG: Force reinstalling uvicorn ==="
"$VENV_DIR/bin/pip" install --force-reinstall uvicorn
fi
python3 -c "import aisbf; print(aisbf.__version__)" > "$VENV_DIR/.aisbf_version" 2>/dev/null || echo "unknown" > "$VENV_DIR/.aisbf_version"
_aisbf_version > "$VENV_DIR/.aisbf_version"
echo "Virtual environment updated successfully"
else
[ "$DEBUG" = "true" ] && echo "=== DEBUG: No package upgrade detected ==="
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment