api.controller: switch to typing module
Converting Python docstring annotations to typing.
BUG=b:196895668
TEST=./run_tests api/controller/artifacts_unittest.py
Change-Id: I4924041a513eb7ee8fd2af615e8fb17b11889764
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/3215092
Tested-by: Varun Somani <vsomani@google.com>
Commit-Queue: Varun Somani <vsomani@google.com>
Reviewed-by: Alex Klein <saklein@chromium.org>
diff --git a/api/controller/artifacts.py b/api/controller/artifacts.py
index 797d02a..2a3aaba 100644
--- a/api/controller/artifacts.py
+++ b/api/controller/artifacts.py
@@ -6,7 +6,7 @@
import logging
import os
-from typing import Any, NamedTuple
+from typing import Any, NamedTuple, Optional, TYPE_CHECKING
from chromite.api import controller
from chromite.api import faux
@@ -25,6 +25,8 @@
from chromite.service import artifacts
from chromite.service import test
+if TYPE_CHECKING:
+ from chromite.api import api_config
class RegisteredGet(NamedTuple):
"""An registered function for calling Get on an artifact type."""
@@ -46,7 +48,10 @@
@faux.success(ExampleGetResponse)
@validate.exists('result_path.path.path')
@validate.validation_complete
-def Get(input_proto, output_proto, _config):
+def Get(
+ input_proto: artifacts_pb2.GetRequest,
+ output_proto: artifacts_pb2.GetResponse,
+ _config: 'api_config.ApiConfig'):
"""Get all artifacts.
Get all artifacts for the build.
@@ -55,9 +60,9 @@
stop uploading it via the individual bundler function.
Args:
- input_proto (GetRequest): The input proto.
- output_proto (GetResponse): The output proto.
- _config (api_config.ApiConfig): The API call config.
+ input_proto: The input proto.
+ output_proto: The output proto.
+ _config: The API call config.
"""
output_dir = input_proto.result_path.path.path
@@ -111,7 +116,11 @@
@faux.success(_BuildSetupResponse)
@faux.empty_error
@validate.validation_complete
-def BuildSetup(_input_proto, output_proto, _config):
+def BuildSetup(
+ _input_proto: artifacts_pb2.GetRequest,
+ output_proto: artifacts_pb2.GetResponse,
+ _config: 'api_config.ApiConfig'):
+
"""Setup anything needed for building artifacts
If any artifact types require steps prior to building the package, they go
@@ -122,9 +131,9 @@
individual bundler function.
Args:
- _input_proto (GetRequest): The input proto.
- output_proto (GetResponse): The output proto.
- _config (api_config.ApiConfig): The API call config.
+ _input_proto: The input proto.
+ output_proto: The output proto.
+ _config: The API call config.
"""
# If any artifact_type says "NEEDED", the return is NEEDED.
# Otherwise, if any artifact_type says "UNKNOWN", the return is UNKNOWN.
@@ -133,14 +142,14 @@
return controller.RETURN_CODE_SUCCESS
-def _GetImageDir(build_root, target):
+def _GetImageDir(build_root: str, target: str) -> Optional[str]:
"""Return path containing images for the given build target.
TODO(saklein) Expand image_lib.GetLatestImageLink to support this use case.
Args:
- build_root (str): Path to checkout where build occurs.
- target (str): Name of the build target.
+ build_root: Path to checkout where build occurs.
+ target: Name of the build target.
Returns:
Path to the latest directory containing target images or None.
@@ -192,13 +201,16 @@
@validate.require('build_target.name', 'output_dir')
@validate.exists('output_dir')
@validate.validation_complete
-def BundleImageZip(input_proto, output_proto, _config):
+def BundleImageZip(
+ input_proto: artifacts_pb2.BundleRequest,
+ output_proto: artifacts_pb2.BundleResponse,
+ _config: 'api_config.ApiConfig'):
"""Bundle image.zip.
Args:
- input_proto (BundleRequest): The input proto.
- output_proto (BundleResponse): The output proto.
- _config (api_config.ApiConfig): The API call config.
+ input_proto: The input proto.
+ output_proto: The output proto.
+ _config: The API call config.
"""
target = input_proto.build_target.name
output_dir = input_proto.output_dir
@@ -221,13 +233,16 @@
@validate.require('build_target.name', 'output_dir')
@validate.exists('output_dir')
@validate.validation_complete
-def BundleTestUpdatePayloads(input_proto, output_proto, _config):
+def BundleTestUpdatePayloads(
+ input_proto: artifacts_pb2.BundleRequest,
+ output_proto: artifacts_pb2.BundleResponse,
+ _config: 'api_config.ApiConfig'):
"""Generate minimal update payloads for the build target for testing.
Args:
- input_proto (BundleRequest): The input proto.
- output_proto (BundleResponse): The output proto.
- _config (api_config.ApiConfig): The API call config.
+ input_proto: The input proto.
+ output_proto: The output proto.
+ _config: The API call config.
"""
target = input_proto.build_target.name
output_dir = input_proto.output_dir
@@ -265,13 +280,16 @@
@faux.empty_error
@validate.require('output_dir')
@validate.exists('output_dir')
-def BundleAutotestFiles(input_proto, output_proto, config):
+def BundleAutotestFiles(
+ input_proto: artifacts_pb2.BundleRequest,
+ output_proto: artifacts_pb2.BundleResponse,
+ config: 'api_config.ApiConfig'):
"""Tar the autotest files for a build target.
Args:
- input_proto (BundleRequest): The input proto.
- output_proto (BundleResponse): The output proto.
- config (api_config.ApiConfig): The API call config.
+ input_proto: The input proto.
+ output_proto: The output proto.
+ config: The API call config.
"""
output_dir = input_proto.output_dir
target = input_proto.build_target.name
@@ -316,13 +334,16 @@
@faux.empty_error
@validate.require('output_dir')
@validate.exists('output_dir')
-def BundleTastFiles(input_proto, output_proto, config):
+def BundleTastFiles(
+ input_proto: artifacts_pb2.BundleRequest,
+ output_proto: artifacts_pb2.BundleResponse,
+ config: 'api_config.ApiConfig'):
"""Tar the tast files for a build target.
Args:
- input_proto (BundleRequest): The input proto.
- output_proto (BundleResponse): The output proto.
- config (api_config.ApiConfig): The API call config.
+ input_proto: The input proto.
+ output_proto: The output proto.
+ config: The API call config.
"""
target = input_proto.build_target.name
output_dir = input_proto.output_dir
@@ -381,15 +402,18 @@
@validate.exists('chroot.path')
@validate.require('sysroot.path')
@validate.validation_complete
-def FetchMetadata(input_proto, output_proto, _config):
+def FetchMetadata(
+ input_proto: artifacts_pb2.FetchMetadataRequest,
+ output_proto: artifacts_pb2.FetchMetadataResponse,
+ _config: 'api_config.ApiConfig'):
"""FetchMetadata returns the paths to all build/test metadata files.
This implements ArtifactsService.FetchMetadata.
Args:
- input_proto (FetchMetadataRequest): The input proto.
- output_proto (FetchMetadataResponse): The output proto.
- config (api_config.ApiConfig): The API call config.
+ input_proto: The input proto.
+ output_proto: The output proto.
+ config: The API call config.
"""
chroot = controller_util.ParseChroot(input_proto.chroot)
sysroot = controller_util.ParseSysroot(input_proto.sysroot)
@@ -410,13 +434,16 @@
@validate.require('output_dir', 'sysroot.path')
@validate.exists('output_dir')
@validate.validation_complete
-def BundleFirmware(input_proto, output_proto, _config):
+def BundleFirmware(
+ input_proto: artifacts_pb2.BundleRequest,
+ output_proto: artifacts_pb2.BundleResponse,
+ _config: 'api_config.ApiConfig'):
"""Tar the firmware images for a build target.
Args:
- input_proto (BundleRequest): The input proto.
- output_proto (BundleResponse): The output proto.
- _config (api_config.ApiConfig): The API call config.
+ input_proto: The input proto.
+ output_proto: The output proto.
+ _config: The API call config.
"""
output_dir = input_proto.output_dir
chroot = controller_util.ParseChroot(input_proto.chroot)
@@ -450,13 +477,16 @@
@validate.require('output_dir', 'sysroot.path')
@validate.exists('output_dir')
@validate.validation_complete
-def BundleFpmcuUnittests(input_proto, output_proto, _config):
+def BundleFpmcuUnittests(
+ input_proto: artifacts_pb2.BundleRequest,
+ output_proto: artifacts_pb2.BundleResponse,
+ _config: 'api_config.ApiConfig'):
"""Tar the fingerprint MCU unittest binaries for a build target.
Args:
- input_proto (BundleRequest): The input proto.
- output_proto (BundleResponse): The output proto.
- _config (api_config.ApiConfig): The API call config.
+ input_proto: The input proto.
+ output_proto: The output proto.
+ _config: The API call config.
"""
output_dir = input_proto.output_dir
chroot = controller_util.ParseChroot(input_proto.chroot)
@@ -488,13 +518,16 @@
@faux.success(_BundleEbuildLogsResponse)
@faux.empty_error
@validate.exists('output_dir')
-def BundleEbuildLogs(input_proto, output_proto, config):
+def BundleEbuildLogs(
+ input_proto: artifacts_pb2.BundleRequest,
+ output_proto: artifacts_pb2.BundleResponse,
+ config: 'api_config.ApiConfig'):
"""Tar the ebuild logs for a build target.
Args:
- input_proto (BundleRequest): The input proto.
- output_proto (BundleResponse): The output proto.
- config (api_config.ApiConfig): The API call config.
+ input_proto: The input proto.
+ output_proto: The output proto.
+ config: The API call config.
"""
output_dir = input_proto.output_dir
sysroot_path = input_proto.sysroot.path
@@ -532,13 +565,16 @@
@faux.empty_error
@validate.exists('output_dir')
@validate.validation_complete
-def BundleChromeOSConfig(input_proto, output_proto, _config):
+def BundleChromeOSConfig(
+ input_proto: artifacts_pb2.BundleRequest,
+ output_proto: artifacts_pb2.BundleResponse,
+ _config: 'api_config.ApiConfig'):
"""Output the ChromeOS Config payload for a build target.
Args:
- input_proto (BundleRequest): The input proto.
- output_proto (BundleResponse): The output proto.
- _config (api_config.ApiConfig): The API call config.
+ input_proto: The input proto.
+ output_proto: The output proto.
+ _config: The API call config.
"""
output_dir = input_proto.output_dir
sysroot_path = input_proto.sysroot.path
@@ -611,13 +647,16 @@
@validate.require('chroot.path', 'test_results_dir', 'output_dir')
@validate.exists('output_dir')
@validate.validation_complete
-def BundleVmFiles(input_proto, output_proto, _config):
+def BundleVmFiles(
+ input_proto: artifacts_pb2.BundleVmFilesRequest,
+ output_proto: artifacts_pb2.BundleResponse,
+ _config: 'api_config.ApiConfig'):
"""Tar VM disk and memory files.
Args:
- input_proto (BundleVmFilesRequest): The input proto.
- output_proto (BundleResponse): The output proto.
- _config (api_config.ApiConfig): The API call config.
+ input_proto: The input proto.
+ output_proto: The output proto.
+ _config: The API call config.
"""
chroot = controller_util.ParseChroot(input_proto.chroot)
test_results_dir = input_proto.test_results_dir
@@ -643,13 +682,16 @@
@validate.exists('output_dir')
@validate.exists('chroot.chrome_dir')
@validate.validation_complete
-def BundleAFDOGenerationArtifacts(input_proto, output_proto, _config):
+def BundleAFDOGenerationArtifacts(
+ input_proto: artifacts_pb2.BundleChromeAFDORequest,
+ output_proto: artifacts_pb2.BundleResponse,
+ _config: 'api_config.ApiConfig'):
"""Generic function for creating tarballs of both AFDO and orderfile.
Args:
- input_proto (BundleChromeAFDORequest): The input proto.
- output_proto (BundleResponse): The output proto.
- _config (api_config.ApiConfig): The API call config.
+ input_proto: The input proto.
+ output_proto: The output proto.
+ _config: The API call config.
"""
chrome_root = input_proto.chroot.chrome_dir
output_dir = input_proto.output_dir
@@ -682,13 +724,16 @@
@faux.success(_ExportCpeReportResponse)
@faux.empty_error
@validate.exists('output_dir')
-def ExportCpeReport(input_proto, output_proto, config):
+def ExportCpeReport(
+ input_proto: artifacts_pb2.BundleRequest,
+ output_proto: artifacts_pb2.BundleResponse,
+ config: 'api_config.ApiConfig'):
"""Export a CPE report.
Args:
- input_proto (BundleRequest): The input proto.
- output_proto (BundleResponse): The output proto.
- config (api_config.ApiConfig): The API call config.
+ input_proto: The input proto.
+ output_proto: The output proto.
+ config: The API call config.
"""
chroot = controller_util.ParseChroot(input_proto.chroot)
output_dir = input_proto.output_dir
@@ -724,13 +769,16 @@
@validate.require('build_target.name', 'output_dir')
@validate.exists('output_dir')
@validate.validation_complete
-def BundleGceTarball(input_proto, output_proto, _config):
+def BundleGceTarball(
+ input_proto: artifacts_pb2.BundleRequest,
+ output_proto: artifacts_pb2.BundleResponse,
+ _config: 'api_config.ApiConfig'):
"""Bundle the test image into a tarball suitable for importing into GCE.
Args:
- input_proto (BundleRequest): The input proto.
- output_proto (BundleResponse): The output proto.
- _config (api_config.ApiConfig): The API call config.
+ input_proto: The input proto.
+ output_proto: The output proto.
+ _config: The API call config.
"""
target = input_proto.build_target.name
output_dir = input_proto.output_dir