Skip to content

Commit fd1e922

Browse files
authored
harden getMetadata and related calls from getting non-utf-8 'json' (#140)
* harden getMetadata and related calls from getting non-utf-8 'json' from PDAL * whoops * lern2type * py.test no longer always available on conda-forge packages * editable install * arg order * no editable * explicit pytest install * ditch 3.7 and 3.8 * pip install --upgrade --force-reinstall pytest * shut off embed for now * test fixes * turn on embed tests * update pypa/gh-action-pypi-publish@release/v1
1 parent 88f548e commit fd1e922

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
fail-fast: true
2525
matrix:
2626
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
27-
python-version: ['3.7', '3.8', '3.9', '3.10']
27+
python-version: ['3.9', '3.10', '3.11']
2828

2929
steps:
3030
- name: Check out python-pdal
@@ -50,6 +50,9 @@ jobs:
5050
working-directory: ./plugins
5151
run: pip install .
5252

53+
- name: Install pytest
54+
run: pip install --upgrade --force-reinstall pytest
55+
5356
- name: Test
5457
run: |
5558
export PDAL_DRIVER_PATH=$(python -c "import os, skbuild; print(os.path.join('plugins', skbuild.constants.SKBUILD_DIR(), 'cmake-build'))")
@@ -87,7 +90,7 @@ jobs:
8790
tree ./dist
8891
8992
- name: Publish package
90-
uses: pypa/gh-action-pypi-publish@master
93+
uses: pypa/gh-action-pypi-publish@release/v1
9194
if: github.event_name == 'release' && github.event.action == 'published'
9295
with:
9396
user: __token__

pdal/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "3.2.0"
1+
__version__ = "3.2.1"
22
__all__ = ["Pipeline", "Stage", "Reader", "Filter", "Writer", "dimensions", "info"]
33

44
from . import libpdalpython

pdal/libpdalpython.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,9 @@ namespace pdal {
134134
MetadataNode root = (StreamableExecutor::getMetadata()).clone("metadata");
135135
pdal::Utils::toJSON(root, strm);
136136

137-
py::str pystring(strm.str());
138-
pystring.attr("strip");
137+
138+
py::bytes pybytes(strm.str());
139+
py::str pystring ( pybytes.attr("decode")("utf-8", "ignore"));
139140

140141
py::object j;
141142
j = json.attr("loads")(pystring);
@@ -182,7 +183,9 @@ namespace pdal {
182183
py::gil_scoped_acquire acquire;
183184
py::object json = py::module_::import("json");
184185

185-
py::str pystring(getExecutor()->getQuickInfo());
186+
py::bytes pybytes(getExecutor()->getQuickInfo());
187+
188+
py::str pystring ( pybytes.attr("decode")("utf-8", "ignore"));
186189
pystring.attr("strip");
187190

188191
py::object j;
@@ -193,7 +196,16 @@ namespace pdal {
193196
}
194197

195198
py::object getMetadata() {
196-
return py::module_::import("json").attr("loads")(getExecutor()->getMetadata());
199+
py::object json = py::module_::import("json");
200+
201+
py::bytes pybytes(getExecutor()->getMetadata());
202+
py::str pystring ( pybytes.attr("decode")("utf-8", "ignore"));
203+
204+
py::object j;
205+
j = json.attr("loads")(pystring);
206+
207+
return j;
208+
197209
}
198210

199211
py::object getSchema() {

test/test_pipeline.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def get_pipeline(filename):
3434
def test_dimensions():
3535
"""Ask PDAL for its valid dimensions list"""
3636
dims = pdal.dimensions
37-
assert 71 < len(dims) < 120
37+
assert 71 < len(dims) < 122
3838

3939

4040
class TestPipeline:
@@ -500,6 +500,10 @@ def test_fetch(self):
500500
df = p.get_dataframe(0)
501501
assert df.size == 17040
502502

503+
@pytest.mark.skipif(
504+
not pdal.pipeline.DataFrame,
505+
reason="pandas is not available",
506+
)
503507
def test_load(self):
504508
r = pdal.Reader(os.path.join(DATADIRECTORY,"autzen-utm.las"))
505509
p = r.pipeline()

0 commit comments

Comments
 (0)