mirror of
https://github.com/pyMC-dev/pyMC_Repeater.git
synced 2026-08-08 09:52:55 +02:00
Merge pull request #313 from openhop-dev/fix-venv-in-manage
Fix venv in manage
This commit is contained in:
@@ -16,8 +16,8 @@ jobs:
|
||||
docker:
|
||||
if: |
|
||||
github.event_name == 'workflow_dispatch' ||
|
||||
github.repository == 'pyMC-dev/openhop-repeater' ||
|
||||
github.repository == 'yellowcooln/openhop-repeater'
|
||||
github.repository == 'openhop-dev/openhop_repeater' ||
|
||||
github.repository == 'yellowcooln/openhop_repeater'
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
@@ -58,7 +58,7 @@ jobs:
|
||||
run: |
|
||||
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ inputs.image_repository }}" ]; then
|
||||
image_repository="${{ inputs.image_repository }}"
|
||||
elif [ "${{ github.repository }}" = "yellowcooln/openhop-repeater" ]; then
|
||||
elif [ "${{ github.repository }}" = "yellowcooln/openhop_repeater" ]; then
|
||||
image_repository="yellowcooln/openhop-repeater"
|
||||
else
|
||||
image_repository="pymcdev/openhop-repeater"
|
||||
@@ -92,7 +92,7 @@ jobs:
|
||||
cache-to: type=gha,mode=max
|
||||
|
||||
- name: Notify Home Assistant add-on repository
|
||||
if: github.repository == 'pyMC-dev/openhop-repeater'
|
||||
if: github.repository == 'openhop-dev/openhop_repeater'
|
||||
env:
|
||||
DISPATCH_TOKEN: ${{ secrets.HA_ADDON_REPO_DISPATCH_TOKEN }}
|
||||
CHANNEL: ${{ github.ref_name }}
|
||||
|
||||
@@ -90,12 +90,30 @@ migrate_legacy_paths() {
|
||||
|
||||
# Create (or re-create) the dedicated venv for openhop_repeater
|
||||
ensure_venv() {
|
||||
local recreate=0
|
||||
|
||||
if [ ! -x "$VENV_PYTHON" ]; then
|
||||
echo ">>> Creating virtual environment at $VENV_DIR ..."
|
||||
python3 -m venv --system-site-packages "$VENV_DIR"
|
||||
# Upgrade pip inside the venv
|
||||
"$VENV_PIP" install --upgrade pip setuptools wheel >/dev/null 2>&1 || true
|
||||
recreate=1
|
||||
elif ! "$VENV_PYTHON" -c 'import sys; print(sys.executable)' >/dev/null 2>&1; then
|
||||
# Venv python exists but points to a missing interpreter (stale venv).
|
||||
recreate=1
|
||||
elif ! "$VENV_PYTHON" -m pip --version >/dev/null 2>&1; then
|
||||
# Pip script/shebang can break after Python upgrades; treat as stale.
|
||||
recreate=1
|
||||
fi
|
||||
|
||||
if [ "$recreate" -eq 1 ]; then
|
||||
if [ -d "$VENV_DIR" ]; then
|
||||
echo ">>> Rebuilding broken virtual environment at $VENV_DIR ..."
|
||||
rm -rf "$VENV_DIR"
|
||||
else
|
||||
echo ">>> Creating virtual environment at $VENV_DIR ..."
|
||||
fi
|
||||
python3 -m venv --system-site-packages "$VENV_DIR"
|
||||
fi
|
||||
|
||||
# Always use python -m pip so we don't rely on a potentially stale pip wrapper.
|
||||
"$VENV_PYTHON" -m pip install --upgrade pip setuptools wheel >/dev/null 2>&1 || true
|
||||
}
|
||||
|
||||
# Migrate an existing system-pip install into the venv.
|
||||
@@ -567,7 +585,7 @@ fi
|
||||
if [ ! -x "$VENV_PYTHON" ]; then
|
||||
echo "[pymc-do-upgrade] Creating venv at $VENV_DIR ..."
|
||||
python3 -m venv --system-site-packages "$VENV_DIR"
|
||||
"$VENV_PIP" install --upgrade pip setuptools wheel >/dev/null 2>&1 || true
|
||||
"$VENV_PYTHON" -m pip install --upgrade pip setuptools wheel >/dev/null 2>&1 || true
|
||||
fi
|
||||
# ---- Migration: clean up legacy service unit issues ----
|
||||
SVC_UNIT=/etc/systemd/system/openhop-repeater.service
|
||||
@@ -615,10 +633,10 @@ if [ -n "$ARCH_TAG" ]; then
|
||||
PY_TAG=$("$VENV_PYTHON" -c 'import sys; v=f"cp{sys.version_info.major}{sys.version_info.minor}"; print(f"{v}-{v}")' 2>/dev/null || echo "cp311-cp311")
|
||||
WHEEL_BASE="${R2_BASE_URL}/${ARCH_TAG}/${PLATFORM_TAG}/${PY_TAG}"
|
||||
echo "[pymc-do-upgrade] Trying dependencies from R2 wheels..."
|
||||
"$VENV_PIP" install --find-links "${WHEEL_BASE}/index.html" --no-cache-dir "pycryptodome>=3.23.0" "PyNaCl>=1.5.0" cffi "pyyaml>=6.0.0" 2>/dev/null || true
|
||||
"$VENV_PYTHON" -m pip install --find-links "${WHEEL_BASE}/index.html" --no-cache-dir "pycryptodome>=3.23.0" "PyNaCl>=1.5.0" cffi "pyyaml>=6.0.0" 2>/dev/null || true
|
||||
fi
|
||||
# ---- Install openhop_repeater from git ----
|
||||
if "$VENV_PIP" install \
|
||||
if "$VENV_PYTHON" -m pip install \
|
||||
--upgrade \
|
||||
--no-cache-dir \
|
||||
"openhop_repeater[hardware] @ git+https://github.com/rightup/openhop-repeater.git@${CHANNEL}"; then
|
||||
@@ -687,7 +705,7 @@ UPGRADEEOF
|
||||
WHEEL_BASE="${R2_BASE_URL}/${ARCH_TAG}/${PLATFORM_TAG}/${PY_TAG}"
|
||||
echo " Checking for R2 wheels (${ARCH_TAG}/${PLATFORM_TAG}/${PY_TAG})..."
|
||||
echo " Trying install from R2 pre-built wheels..."
|
||||
"$VENV_PIP" install --find-links "${WHEEL_BASE}/index.html" --no-cache-dir "pycryptodome>=3.23.0" "PyNaCl>=1.5.0" cffi "pyyaml>=6.0.0" 2>/dev/null && R2_SUCCESS=1 || R2_SUCCESS=0
|
||||
"$VENV_PYTHON" -m pip install --find-links "${WHEEL_BASE}/index.html" --no-cache-dir "pycryptodome>=3.23.0" "PyNaCl>=1.5.0" cffi "pyyaml>=6.0.0" 2>/dev/null && R2_SUCCESS=1 || R2_SUCCESS=0
|
||||
if [ "$R2_SUCCESS" -eq 1 ]; then
|
||||
echo " ✓ R2 wheels installed"
|
||||
else
|
||||
@@ -696,7 +714,7 @@ UPGRADEEOF
|
||||
fi
|
||||
fi
|
||||
|
||||
if "$VENV_PIP" install --upgrade --no-cache-dir .[hardware]; then
|
||||
if "$VENV_PYTHON" -m pip install --upgrade --no-cache-dir .[hardware]; then
|
||||
echo ""
|
||||
echo "✓ Python package installation completed successfully!"
|
||||
|
||||
@@ -1002,7 +1020,7 @@ fi
|
||||
if [ ! -x "$VENV_PYTHON" ]; then
|
||||
echo "[pymc-do-upgrade] Creating venv at $VENV_DIR ..."
|
||||
python3 -m venv --system-site-packages "$VENV_DIR"
|
||||
"$VENV_PIP" install --upgrade pip setuptools wheel >/dev/null 2>&1 || true
|
||||
"$VENV_PYTHON" -m pip install --upgrade pip setuptools wheel >/dev/null 2>&1 || true
|
||||
fi
|
||||
# ---- Migration: clean up legacy service unit issues ----
|
||||
SVC_UNIT=/etc/systemd/system/openhop-repeater.service
|
||||
@@ -1050,10 +1068,10 @@ python3 -m pip uninstall -y pymc_core 2>/dev/null || true
|
||||
PY_TAG=$("$VENV_PYTHON" -c 'import sys; v=f"cp{sys.version_info.major}{sys.version_info.minor}"; print(f"{v}-{v}")' 2>/dev/null || echo "cp311-cp311")
|
||||
WHEEL_BASE="${R2_BASE_URL}/${ARCH_TAG}/${PLATFORM_TAG}/${PY_TAG}"
|
||||
echo "[pymc-do-upgrade] Trying dependencies from R2 wheels..."
|
||||
"$VENV_PIP" install --find-links "${WHEEL_BASE}/index.html" --no-cache-dir "pycryptodome>=3.23.0" "PyNaCl>=1.5.0" cffi "pyyaml>=6.0.0" 2>/dev/null || true
|
||||
"$VENV_PYTHON" -m pip install --find-links "${WHEEL_BASE}/index.html" --no-cache-dir "pycryptodome>=3.23.0" "PyNaCl>=1.5.0" cffi "pyyaml>=6.0.0" 2>/dev/null || true
|
||||
fi
|
||||
# ---- Install openhop_repeater from git ----
|
||||
if "$VENV_PIP" install \
|
||||
if "$VENV_PYTHON" -m pip install \
|
||||
--upgrade \
|
||||
--no-cache-dir \
|
||||
"openhop_repeater[hardware] @ git+https://github.com/rightup/openhop-repeater.git@${CHANNEL}"; then
|
||||
@@ -1122,7 +1140,7 @@ UPGRADEEOF
|
||||
WHEEL_BASE="${R2_BASE_URL}/${ARCH_TAG}/${PLATFORM_TAG}/${PY_TAG}"
|
||||
echo " Checking for R2 wheels (${ARCH_TAG}/${PLATFORM_TAG}/${PY_TAG})..."
|
||||
echo " Trying install from R2 pre-built wheels..."
|
||||
"$VENV_PIP" install --find-links "${WHEEL_BASE}/index.html" --no-cache-dir "pycryptodome>=3.23.0" "PyNaCl>=1.5.0" cffi "pyyaml>=6.0.0" 2>/dev/null && R2_SUCCESS=1 || R2_SUCCESS=0
|
||||
"$VENV_PYTHON" -m pip install --find-links "${WHEEL_BASE}/index.html" --no-cache-dir "pycryptodome>=3.23.0" "PyNaCl>=1.5.0" cffi "pyyaml>=6.0.0" 2>/dev/null && R2_SUCCESS=1 || R2_SUCCESS=0
|
||||
if [ "$R2_SUCCESS" -eq 1 ]; then
|
||||
echo " ✓ R2 wheels installed"
|
||||
else
|
||||
@@ -1131,7 +1149,7 @@ UPGRADEEOF
|
||||
fi
|
||||
fi
|
||||
|
||||
if "$VENV_PIP" install --upgrade --no-cache-dir .[hardware]; then
|
||||
if "$VENV_PYTHON" -m pip install --upgrade --no-cache-dir .[hardware]; then
|
||||
echo ""
|
||||
echo "✓ Package and dependencies upgraded successfully!"
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user