From d2599ec4e31d1c4255c9e0c023c63d3aca2ab8be Mon Sep 17 00:00:00 2001 From: Patrick Ogenstad Date: Thu, 17 Oct 2024 18:57:52 +0200 Subject: [PATCH] Fix typehints and remove type ignores for ctl.importer & exporter This change also highlighted an issue as we were still running aiorun to get the client. --- infrahub_sdk/ctl/exporter.py | 7 ++++--- infrahub_sdk/ctl/importer.py | 7 ++++--- pyproject.toml | 8 -------- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/infrahub_sdk/ctl/exporter.py b/infrahub_sdk/ctl/exporter.py index a292f23c..a6db1ecc 100644 --- a/infrahub_sdk/ctl/exporter.py +++ b/infrahub_sdk/ctl/exporter.py @@ -13,7 +13,7 @@ from .parameters import CONFIG_PARAM -def directory_name_with_timestamp(): +def directory_name_with_timestamp() -> str: right_now = datetime.now(timezone.utc).astimezone() timestamp = right_now.strftime("%Y%m%d-%H%M%S") return f"infrahubexport-{timestamp}" @@ -39,9 +39,10 @@ def dump( """Export nodes and their relationships out of the database.""" console = Console() - client = aiorun( - initialize_client(branch=branch, timeout=timeout, max_concurrent_execution=concurrent, retry_on_failure=True) + client = initialize_client( + branch=branch, timeout=timeout, max_concurrent_execution=concurrent, retry_on_failure=True ) + exporter = LineDelimitedJSONExporter(client, console=Console() if not quiet else None) try: aiorun(exporter.export(export_directory=directory, namespaces=namespace, branch=branch, exclude=exclude)) diff --git a/infrahub_sdk/ctl/importer.py b/infrahub_sdk/ctl/importer.py index b840f831..00627490 100644 --- a/infrahub_sdk/ctl/importer.py +++ b/infrahub_sdk/ctl/importer.py @@ -12,7 +12,7 @@ from .parameters import CONFIG_PARAM -def local_directory(): +def local_directory() -> Path: # We use a function here to avoid failure when generating the documentation due to directory name return Path().resolve() @@ -35,9 +35,10 @@ def load( """Import nodes and their relationships into the database.""" console = Console() - client = aiorun( - initialize_client(branch=branch, timeout=timeout, max_concurrent_execution=concurrent, retry_on_failure=True) + client = initialize_client( + branch=branch, timeout=timeout, max_concurrent_execution=concurrent, retry_on_failure=True ) + importer = LineDelimitedJSONImporter( client, InfrahubSchemaTopologicalSorter(), diff --git a/pyproject.toml b/pyproject.toml index 9915bd59..71da5d45 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -159,18 +159,10 @@ ignore_errors = true module = "infrahub_sdk.ctl.cli_commands" ignore_errors = true -[[tool.mypy.overrides]] -module = "infrahub_sdk.ctl.exporter" -ignore_errors = true - [[tool.mypy.overrides]] module = "infrahub_sdk.ctl.generator" ignore_errors = true -[[tool.mypy.overrides]] -module = "infrahub_sdk.ctl.importer" -ignore_errors = true - [[tool.mypy.overrides]] module = "infrahub_sdk.ctl.schema" ignore_errors = true