symmetryinvestments / autowrap

Wrap existing D code for use in Python, Excel, C#
BSD 3-Clause "New" or "Revised" License
80 stars 16 forks source link

Make examples compile for newest python version #340

Closed Inkrementator closed 5 months ago

Inkrementator commented 6 months ago

Note: Unittests don't compile on my machine, but I think it's unrelated to my changes

    Building autowrap:pynih 0.8.1+commit.8.gcfe0764: building configuration [default]
../../../../.dub/packages/monty/0.0.4/monty/source/python/c.d-mixin-19684(19685,24): Error: forward reference to inferred return type of function call `Py_TYPE(_PyObject_CAST(arg0))`
../../../../.dub/packages/monty/0.0.4/monty/source/python/c.d-mixin-17252(17253,46): Error: template instance `python.c.Py_TYPE!(_object*)` error instantiating
pynih/source/autowrap/pynih/python/exception.d(35,25):        instantiated from here: `PyTuple_Check!(_object*)`
pynih/source/autowrap/pynih/python/object_.d(176,24): Error: template instance `python.c.PyDict_Check!(_object*)` error instantiating
Error /usr/bin/dmd failed with exit code 1.

And as in the commit msg: I only tested some cherrypicked examples, but they worked.

atilaneves commented 6 months ago

It doesn't work in CI either.

Inkrementator commented 5 months ago

dub test now works on my machine. Instead of what I did in e3b4c40 , I suggest that the test should just check if it finds "AttributeError" to be forward and backwards compatible with python upgrades.

make test still fails after setting python to version 3.11, with a ton of input errors

Inkrementator commented 5 months ago

And to make auditing f3d39e1 easier, here the steps to reproduce.

From git root:

fd dub.selections.json -X sed -Ei 's/("pyd": "0.14.)3"/\14/'

and from examples:

fd dub.sdl -X sed -i '/configuration "python38" {/ {
iconfiguration "python311" {
i\\    targetPath "lib/pyd"
i\\    lflags "-L$PYTHON_LIB_DIR"
i\\    dependency "autowrap:pyd" path="../../"
i\\    subConfiguration "autowrap:pyd" "python311"
i}
i
iconfiguration "python310" {
i\\    targetPath "lib/pyd"
i\\    lflags "-L$PYTHON_LIB_DIR"
i\\    dependency "autowrap:pyd" path="../../"
i\\    subConfiguration "autowrap:pyd" "python310"
i}
i
iconfiguration "python39" {
i\\    targetPath "lib/pyd"
i\\    lflags "-L$PYTHON_LIB_DIR"
i\\    dependency "autowrap:pyd" path="../../"
i\\    subConfiguration "autowrap:pyd" "python39"
i}
i
}'
Inkrementator commented 5 months ago

Note: To get make test to run, in addition to setting it to the right pythonversion, I have to set LD_LIBRARY_PATH="$PYTHONPATH" in the makefile rules.

edit: Done this in afac5dd

Inkrementator commented 5 months ago

All right, make test now runs on my machine with the following environment:

export DUB_CONFIGURATION=python311
export PYTHON_LIB_DIR=/lib/python3.11
export PYD_LIBPYTHON=python3.11
make test

I guess the one thing left now would be to update CI to actually test the different python versions, but I won't/ can't do that.

Inkrementator commented 5 months ago

CI fails because e3b4c40, it should work now.

Inkrementator commented 5 months ago

Sorry for all the back and forth, I'll set up the right python environments on the weekend.

atilaneves commented 5 months ago

CI is still red.

Inkrementator commented 5 months ago

I've set up a python 3.8 environment and can't reproduce it, it works on my machine.

My dmd version is v2.108.0, so different from the one set in CI.

In the CI report, the step "python env vars", it also sets LD_LIBRARY_PATH, so maybe I was overwriting it.

Inkrementator commented 5 months ago

I'm also not entirely sure I got the quoting right in d5f51f0 because I'm not sure if make has any special rules regarding variables and quoting. Works on my machine...