Spaces:
Running on Zero
Running on Zero
File size: 2,994 Bytes
66ee87e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | """Pinned, reproducible build: every dependency version is fixed (sweep 1 open item, closed in 1.7.1).
The Dockerfile and requirement files stay outside the image, so inside the container these tests are skipped.
"""
import re
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
FILES = [ROOT / "requirements-container.txt", ROOT / "constraints.txt", ROOT / "Dockerfile"]
def pins(path: Path) -> dict:
out = {}
for line in path.read_text().splitlines():
line = line.split("#", 1)[0].strip()
if line:
m = re.fullmatch(r"([A-Za-z0-9_.\-]+)(\[[^\]]+\])?==([^\s;]+)", line)
if not m:
raise AssertionError(f"{path.name}: not an exact pin: {line!r}")
out[m.group(1).lower().replace("_", "-")] = m.group(3)
return out
@unittest.skipUnless((ROOT / "Dockerfile").is_file(), "the Dockerfile is not in the image")
class PinnedBuildTest(unittest.TestCase):
def test_every_requirement_is_an_exact_pin(self):
self.assertTrue(pins(ROOT / "requirements-container.txt"))
def test_every_constraint_is_an_exact_pin(self):
self.assertGreater(len(pins(ROOT / "constraints.txt")), 30)
def test_requirements_and_constraints_agree(self):
req, con = pins(ROOT / "requirements-container.txt"), pins(ROOT / "constraints.txt")
for name, version in req.items():
with self.subTest(package=name):
self.assertEqual(con.get(name), version)
def test_torch_is_pinned_in_the_dockerfile_not_the_constraints(self):
self.assertNotIn("torch", pins(ROOT / "constraints.txt"))
self.assertRegex((ROOT / "Dockerfile").read_text(), r"ARG TORCH_VERSION=\d+\.\d+\.\d+\n")
def test_dockerfile_installs_the_exact_set_and_checks_it(self):
df = (ROOT / "Dockerfile").read_text()
self.assertIn('pip install "torch==${TORCH_VERSION}"', df)
self.assertIn("-c constraints.txt", df)
self.assertIn("pip install --no-deps -r constraints.txt", df)
self.assertIn("&& pip check\n", df) # the command, not the comment that mentions it
self.assertIn("COPY requirements-container.txt constraints.txt ./", df)
if __name__ == "__main__":
unittest.main()
@unittest.skipUnless((ROOT / "docker-compose.yml").is_file(), "docker-compose.yml is not in the image")
class ComposeModelsTest(unittest.TestCase):
"""Compose must not override the operator's model list with other repos."""
def test_compose_does_not_pin_other_repos(self):
compose = (ROOT / "docker-compose.yml").read_text()
self.assertNotIn("laya-v796", compose)
for line in compose.splitlines():
if line.strip().startswith(("LAYA_REPO:", "LIGHTDEC_ARTHUR_REPO:", "LIGHTDEC_V2_REPO:")):
self.assertIn(line.split(":", 1)[1].split("#")[0].strip(),
("convaiinnovations/laya", "Falconsai/LightDec_Arthur", "Falconsai/LightDec_V2"))
|