Skip to content

Commit

Permalink
fix: update horde dependency patches on worker start
Browse files Browse the repository at this point in the history
  • Loading branch information
tazlin committed Mar 3, 2024
1 parent 1f588ed commit 5cb6b35
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 18 deletions.
21 changes: 19 additions & 2 deletions horde-bridge.cmd
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
@echo off
cd /d %~dp0
call runtime python -s download_models.py

: This first call to runtime activates the environment for the rest of the script
call runtime python -s -m pip -V

call python -s -m pip install horde_sdk~=0.8.0 horde_model_reference~=0.6.2 hordelib~=2.6.2 -U
if %ERRORLEVEL% NEQ 0 (
echo "Please run update-runtime.cmd."
GOTO END
)

call python -s -m pip check
if %ERRORLEVEL% NEQ 0 (
echo "Please run update-runtime.cmd."
GOTO END
)

:DOWNLOAD
call python -s download_models.py
if %ERRORLEVEL% NEQ 0 GOTO ABORT
echo "Model Download OK. Starting worker..."
call runtime python -s run_worker.py %*
call python -s run_worker.py %*

GOTO END

Expand Down
27 changes: 27 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Configures pytest and creates fixtures."""
# import hordelib
from pathlib import Path

import pytest
from loguru import logger

Expand All @@ -8,3 +10,28 @@
def init_hordelib() -> None:
# hordelib.initialise()
logger.warning("hordelib.initialise() not called")


PRECOMMIT_FILE_PATH = Path(__file__).parent.parent / ".pre-commit-config.yaml"
REQUIREMENTS_FILE_PATH = Path(__file__).parent.parent / "requirements.txt"

TRACKED_DEPENDENCIES = [
"horde_sdk",
"hordelib",
"horde_model_reference",
# "horde_safety"
]


@pytest.fixture(scope="session")
def horde_dependency_versions() -> list[tuple[str, str]]:
with open(REQUIREMENTS_FILE_PATH) as f:
requirements = f.readlines()

dependencies = []
for req in requirements:
for dep in TRACKED_DEPENDENCIES:
if req.startswith(dep):
dependencies.append((dep, req.split("~=")[1].strip()))

return dependencies
17 changes: 17 additions & 0 deletions tests/test_horde_dep_updates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from pathlib import Path

HORDE_BRIDGE_SCRIPT = Path(__file__).parent.parent / "horde-bridge.cmd"


def test_horde_bridge_updating(horde_dependency_versions: list[tuple[str, str]]) -> None:
script_lines = HORDE_BRIDGE_SCRIPT.read_text().split("\n")

found_line = False
for line in script_lines:
if line.startswith("call runtime python -s -m pip install"):
found_line = True
assert "-U" in line, "No -U flag found in pip install command"
for dep, version in horde_dependency_versions:
assert f"{dep}~={version}" in line, f"Dependency {dep} not found in pip install command"

assert found_line
22 changes: 6 additions & 16 deletions tests/test_pre_commit_dep_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
REQUIREMENTS_FILE_PATH = Path(__file__).parent.parent / "requirements.txt"


def test_pre_commit_dep_versions() -> None:
def test_pre_commit_dep_versions(horde_dependency_versions: list[tuple[str, str]]) -> None:
# Make sure hordelib and horde_sdk version pins match
with open(PRECOMMIT_FILE_PATH) as f:
precommit_config = yaml.safe_load(f)

NUM_TRACKED_REPOS = 3
horde_sdk_version = None
hordelib_version = None
horde_model_reference_version = None
Expand All @@ -33,22 +32,13 @@ def test_pre_commit_dep_versions() -> None:
assert hordelib_version is not None
assert horde_model_reference_version is not None

with open(REQUIREMENTS_FILE_PATH) as f:
requirements = f.readlines()

matches = 0
for req in requirements:
if req.startswith("horde_sdk"):
req_version = req.split("~=")[1].strip()
assert horde_sdk_version == req_version
for dep, version in horde_dependency_versions:
if dep == "horde_sdk" and version == horde_sdk_version:
matches += 1
if req.startswith("hordelib"):
req_version = req.split("~=")[1].strip()
assert hordelib_version == req_version
if dep == "hordelib" and version == hordelib_version:
matches += 1
if req.startswith("horde_model_reference"):
req_version = req.split("~=")[1].strip()
assert horde_model_reference_version == req_version
if dep == "horde_model_reference" and version == horde_model_reference_version:
matches += 1

assert matches == NUM_TRACKED_REPOS
assert matches == len(horde_dependency_versions)

0 comments on commit 5cb6b35

Please sign in to comment.