Skip to content

Commit 2a520c5

Browse files
authored
should use opaque types (#10)
* --force-reinstall * fix opaque types
1 parent 7b159ac commit 2a520c5

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ test_in_linux:
9797

9898
PYTHON ?= python3
9999
python_install:
100-
$(PYTHON) setup.py install
100+
$(PYTHON) setup.py install --force
101101
python_build:
102102
$(PYTHON) setup.py bdist_wheel
103103
python_sdist:

src/pybind11_geojson.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@
1313
#include <fstream>
1414
#include <iostream>
1515

16+
// https://pybind11.readthedocs.io/en/stable/advanced/cast/stl.html?highlight=stl#making-opaque-types
17+
PYBIND11_MAKE_OPAQUE(mapbox::geojson::geometry_collection::container_type);
18+
PYBIND11_MAKE_OPAQUE(mapbox::geojson::multi_line_string::container_type);
19+
PYBIND11_MAKE_OPAQUE(mapbox::geojson::multi_point::container_type);
20+
PYBIND11_MAKE_OPAQUE(mapbox::geojson::multi_polygon::container_type);
21+
PYBIND11_MAKE_OPAQUE(mapbox::geojson::polygon::container_type);
22+
PYBIND11_MAKE_OPAQUE(mapbox::geojson::value::array_type);
23+
PYBIND11_MAKE_OPAQUE(mapbox::geojson::value::object_type);
24+
PYBIND11_MAKE_OPAQUE(std::vector<mapbox::geojson::feature>);
25+
1626
namespace cubao
1727
{
1828
namespace py = pybind11;
@@ -49,9 +59,6 @@ void bind_geojson(py::module &geojson)
4959
//
5060
;
5161

52-
// TODO
53-
// py::class_<mapbox::geojson::multi_point::container_type>(geojson,
54-
// "coordinates")
5562
py::bind_vector<mapbox::geojson::multi_point::container_type>(geojson,
5663
"coordinates")
5764
.def(
@@ -656,7 +663,6 @@ void bind_geojson(py::module &geojson)
656663
//
657664
;
658665

659-
// fix bind_vector
660666
py::bind_vector<mapbox::geojson::multi_line_string::container_type>(
661667
geojson, "LineStringList", py::module_local());
662668

@@ -675,7 +681,6 @@ void bind_geojson(py::module &geojson)
675681
//
676682
;
677683

678-
// fix bind_vector
679684
py::bind_vector<mapbox::geojson::polygon::container_type>(
680685
geojson, "LinearRingList", py::module_local());
681686
py::class_<mapbox::geojson::polygon,

tests/test_geobuf.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,10 @@ def test_geojson_multi_point():
356356
if idx == 1:
357357
assert pt() == [7, 8, 9]
358358
g1.append(geojson.Point())
359-
assert len(g1) == 2 # append not working, for now
359+
assert len(g1) == 3 # append works now
360360
g1.push_back(geojson.Point())
361-
assert len(g1) == 3 # push_back works now
361+
assert len(g1) == 4 # push_back works now
362+
g1.pop_back()
362363
g1.pop_back()
363364
assert len(g1) == 2
364365

@@ -418,9 +419,8 @@ def test_geojson_line_string():
418419
assert len(g1) == 0
419420
assert g1 == g1.clear()
420421

421-
# TODO, fix append
422-
g1.append(geojson.Point(1, 2)) # don't use append for now
423-
assert len(g1) == 0
422+
g1.append(geojson.Point(1, 2))
423+
assert len(g1) == 1
424424

425425

426426
def test_geojson_multi_line_string():
@@ -735,11 +735,10 @@ def test_geobuf_from_geojson():
735735

736736

737737
def test_geojson_feature():
738-
return
739738
feature = geojson.Feature()
740739
props = feature.properties()
741740
assert not isinstance(props, dict)
742-
assert isinstance(props, int)
741+
assert isinstance(props, geojson.value.object_type)
743742

744743

745744
def pytest_main(dir: str, *, test_file: str = None):

0 commit comments

Comments
 (0)