Skip to content

Commit

Permalink
Use --metadata=STDOUT to simplify pdal_execute_pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
olsen232 committed Aug 31, 2023
1 parent 28e14f1 commit 0d9d50d
Showing 1 changed file with 8 additions and 35 deletions.
43 changes: 8 additions & 35 deletions kart/point_cloud/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import json
from pathlib import Path
import tempfile

from kart import is_windows
from kart import subprocess_util as subprocess


Expand All @@ -15,37 +12,13 @@ def pdal_execute_pipeline(pipeline, *, env_overrides=None):
# NOTE: Kart itself doesn't currently use env_overrides, but don't remove it.
# PDAL uses environment variables for various purposes, and this is helpful for `kart ext-run` scripts.

if is_windows:
# On windows we can't keep the metadata file open while pdal writes to it:
with tempfile.NamedTemporaryFile(delete=False) as f_metadata:
metadata_path = Path(f_metadata.name)
output = subprocess.check_output(
["pdal", "pipeline", "--stdin", "--metadata=STDOUT"],
input=json.dumps(pipeline),
encoding="utf-8",
env_overrides=env_overrides,
)

subprocess.run(
["pdal", "pipeline", "--stdin", f"--metadata={metadata_path}"],
check=True,
input=json.dumps(pipeline),
encoding="utf-8",
capture_output=True,
env_overrides=env_overrides,
)
metadata = json.loads(output)

with metadata_path.open(encoding="utf-8") as f:
metadata = json.load(f)

metadata_path.unlink()
return metadata["stages"]

else:
with tempfile.NamedTemporaryFile() as f_metadata:

subprocess.run(
["pdal", "pipeline", "--stdin", f"--metadata={f_metadata.name}"],
check=True,
input=json.dumps(pipeline),
encoding="utf-8",
capture_output=True,
env_overrides=env_overrides,
)
f_metadata.seek(0)
metadata = json.load(f_metadata)
return metadata["stages"]
return metadata["stages"]

0 comments on commit 0d9d50d

Please sign in to comment.