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: ...@@ -165,16 +165,23 @@ except:
fi 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 # Function to check if package was upgraded
check_package_upgrade() { check_package_upgrade() {
local INSTALLED_VERSION_FILE="$VENV_DIR/.aisbf_version" 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="" local SAVED_VERSION=""
if [ -f "$INSTALLED_VERSION_FILE" ]; then if [ -f "$INSTALLED_VERSION_FILE" ]; then
SAVED_VERSION=$(cat "$INSTALLED_VERSION_FILE") SAVED_VERSION=$(cat "$INSTALLED_VERSION_FILE")
fi fi
if [ "$SAVED_VERSION" != "$CURRENT_VERSION" ]; then if [ "$SAVED_VERSION" != "$CURRENT_VERSION" ]; then
return 0 # Needs update return 0 # Needs update
fi fi
...@@ -253,7 +260,7 @@ ensure_venv() { ...@@ -253,7 +260,7 @@ ensure_venv() {
fi fi
[ "$DEBUG" = "true" ] && echo "=== DEBUG: Saving version info ===" [ "$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 else
[ "$DEBUG" = "true" ] && echo "=== DEBUG: Venv already exists, checking for upgrades ===" [ "$DEBUG" = "true" ] && echo "=== DEBUG: Venv already exists, checking for upgrades ==="
...@@ -279,7 +286,7 @@ ensure_venv() { ...@@ -279,7 +286,7 @@ ensure_venv() {
[ "$DEBUG" = "true" ] && echo "=== DEBUG: Force reinstalling uvicorn ===" [ "$DEBUG" = "true" ] && echo "=== DEBUG: Force reinstalling uvicorn ==="
"$VENV_DIR/bin/pip" install --force-reinstall uvicorn "$VENV_DIR/bin/pip" install --force-reinstall uvicorn
fi 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" echo "Virtual environment updated successfully"
else else
[ "$DEBUG" = "true" ] && echo "=== DEBUG: No package upgrade detected ===" [ "$DEBUG" = "true" ] && echo "=== DEBUG: No package upgrade detected ==="
......
...@@ -165,16 +165,23 @@ except: ...@@ -165,16 +165,23 @@ except:
fi 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 # Function to check if package was upgraded
check_package_upgrade() { check_package_upgrade() {
local INSTALLED_VERSION_FILE="$VENV_DIR/.aisbf_version" 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="" local SAVED_VERSION=""
if [ -f "$INSTALLED_VERSION_FILE" ]; then if [ -f "$INSTALLED_VERSION_FILE" ]; then
SAVED_VERSION=$(cat "$INSTALLED_VERSION_FILE") SAVED_VERSION=$(cat "$INSTALLED_VERSION_FILE")
fi fi
if [ "$SAVED_VERSION" != "$CURRENT_VERSION" ]; then if [ "$SAVED_VERSION" != "$CURRENT_VERSION" ]; then
return 0 # Needs update return 0 # Needs update
fi fi
...@@ -253,7 +260,7 @@ ensure_venv() { ...@@ -253,7 +260,7 @@ ensure_venv() {
fi fi
[ "$DEBUG" = "true" ] && echo "=== DEBUG: Saving version info ===" [ "$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 else
[ "$DEBUG" = "true" ] && echo "=== DEBUG: Venv already exists, checking for upgrades ===" [ "$DEBUG" = "true" ] && echo "=== DEBUG: Venv already exists, checking for upgrades ==="
...@@ -279,7 +286,7 @@ ensure_venv() { ...@@ -279,7 +286,7 @@ ensure_venv() {
[ "$DEBUG" = "true" ] && echo "=== DEBUG: Force reinstalling uvicorn ===" [ "$DEBUG" = "true" ] && echo "=== DEBUG: Force reinstalling uvicorn ==="
"$VENV_DIR/bin/pip" install --force-reinstall uvicorn "$VENV_DIR/bin/pip" install --force-reinstall uvicorn
fi 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" echo "Virtual environment updated successfully"
else else
[ "$DEBUG" = "true" ] && echo "=== DEBUG: No package upgrade detected ===" [ "$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