mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
Add and fix typing for docker_pull_helper, github_helper and style_check
This commit is contained in:
parent
02b8da2a0f
commit
6e00bb2e74
@ -6,11 +6,11 @@ import time
|
||||
import subprocess
|
||||
import logging
|
||||
|
||||
from typing import Optional
|
||||
from typing import List, Optional
|
||||
|
||||
|
||||
class DockerImage:
|
||||
def __init__(self, name, version: Optional[str] = None):
|
||||
def __init__(self, name: str, version: Optional[str] = None):
|
||||
self.name = name
|
||||
if version is None:
|
||||
self.version = "latest"
|
||||
@ -22,8 +22,11 @@ class DockerImage:
|
||||
|
||||
|
||||
def get_images_with_versions(
|
||||
reports_path, required_image, pull=True, version: Optional[str] = None
|
||||
):
|
||||
reports_path: str,
|
||||
required_images: List[str],
|
||||
pull: bool = True,
|
||||
version: Optional[str] = None,
|
||||
) -> List[DockerImage]:
|
||||
images_path = None
|
||||
for root, _, files in os.walk(reports_path):
|
||||
for f in files:
|
||||
@ -45,12 +48,13 @@ def get_images_with_versions(
|
||||
images = {}
|
||||
|
||||
docker_images = []
|
||||
for image_name in required_image:
|
||||
for image_name in required_images:
|
||||
docker_image = DockerImage(image_name, version)
|
||||
if image_name in images:
|
||||
docker_image.version = images[image_name]
|
||||
docker_images.append(docker_image)
|
||||
|
||||
latest_error = Exception("predefined to avoid access before created")
|
||||
if pull:
|
||||
for docker_image in docker_images:
|
||||
for i in range(10):
|
||||
@ -75,6 +79,8 @@ def get_images_with_versions(
|
||||
return docker_images
|
||||
|
||||
|
||||
def get_image_with_version(reports_path, image, pull=True, version=None):
|
||||
def get_image_with_version(
|
||||
reports_path: str, image: str, pull: bool = True, version: Optional[str] = None
|
||||
) -> DockerImage:
|
||||
logging.info("Looking for images file in %s", reports_path)
|
||||
return get_images_with_versions(reports_path, [image], pull, version=version)[0]
|
||||
|
@ -90,7 +90,7 @@ class GitHub(github.Github):
|
||||
raise exception
|
||||
|
||||
# pylint: enable=signature-differs
|
||||
def get_pulls_from_search(self, *args, **kwargs) -> PullRequests:
|
||||
def get_pulls_from_search(self, *args, **kwargs) -> PullRequests: # type: ignore
|
||||
"""The search api returns actually issues, so we need to fetch PullRequests"""
|
||||
issues = self.search_issues(*args, **kwargs)
|
||||
repos = {}
|
||||
@ -168,7 +168,7 @@ class GitHub(github.Github):
|
||||
self.dump(user, prfd) # type: ignore
|
||||
return user
|
||||
|
||||
def _get_cached(self, path: Path):
|
||||
def _get_cached(self, path: Path): # type: ignore
|
||||
with open(path, "rb") as ob_fd:
|
||||
return self.load(ob_fd) # type: ignore
|
||||
|
||||
@ -190,11 +190,11 @@ class GitHub(github.Github):
|
||||
return False, cached_obj
|
||||
|
||||
@property
|
||||
def cache_path(self):
|
||||
def cache_path(self) -> Path:
|
||||
return self._cache_path
|
||||
|
||||
@cache_path.setter
|
||||
def cache_path(self, value: str):
|
||||
def cache_path(self, value: str) -> None:
|
||||
self._cache_path = Path(value)
|
||||
if self._cache_path.exists():
|
||||
assert self._cache_path.is_dir()
|
||||
@ -208,5 +208,6 @@ class GitHub(github.Github):
|
||||
return self._retries
|
||||
|
||||
@retries.setter
|
||||
def retries(self, value: int):
|
||||
def retries(self, value: int) -> None:
|
||||
assert isinstance(value, int)
|
||||
self._retries = value
|
||||
|
@ -1,11 +1,13 @@
|
||||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import atexit
|
||||
import csv
|
||||
import logging
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import atexit
|
||||
|
||||
from typing import List, Tuple
|
||||
|
||||
|
||||
from clickhouse_helper import (
|
||||
@ -29,8 +31,10 @@ from upload_result_helper import upload_results
|
||||
NAME = "Style Check"
|
||||
|
||||
|
||||
def process_result(result_folder):
|
||||
test_results = []
|
||||
def process_result(
|
||||
result_folder: str,
|
||||
) -> Tuple[str, str, List[Tuple[str, str]], List[str]]:
|
||||
test_results = [] # type: List[Tuple[str, str]]
|
||||
additional_files = []
|
||||
# Just upload all files from result_folder.
|
||||
# If task provides processed results, then it's responsible
|
||||
@ -57,7 +61,7 @@ def process_result(result_folder):
|
||||
try:
|
||||
results_path = os.path.join(result_folder, "test_results.tsv")
|
||||
with open(results_path, "r", encoding="utf-8") as fd:
|
||||
test_results = list(csv.reader(fd, delimiter="\t"))
|
||||
test_results = list(csv.reader(fd, delimiter="\t")) # type: ignore
|
||||
if len(test_results) == 0:
|
||||
raise Exception("Empty results")
|
||||
|
||||
@ -81,7 +85,7 @@ def parse_args():
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def checkout_head(pr_info: PRInfo):
|
||||
def checkout_head(pr_info: PRInfo) -> None:
|
||||
# It works ONLY for PRs, and only over ssh, so either
|
||||
# ROBOT_CLICKHOUSE_SSH_KEY should be set or ssh-agent should work
|
||||
assert pr_info.number
|
||||
@ -107,7 +111,7 @@ def checkout_head(pr_info: PRInfo):
|
||||
git_runner(f"git checkout -f head-{pr_info.head_ref}")
|
||||
|
||||
|
||||
def commit_push_staged(pr_info: PRInfo):
|
||||
def commit_push_staged(pr_info: PRInfo) -> None:
|
||||
# It works ONLY for PRs, and only over ssh, so either
|
||||
# ROBOT_CLICKHOUSE_SSH_KEY should be set or ssh-agent should work
|
||||
assert pr_info.number
|
||||
|
Loading…
Reference in New Issue
Block a user