Skip to content

Commit 26c1cd9

Browse files
committed
support and test full filespec definitions
1 parent 6a15836 commit 26c1cd9

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

src/pdal/pipeline.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,11 @@ def __init__(self, filename: Optional[str] = None, **options: Any):
220220
if isinstance(filename, dict):
221221
if "path" not in filename:
222222
raise ValueError(f"'path' is missing in the provided filespec: {filename}")
223-
options["filename"] = filename["path"]
224-
else:
225223
options["filename"] = filename
224+
225+
else:
226+
filespec = {'path':str(filename)}
227+
options["filename"] = filespec
226228
super().__init__(**options)
227229

228230
@property
@@ -231,7 +233,15 @@ def type(self) -> str:
231233
return super().type
232234
except KeyError:
233235
filename = self._options.get("filename")
234-
return str(self._infer_type(filename) if filename else "")
236+
if isinstance(filename, dict):
237+
if "path" not in filename:
238+
raise ValueError(f"'path' is missing in the provided filespec: {filename}")
239+
path = filename.get('path')
240+
else:
241+
path = str(filename)
242+
243+
244+
return str(self._infer_type(path) if filename else "")
235245

236246
_infer_type = staticmethod(lambda filename: "")
237247

test/test_pipeline.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,13 @@ def test_infer_stage_type(self):
290290
assert pdal.Reader({}).type == ""
291291
assert pdal.Writer({}).type == ""
292292

293+
def test_filespec(self):
294+
"""Can transit filespecs"""
295+
spec = {'path':'junk.las', 'headers':{'header1':'header_1', 'header2':'header_2'}, 'query':{'query1':'query_1', 'query2':'query_2'}}
296+
assert pdal.Reader(spec).type == "readers.las"
297+
assert pdal.Reader(spec).options['filename']['path'] == "junk.las"
298+
assert pdal.Writer("foo.las").type == "writers.las"
299+
293300
def test_streamable(self):
294301
"""Can we distinguish streamable from non-streamable stages and pipeline"""
295302
rs = pdal.Reader(type="readers.las", filename="foo")

0 commit comments

Comments
 (0)