Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/+lazy-pyarrow-import.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Import `pyarrow` lazily in the line-delimited JSON importer so that `infrahubctl` commands other than `object load` no longer require the `ctl` extra (and its heavy `pyarrow` dependency) to be installed.
12 changes: 11 additions & 1 deletion infrahub_sdk/transfer/importer/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from pathlib import Path
from typing import TYPE_CHECKING, Any

import pyarrow.json as pa_json
import ujson
from rich.progress import Progress

Expand Down Expand Up @@ -53,6 +52,17 @@ def wrapped_task_output(self, start: str, end: str = "[green]done") -> Generator
self.console.print(f"{end}")

async def import_data(self, import_directory: Path, branch: str) -> None:
# pyarrow is a heavy, optional dependency used only to read the line-delimited JSON
# export. Import it lazily so the rest of infrahubctl works without it being installed;
# only `infrahubctl object load` reaches this code path.
try:
import pyarrow.json as pa_json # noqa: PLC0415
except ModuleNotFoundError as exc:
raise ModuleNotFoundError(
"Loading objects requires pyarrow, install the 'ctl' extra of the infrahub-sdk "
"package, `pip install 'infrahub-sdk[ctl]'` or run `uv sync --extra ctl`."
) from exc

node_file = import_directory / "nodes.json"
relationship_file = import_directory / "relationships.json"
for f in (node_file, relationship_file):
Expand Down