Improve style_check scripts style a little bit

This commit is contained in:
Mikhail f. Shiryaev 2022-07-19 13:31:43 +02:00
parent 9e9969cea7
commit dacfc7886c
No known key found for this signature in database
GPG Key ID: 4B02ED204C7D93F4
2 changed files with 22 additions and 26 deletions

View File

@ -40,10 +40,10 @@ def process_result(result_folder):
def write_results(results_file, status_file, results, status): def write_results(results_file, status_file, results, status):
with open(results_file, "w") as f: with open(results_file, "w", encoding="utf-8") as f:
out = csv.writer(f, delimiter="\t") out = csv.writer(f, delimiter="\t")
out.writerows(results) out.writerows(results)
with open(status_file, "w") as f: with open(status_file, "w", encoding="utf-8") as f:
out = csv.writer(f, delimiter="\t") out = csv.writer(f, delimiter="\t")
out.writerow(status) out.writerow(status)
@ -53,9 +53,10 @@ if __name__ == "__main__":
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description="ClickHouse script for parsing results of style check" description="ClickHouse script for parsing results of style check"
) )
parser.add_argument("--in-results-dir", default="/test_output/") default_dir = "/test_output"
parser.add_argument("--out-results-file", default="/test_output/test_results.tsv") parser.add_argument("--in-results-dir", default=default_dir)
parser.add_argument("--out-status-file", default="/test_output/check_status.tsv") parser.add_argument("--out-results-file", default=f"{default_dir}/test_results.tsv")
parser.add_argument("--out-status-file", default=f"{default_dir}/check_status.tsv")
args = parser.parse_args() args = parser.parse_args()
state, description, test_results = process_result(args.in_results_dir) state, description, test_results = process_result(args.in_results_dir)

View File

@ -1,32 +1,26 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import logging
import subprocess
import os
import csv import csv
import logging
import os
import subprocess
import sys import sys
from github import Github
from env_helper import (
RUNNER_TEMP,
GITHUB_WORKSPACE,
)
from s3_helper import S3Helper
from pr_info import PRInfo
from get_robot_token import get_best_robot_token
from upload_result_helper import upload_results
from docker_pull_helper import get_image_with_version
from commit_status_helper import (
post_commit_status,
fail_simple_check,
)
from clickhouse_helper import ( from clickhouse_helper import (
ClickHouseHelper, ClickHouseHelper,
mark_flaky_tests, mark_flaky_tests,
prepare_tests_results_for_clickhouse, prepare_tests_results_for_clickhouse,
) )
from stopwatch import Stopwatch from commit_status_helper import fail_simple_check, post_commit_status
from docker_pull_helper import get_image_with_version
from env_helper import GITHUB_WORKSPACE, RUNNER_TEMP
from get_robot_token import get_best_robot_token
from github_helper import GitHub
from pr_info import PRInfo
from rerun_helper import RerunHelper from rerun_helper import RerunHelper
from s3_helper import S3Helper
from stopwatch import Stopwatch
from upload_result_helper import upload_results
NAME = "Style Check (actions)" NAME = "Style Check (actions)"
@ -58,7 +52,8 @@ def process_result(result_folder):
try: try:
results_path = os.path.join(result_folder, "test_results.tsv") results_path = os.path.join(result_folder, "test_results.tsv")
test_results = list(csv.reader(open(results_path, "r"), delimiter="\t")) with open(results_path, "r", encoding="utf-8") as fd:
test_results = list(csv.reader(fd, delimiter="\t"))
if len(test_results) == 0: if len(test_results) == 0:
raise Exception("Empty results") raise Exception("Empty results")
@ -79,7 +74,7 @@ if __name__ == "__main__":
pr_info = PRInfo() pr_info = PRInfo()
gh = Github(get_best_robot_token()) gh = GitHub(get_best_robot_token())
rerun_helper = RerunHelper(gh, pr_info, NAME) rerun_helper = RerunHelper(gh, pr_info, NAME)
if rerun_helper.is_already_finished_by_status(): if rerun_helper.is_already_finished_by_status():
@ -111,7 +106,7 @@ if __name__ == "__main__":
report_url = upload_results( report_url = upload_results(
s3_helper, pr_info.number, pr_info.sha, test_results, additional_files, NAME s3_helper, pr_info.number, pr_info.sha, test_results, additional_files, NAME
) )
print("::notice ::Report url: {}".format(report_url)) print(f"::notice ::Report url: {report_url}")
post_commit_status(gh, pr_info.sha, NAME, description, state, report_url) post_commit_status(gh, pr_info.sha, NAME, description, state, report_url)
prepared_events = prepare_tests_results_for_clickhouse( prepared_events = prepare_tests_results_for_clickhouse(