Skip to content

Commit

Permalink
Flake and typing fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ajfabbri committed Sep 18, 2024
1 parent 14b1b2e commit 79f4553
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
16 changes: 9 additions & 7 deletions interface_gen/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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 <namespace>.proto,
# which causes all except the last schema to be overwritten. Rename that
# workaround: avrotize func. above always names file
# <namespace>.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:
Expand All @@ -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()

Expand Down
8 changes: 5 additions & 3 deletions interface_gen/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit 79f4553

Please sign in to comment.