Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test-opensrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
matrix:
include:
- name: normal_test
test_target: "//kv_cache_manager/... //integration_test/..."
test_target: "//kv_cache_manager/... //integration_test/... //package/kvcm_ops/..."
test_args: ""
- name: asan_test
test_target: "//kv_cache_manager/... //integration_test/..."
Expand Down
12 changes: 9 additions & 3 deletions open_source/deps/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ load("@rules_python//python:packaging.bzl", "py_package")
load("@rules_python//python:pip.bzl", "compile_pip_requirements")
load(":pip.bzl", "PIP_EXTRA_ARGS")

exports_files(["requirements_base.txt"])
exports_files([
"requirements_base.txt",
"requirements_kvcm_ops.txt",
])

py_package(
name = "extension_package",
Expand All @@ -24,7 +27,10 @@ compile_pip_requirements(
name = "requirements_cpu",
src = "requirements_cpu.txt",
extra_args = PIP_EXTRA_ARGS,
extra_data = ["//open_source/deps:requirements_base.txt"],
extra_data = [
"//open_source/deps:requirements_base.txt",
"//open_source/deps:requirements_kvcm_ops.txt",
],
requirements_txt = "requirements_lock_cpu.txt",
tags = ["manual"],
)
)
2 changes: 1 addition & 1 deletion open_source/deps/requirements_base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ setuptools==60.5.0
grpcio==1.62.0
grpcio-tools==1.62.0
protobuf==4.25
requests==2.32.5
-r ./requirements_kvcm_ops.txt
1 change: 1 addition & 0 deletions open_source/deps/requirements_kvcm_ops.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests==2.32.5
2 changes: 1 addition & 1 deletion open_source/deps/requirements_lock_cpu.txt
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ protobuf==4.25.0 \
requests==2.32.5 \
--hash=sha256:2462f94637a34fd532264295e186976db0f5d453d1cdd31473c85a6a161affb6 \
--hash=sha256:dbba0bac56e100853db0ea71b82b4dfd5fe2bf6d3754a8893c3af500cec7d7cf
# via -r open_source/deps/./requirements_base.txt
# via -r open_source/deps/././requirements_kvcm_ops.txt
urllib3==2.5.0 \
--hash=sha256:3fc47733c7e419d4bc3f6b3dc2b4f890bb743906a30d56ba4a5bfa4bbff92760 \
--hash=sha256:e6b01673c0fa6a13e374b50871808eb3bf7046c4b125b216f6bf1cc604cff0dc
Expand Down
25 changes: 25 additions & 0 deletions package/kvcm_ops/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,36 @@ py_wheel(
name = "kvcm_ops_wheel",
distribution = "kvcm_ops",
python_tag = "py3",
requires_file = "//open_source/deps:requirements_kvcm_ops.txt",
strip_path_prefixes = ["package"],
version = "0.1.0",
deps = [":kvcm_ops_lib"],
)

py_test(
name = "wheel_metadata_test",
size = "small",
srcs = ["test/wheel_metadata_test.py"],
args = [
"$(location :kvcm_ops_wheel)",
"$(location //open_source/deps:requirements_kvcm_ops.txt)",
],
data = [
":kvcm_ops_wheel",
"//open_source/deps:requirements_kvcm_ops.txt",
],
main = "test/wheel_metadata_test.py",
)

py_test(
name = "wheel_install_test",
size = "medium",
srcs = ["test/wheel_install_test.py"],
args = ["$(location :kvcm_ops_wheel)"],
data = [":kvcm_ops_wheel"],
main = "test/wheel_install_test.py",
)

py_test(
name = "storage_util_test",
srcs = ["test/storage_util_test.py"],
Expand Down
83 changes: 83 additions & 0 deletions package/kvcm_ops/test/wheel_install_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import os
import subprocess
import sys
import tempfile
import unittest
import venv
from pathlib import Path


class WheelInstallTest(unittest.TestCase):
def setUp(self):
self.wheel_path = Path(sys.argv[1]).resolve()
self.temp_dir = tempfile.TemporaryDirectory()
self.addCleanup(self.temp_dir.cleanup)

self.temp_path = Path(self.temp_dir.name)
self.venv_path = self.temp_path / "venv"
venv.EnvBuilder(with_pip=True).create(self.venv_path)
self.python = self.venv_path / "bin" / "python"

self.env = os.environ.copy()
for variable in ("PYTHONHOME", "PYTHONPATH", "PYTHONUSERBASE"):
self.env.pop(variable, None)
self.env["PIP_DISABLE_PIP_VERSION_CHECK"] = "1"
self.env["PYTHONNOUSERSITE"] = "1"

def run_command(self, *args):
result = subprocess.run(
args,
cwd=self.temp_path,
env=self.env,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
)
self.assertEqual(0, result.returncode, msg=result.stdout)
return result.stdout

def test_install_resolves_requests_and_starts_http_command(self):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a useful regression test, but be aware it depends on the CI runner having outbound PyPI access and a base Python with ensurepip. If either is unavailable, the normal_test shard will fail. Consider documenting this requirement or adding tags = ["manual"] if network access is not guaranteed.


🤖 Generated by Qoder

self.run_command(
self.python,
"-I",
"-c",
"import importlib.util; "
"assert importlib.util.find_spec('requests') is None",
)

self.run_command(
self.python,
"-m",
"pip",
"install",
"--no-input",
self.wheel_path,
)
self.run_command(self.python, "-m", "pip", "check")
self.run_command(
self.python,
"-I",
"-c",
"from importlib.metadata import version; "
"assert version('requests') == '2.32.5'; "
"import certifi, charset_normalizer, idna, requests, urllib3",
)

top_level_help = self.run_command(
self.python, "-I", "-m", "kvcm_ops", "--help"
)
self.assertIn("KVCM script entry", top_level_help)

http_command_help = self.run_command(
self.python,
"-I",
"-m",
"kvcm_ops",
"list_instance",
"--help",
)
self.assertIn("kvcm: list_intance.", http_command_help)


if __name__ == "__main__":
unittest.main(argv=[sys.argv[0]])
40 changes: 40 additions & 0 deletions package/kvcm_ops/test/wheel_metadata_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import email
import sys
import unittest
import zipfile
from pathlib import Path


class WheelMetadataTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
wheel_path = Path(sys.argv[1])
requirements_path = Path(sys.argv[2])
cls.expected_requirements = [
line.strip()
for line in requirements_path.read_text(encoding="utf-8").splitlines()
if line.strip() and not line.lstrip().startswith("#")
]

with zipfile.ZipFile(wheel_path) as archive:
metadata_names = [
name
for name in archive.namelist()
if name.endswith(".dist-info/METADATA")
]
if len(metadata_names) != 1:
raise AssertionError(
f"expected exactly one METADATA file, found {metadata_names}"
)
cls.metadata = email.message_from_bytes(archive.read(metadata_names[0]))

def test_declares_shared_runtime_requirements(self):
self.assertEqual(["requests==2.32.5"], self.expected_requirements)
self.assertEqual(
self.expected_requirements,
self.metadata.get_all("Requires-Dist", []),
)


if __name__ == "__main__":
unittest.main(argv=[sys.argv[0]])
Loading