controller/image::Create: Standardize Path usage.
Standardize Path usage when adding images to the output proto.
BUG=None
TEST=cq, manually ran endpoint
Change-Id: I6919f9d03571dc40447a0a18e5b1484e7fc8d4af
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/3133582
Tested-by: Alex Klein <saklein@chromium.org>
Auto-Submit: Alex Klein <saklein@chromium.org>
Commit-Queue: Jack Neus <jackneus@google.com>
Reviewed-by: Jack Neus <jackneus@google.com>
diff --git a/api/controller/image.py b/api/controller/image.py
index 5cb6260..ab66f11 100644
--- a/api/controller/image.py
+++ b/api/controller/image.py
@@ -11,7 +11,7 @@
import functools
import logging
import os
-from typing import List, NamedTuple, Set
+from typing import List, NamedTuple, Set, TYPE_CHECKING, Union
from chromite.api import controller
from chromite.api import faux
@@ -29,6 +29,9 @@
from chromite.service import image
from chromite.utils import metrics
+if TYPE_CHECKING:
+ from pathlib import Path
+
# The image.proto ImageType enum ids.
_BASE_ID = common_pb2.IMAGE_TYPE_BASE
_DEV_ID = common_pb2.IMAGE_TYPE_DEV
@@ -114,10 +117,11 @@
return [_IMAGE_MAPPING[_FACTORY_ID]] if self.has_factory else []
-def _add_image_to_proto(output_proto, path, image_type, board):
+def _add_image_to_proto(output_proto, path: Union['Path', str], image_type: int,
+ board: str):
"""Quick helper function to add a new image to the output proto."""
new_image = output_proto.images.add()
- new_image.path = path
+ new_image.path = str(path)
new_image.type = image_type
new_image.build_target.name = board
@@ -234,7 +238,7 @@
# Success! We need to record the images we built in the output.
all_images = {**core_result.images, **factory_result.images}
for img_name, img_path in all_images.items():
- _add_image_to_proto(output_proto, str(img_path), _IMAGE_MAPPING[img_name],
+ _add_image_to_proto(output_proto, img_path, _IMAGE_MAPPING[img_name],
board)
# Build and record VMs as necessary.