From 79f4553a611a143c255de3e21bc7b87d88af91bc Mon Sep 17 00:00:00 2001 From: Aaron Fabbri Date: Wed, 18 Sep 2024 23:58:13 +0000 Subject: [PATCH] Flake and typing fixes --- interface_gen/generate.py | 16 +++++++++------- interface_gen/toolchain.py | 8 +++++--- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/interface_gen/generate.py b/interface_gen/generate.py index f1ff090..f2320a6 100644 --- a/interface_gen/generate.py +++ b/interface_gen/generate.py @@ -46,7 +46,8 @@ def find_in_path(self, path: str | None = None) -> 'Schemas': self.schemas = list(start_path.rglob("*.avsc")) return self - def from_avro_idl(self, env: dict[str,str], avro_cmd: list[str], output_dir: Path) -> 'Schemas': + def from_avro_idl(self, env: dict[str, str], avro_cmd: list[str], + output_dir: Path) -> 'Schemas': """ Generate all schemas from main Avro IDL files, and select all schemas for future operations on this object. """ protocol_path = self.proto_dir @@ -56,7 +57,7 @@ def from_avro_idl(self, env: dict[str,str], avro_cmd: list[str], output_dir: Pat version_dir = avdl.parent.name sdir = output_dir / version_dir / "schema" subprocess.check_call(avro_cmd + [str(avdl), str(sdir)], env=env) - return self.find_in_path(output_dir) + return self.find_in_path(str(output_dir)) # --> Action methods @@ -67,8 +68,9 @@ def gen_proto3(self): pb_dir.mkdir(parents=True, exist_ok=True) print(f"--> Generating proto3 for {str(schema_file)} in {pb_dir}") convert_avro_to_proto(schema_file, pb_dir) - # workaround: avrotize func. above always names file .proto, - # which causes all except the last schema to be overwritten. Rename that + # workaround: avrotize func. above always names file + # .proto, which causes all except the last schema to be + # overwritten. Rename that # output file here, until we can fix the avrotize lib. ns = namespace(schema_file) if ns: @@ -86,15 +88,15 @@ def main(): Output will be written to the output directory (-o): Avro schemas, proto3 definitions, markdown documentation. """ - parser = argparse.ArgumentParser(prog="generate.py", - description="Generate docs and definitions from Avro IDL.", + desc = "Generate docs and definitions from Avro IDL." + parser = argparse.ArgumentParser(prog="generate.py", description=desc, epilog=epilog) parser.add_argument('-p', '--protocol-dir', help="Path w/ Avro IDL files in version subdirs") parser.add_argument('-o', '--output-dir', required=True, help="Path where to generate markdown docs") parser.add_argument('-i', '--install-toolchain', - help="(deprecated: We always try to install toolchain)", + help="(deprecated: always attempts toolchain install)", action="store_true") args = parser.parse_args() diff --git a/interface_gen/toolchain.py b/interface_gen/toolchain.py index 26972c3..7956f72 100644 --- a/interface_gen/toolchain.py +++ b/interface_gen/toolchain.py @@ -62,7 +62,7 @@ def install_avro_tools(target_dir: Path): download_file(url, target_dir) -def java_env(java_path: Path) -> list[str]: +def java_env(java_path: Path) -> dict[str, str]: """ Return environment with path, etc. set for java command """ bin_dir = java_path.parent java_home = bin_dir.parent @@ -73,16 +73,18 @@ def java_env(java_path: Path) -> list[str]: env['LD_LIBRARY_PATH'] = str(lib_dir) return env + # TODO make this file a class that retains toolchain paths, etc. and provides a # method to run the command -def create_avro_cmd(java_path: Path, target_dir: Path) -> (dict[str, str], list[str]): +def create_avro_cmd(java_path: Path, target_dir: Path) \ + -> tuple[dict[str, str], list[str]]: env = java_env(java_path) return (env, [str(java_path), '-jar', f'{target_dir}/{avro_jar(AVRO_VERSION)}', 'idl2schemata']) -def install() -> (dict[str, str], list[str]): +def install() -> tuple[dict[str, str], list[str]]: """ Install the toolchain and return the command needed to generate schemas and code. """ sdir = script_dir()