Skip to content

Commit

Permalink
Change lambda capture to capture-by-reference in example plugin.
Browse files Browse the repository at this point in the history
Build and run example plugin during Ubuntu "stress test" CI.

Closes #920
  • Loading branch information
molpopgen committed Apr 3, 2022
1 parent 895664a commit 838a90e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ jobs:
run: |
python -m pytest -n 2 tests
- name: Build and run examples/plugin
run: |
CPPFLAGS=$CPPFLAGS CC=$CC CXX=$CXX PYTHONPATH=. cmake examples/plugin
make
PYTHONPATH=. python examples/plugin/test_plugin.py
- name: Validate the sdist
run: |
python setup.py sdist
Expand Down
3 changes: 3 additions & 0 deletions doc/misc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Bug fixes
Issue {issue}`881`.
{user}`apragsdale`,
{user}`molpopgen`.
* Fix lambda capture in `examples/plugin/gvalue_recorder.cc`.
The previous code was not compatible with current versions of `pybind11`.
PR {pr}`921`. Issue {issue}`920`.

* User interface improvements

Expand Down
6 changes: 3 additions & 3 deletions examples/plugin/gvalue_recorder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

PYBIND11_MODULE(gvalue_recorder, m)
{
m.def("record_gvalue", [](pybind11::list l) {
m.def("record_gvalue", []() {
return pybind11::cpp_function(
[l](const fwdpy11::DiploidPopulation &pop,
fwdpy11::SampleRecorder &) {
[](const fwdpy11::DiploidPopulation &pop,
pybind11::list l) {
double mean_trait_value = 0.0;
for (auto &md : pop.diploid_metadata)
{
Expand Down
8 changes: 7 additions & 1 deletion examples/plugin/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@
rng = fwdpy11.GSLrng(42)

gvalues = []
r = gvalue_recorder.record_gvalue(gvalues)
rg = gvalue_recorder.record_gvalue()


def r(pop, _):
rg(pop, gvalues)


fwdpy11.evolvets(rng, pop, params, 100, r)

assert len(gvalues) == pop.generation, "Callback failure"
2 changes: 1 addition & 1 deletion requirements/conda_minimal_deps.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
intervaltree
pybind11==2.6.0
pybind11>=2.6.0
numpy
sparse
scipy
Expand Down

0 comments on commit 838a90e

Please sign in to comment.