Skip to content

Commit f161adc

Browse files
committed
validation of available pdal drivers using introspected data
1 parent ae11bb1 commit f161adc

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

pdal/pio.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import types
12
import json
3+
import subprocess
24
from functools import partial
35
from collections import defaultdict
46
from itertools import chain
@@ -7,18 +9,24 @@
79

810
import pdal
911

12+
PDAL_DRIVERS_JSON = subprocess.run(["pdal", "--drivers", "--showjson"], capture_output=True).stdout
13+
PDAL_DRIVERS = json.loads(PDAL_DRIVERS_JSON)
14+
modules = set([e["name"].split(".")[0] for e in PDAL_DRIVERS])
15+
16+
1017
DEFAULT_STAGE_PARAMS = defaultdict(dict)
1118
DEFAULT_STAGE_PARAMS.update({
1219
# TODO: add stage specific default configurations
1320
})
1421

22+
1523
class StageSpec(object):
1624
def __init__(self, prefix, **kwargs):
1725
self.prefix = prefix
18-
key = ".".join([self.prefix, kwargs.get("type", "")])
19-
self.spec = DEFAULT_STAGE_PARAMS[key].copy()
26+
self.key = ".".join([self.prefix, kwargs.get("type", "")])
27+
self.spec = DEFAULT_STAGE_PARAMS[self.key].copy()
2028
self.spec.update(kwargs)
21-
self.spec["type"] = key
29+
self.spec["type"] = self.key
2230
# NOTE: special case to support reading files without passing an explicit reader
2331
if (self.prefix == "readers") and kwargs.get("type") == "auto":
2432
del self.spec["type"]
@@ -30,6 +38,7 @@ def pipeline(self):
3038
return output
3139

3240
def __getattr__(self, name):
41+
assert name in dir(self), "Invalid or unsupported stage"
3342
return partial(self.__class__, self.prefix, type=name)
3443

3544
def __str__(self):
@@ -38,6 +47,10 @@ def __str__(self):
3847
def __add__(self, other):
3948
return self.pipeline + other
4049

50+
def __dir__(self):
51+
extra_keys = [e["name"][len(self.key):] for e in PDAL_DRIVERS if e["name"].startswith(self.key)]
52+
return super().__dir__() + [e for e in extra_keys if len(e) > 0]
53+
4154
def execute(self):
4255
return self.pipeline.execute()
4356

0 commit comments

Comments
 (0)