diff --git a/src/pdal/pipeline.py b/src/pdal/pipeline.py index 60a181c0..e00b8c2d 100644 --- a/src/pdal/pipeline.py +++ b/src/pdal/pipeline.py @@ -217,7 +217,14 @@ def __or__(self, other: Union[Stage, Pipeline]) -> Pipeline: class InferableTypeStage(Stage): def __init__(self, filename: Optional[str] = None, **options: Any): if filename: - options["filename"] = filename + if isinstance(filename, dict): + if "path" not in filename: + raise ValueError(f"'path' is missing in the provided filespec: {filename}") + options["filename"] = filename + + else: + filespec = {'path':str(filename)} + options["filename"] = filespec super().__init__(**options) @property @@ -226,7 +233,15 @@ def type(self) -> str: return super().type except KeyError: filename = self._options.get("filename") - return str(self._infer_type(filename) if filename else "") + if isinstance(filename, dict): + if "path" not in filename: + raise ValueError(f"'path' is missing in the provided filespec: {filename}") + path = filename.get('path') + else: + path = str(filename) + + + return str(self._infer_type(path) if filename else "") _infer_type = staticmethod(lambda filename: "") diff --git a/test/test_pipeline.py b/test/test_pipeline.py index 46e0a18d..8760b1b5 100644 --- a/test/test_pipeline.py +++ b/test/test_pipeline.py @@ -3,7 +3,6 @@ import os import sys -from typing import List from itertools import product import numpy as np import pytest @@ -284,6 +283,19 @@ def test_infer_stage_type(self): assert pdal.Writer("foo.xxx").type == "" assert pdal.Reader().type == "" assert pdal.Writer().type == "" + assert pdal.Reader({"path": "foo.las"}).type == "readers.las" + assert pdal.Writer({"path": "foo.las"}).type == "writers.las" + assert pdal.Reader({"path": "foo.xxx"}).type == "" + assert pdal.Writer({"path": "foo.xxx"}).type == "" + assert pdal.Reader({}).type == "" + assert pdal.Writer({}).type == "" + + def test_filespec(self): + """Can transit filespecs""" + spec = {'path':'junk.las', 'headers':{'header1':'header_1', 'header2':'header_2'}, 'query':{'query1':'query_1', 'query2':'query_2'}} + assert pdal.Reader(spec).type == "readers.las" + assert pdal.Reader(spec).options['filename']['path'] == "junk.las" + assert pdal.Writer("foo.las").type == "writers.las" def test_streamable(self): """Can we distinguish streamable from non-streamable stages and pipeline"""