aboutsummaryrefslogtreecommitdiffstats
path: root/library/python/testing/custom_linter_util
diff options
context:
space:
mode:
authorsay <say@yandex-team.com>2023-02-14 17:24:43 +0300
committersay <say@yandex-team.com>2023-02-14 17:24:43 +0300
commite0094c4ad6964e11564777bc0d859c68d8aa9de2 (patch)
tree5d2ad1a4df88da1f74385888891a2a5f9fbbc3ef /library/python/testing/custom_linter_util
parent65a08c9fdece8dba50da8beb4d7c81447211dd45 (diff)
downloadydb-e0094c4ad6964e11564777bc0d859c68d8aa9de2.tar.gz
Migrate black linter on custom_lint pipeline
Diffstat (limited to 'library/python/testing/custom_linter_util')
-rw-r--r--library/python/testing/custom_linter_util/linter_params.py61
-rw-r--r--library/python/testing/custom_linter_util/reporter.py39
2 files changed, 100 insertions, 0 deletions
diff --git a/library/python/testing/custom_linter_util/linter_params.py b/library/python/testing/custom_linter_util/linter_params.py
new file mode 100644
index 0000000000..b82e04455b
--- /dev/null
+++ b/library/python/testing/custom_linter_util/linter_params.py
@@ -0,0 +1,61 @@
+import argparse
+import json
+from dataclasses import dataclass
+from typing import Optional
+
+
+@dataclass
+class LinterArgs:
+ source_root: str
+ project_path: str
+ output_path: str
+ depends: dict[str, str]
+ configs: list[str]
+ report_file: str
+ files: list[str]
+
+
+def get_params(raw_args: Optional[list[str]] = None) -> LinterArgs:
+ parser = argparse.ArgumentParser()
+ parser.add_argument("--params")
+ parser.add_argument("--source-root")
+ parser.add_argument("--project-path")
+ parser.add_argument("--output-path")
+ parser.add_argument("--depends", action="append")
+ parser.add_argument("--configs", action="append")
+ parser.add_argument("--report-file", default="-")
+ parser.add_argument("files", nargs="*")
+ args = parser.parse_args(raw_args)
+
+ if args.params:
+ with open(args.params) as f:
+ params = json.load(f)
+ source_root = params["source_root"]
+ project_path = params["project_path"]
+ output_path = params["output_path"]
+ depends = params.get("depends", {})
+ configs = params.get("configs", [])
+ report_file = params["report_file"]
+ files = params["files"]
+ else:
+ source_root = args.source_root
+ project_path = args.project_path
+ output_path = args.output_path
+ depends = {}
+ if args.depends:
+ for dep in args.depends:
+ rel_path, abs_path = dep.split(":", 1)
+ depends[rel_path] = abs_path
+ configs = args.configs if args.configs else []
+ report_file = args.report_file
+ files = args.files
+
+ return LinterArgs(
+ source_root=source_root,
+ project_path=project_path,
+ output_path=output_path,
+ depends=depends,
+ configs=configs,
+ report_file=report_file,
+ files=files,
+ )
diff --git a/library/python/testing/custom_linter_util/reporter.py b/library/python/testing/custom_linter_util/reporter.py
new file mode 100644
index 0000000000..8ae559bca0
--- /dev/null
+++ b/library/python/testing/custom_linter_util/reporter.py
@@ -0,0 +1,39 @@
+import json
+import sys
+from enum import Enum
+from typing import Optional
+
+
+class LintStatus(Enum):
+ GOOD = "GOOD"
+ FAIL = "FAIL"
+ SKIPPED = "SKIPPED"
+
+
+class LintReport():
+ def __init__(self):
+ self._report = {}
+
+ def add(self, file_name: str, status: LintStatus, message: str = "", elapsed: float = 0.0):
+ self._report[file_name] = {
+ "status": status.value,
+ "message": message,
+ "elapsed": elapsed,
+ }
+
+ def dump(self, report_file, pretty: Optional[bool] = None):
+ data = {
+ "report": self._report,
+ }
+ if report_file == "-":
+ if pretty is None:
+ pretty = True
+ self._do_dump(sys.stdout, data, pretty)
+ else:
+ with open(report_file, "w") as f:
+ self._do_dump(f, data, pretty)
+
+ @staticmethod
+ def _do_dump(dest, data, pretty):
+ indent = 4 if pretty else None
+ json.dump(data, dest, indent=indent)