Skip to content

Commit dfdc448

Browse files
authored
support pathlib.Path as option types for 'filename' #148 (#149)
1 parent 73b4690 commit dfdc448

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

pdal/libpdalpython.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <pybind11/pybind11.h>
22
#include <pybind11/stl.h>
33
#include <pybind11/numpy.h>
4+
#include <pybind11/stl/filesystem.h>
45
#include <iostream>
56

67
#include <pdal/pdal_config.hpp>
@@ -108,6 +109,16 @@ namespace pdal {
108109
return dims;
109110
};
110111

112+
std::string getReaderDriver(std::filesystem::path const& p)
113+
{
114+
return StageFactory::inferReaderDriver(p.string());
115+
}
116+
117+
std::string getWriterDriver(std::filesystem::path const& p)
118+
{
119+
return StageFactory::inferWriterDriver(p.string());
120+
}
121+
111122
using pdal::python::PipelineExecutor;
112123
using pdal::python::StreamableExecutor;
113124

@@ -286,8 +297,8 @@ namespace pdal {
286297
m.def("getDrivers", &getDrivers);
287298
m.def("getOptions", &getOptions);
288299
m.def("getDimensions", &getDimensions);
289-
m.def("infer_reader_driver", &StageFactory::inferReaderDriver);
290-
m.def("infer_writer_driver", &StageFactory::inferWriterDriver);
300+
m.def("infer_reader_driver", &getReaderDriver);
301+
m.def("infer_writer_driver", &getWriterDriver);
291302
};
292303

293304
}; // namespace pdal

pdal/pipeline.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import Any, Container, Dict, Iterator, List, Optional, Sequence, Union, cast
66

77
import numpy as np
8+
import pathlib
89

910
try:
1011
from meshio import Mesh
@@ -142,6 +143,9 @@ def toJSON(self) -> str:
142143
for stage in stages:
143144
stage2tag[stage] = stage.tag or _generate_tag(stage, stage2tag.values())
144145
options = stage.options
146+
for option in options:
147+
if isinstance(options[option], pathlib.Path):
148+
options[option] = str(options[option])
145149
options["tag"] = stage2tag[stage]
146150
options["type"] = stage.type
147151
inputs = _get_input_tags(stage, stage2tag)

test/test_pipeline.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import pytest
88

99
import pdal
10+
import pathlib
1011

1112
DATADIRECTORY = os.path.join(os.path.dirname(__file__), "data")
1213

@@ -487,6 +488,14 @@ def test_meshio(self, filename):
487488
assert len(triangles) == 134
488489
assert triangles[0][0] == 29
489490

491+
def test_pathlib(self):
492+
"""Can we build a pipeline using pathlib.Path as the filenames"""
493+
path = pathlib.Path("test/data/autzen-utm.las")
494+
read = pdal.Reader(path)
495+
pipeline = read.pipeline()
496+
pipeline.execute()
497+
498+
490499
class TestDataFrame:
491500

492501
@pytest.mark.skipif(

0 commit comments

Comments
 (0)