Repository: caikit/caikit
Pull request #569 (2023-11-08 16:32:18)

Add support for custom package version info
<!--  Thanks for sending a pull request!  Here are some tips for you:
1. Make sure to read the Contributing Guide before submitting your PR: https://github.com/caikit/caikit/blob/main/CONTRIBUTING.md
2. If this PR closes another issue, add 'closes #<issue number>' somewhere in the PR summary. GitHub will automatically close that issue when this PR gets merged. Alternatively, adding 'refs #<issue number>' will not close the issue, but help provide the reviewer more context.-->

**What this PR does / why we need it**:
This PR adds support for supplying custom package names and versions to `runtime.version_info.python_packages`. This allows users to supply more detailed package information without supplying to much with `all`. 

**Special notes for your reviewer**:

**If applicable**:
- [ ] this PR contains documentation
- [X] this PR contains unit tests
- [X] this PR has been tested for backwards compatibility



Patch:
diff --git a/caikit/runtime/servicers/info_servicer.py b/caikit/runtime/servicers/info_servicer.py
index 6d261edb..b4974dec 100644
--- a/caikit/runtime/servicers/info_servicer.py
+++ b/caikit/runtime/servicers/info_servicer.py
@@ -46,8 +46,14 @@ class InfoServicer:
 
     def get_runtime_info_impl(self) -> RuntimeInfoResponse:
         """Get information on versions of libraries and server from config"""
-        python_packages = {}
         config_version_info = get_config().runtime.version_info or {}
+        python_packages = {
+            package: version
+            for package, version in config_version_info.get(
+                "python_packages", {}
+            ).items()
+            if package != "all"
+        }
         all_packages = (config_version_info.get("python_packages") or {}).get("all")
 
         for lib, dist_names in importlib_metadata.packages_distributions().items():


Test patch:
diff --git a/tests/runtime/http_server/test_http_server.py b/tests/runtime/http_server/test_http_server.py
index 0d4ab553..f4dbd066 100644
--- a/tests/runtime/http_server/test_http_server.py
+++ b/tests/runtime/http_server/test_http_server.py
@@ -789,6 +789,27 @@ def test_runtime_info_ok_response_all_packages(runtime_http_server):
             assert "py_to_proto" in json_response["python_packages"]
 
 
+def test_runtime_info_ok_custom_python_packages(runtime_http_server):
+    """Make sure the runtime info returns version data"""
+    with temp_config(
+        {"runtime": {"version_info": {"python_packages": {"custom_package": "0.1.0"}}}},
+        merge_strategy="merge",
+    ):
+        with TestClient(runtime_http_server.app) as client:
+            response = client.get(http_server.RUNTIME_INFO_ENDPOINT)
+            assert response.status_code == 200
+
+            json_response = json.loads(
+                response.content.decode(response.default_encoding)
+            )
+            # runtime_version not added if not set
+            assert json_response["runtime_version"] == ""
+            # custom library is set while other random packages are not
+            assert "caikit" in json_response["python_packages"]
+            assert json_response["python_packages"]["custom_package"] == "0.1.0"
+            assert "py_to_proto" not in json_response["python_packages"]
+
+
 def test_http_server_shutdown_with_model_poll(open_port):
     """Test that a SIGINT successfully shuts down the running server"""
     with tempfile.TemporaryDirectory() as workdir: