Fix compatibility with Cython >= 3.1 #269
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello, I'm one of the Cython maintainers on Fedora.
When doing an impact test for updating from Cython 3.0.12 to 3.1.2, pygrib failed to build so I tried using #266. While the package built, various tests failed:
Snippet of failed tests
File "/builddir/build/BUILD/pygrib-2.1.6-build/pygrib-2.1.6-tmp-test/test/test.py", line 98, in main.test
Failed example:
selgrbs = grbindx(name='Minimum temperature',level=2,typeOfLevel='heightAboveGround')
Exception raised:
Traceback (most recent call last):
File "<doctest main.test[36]>", line 1, in
selgrbs = grbindx(name='Minimum temperature',level=2,typeOfLevel='heightAboveGround')
File "src/pygrib/_pygrib.pyx", line 1879, in pygrib._pygrib.index.call
File "src/pygrib/_pygrib.pyx", line 1932, in pygrib._pygrib.index.select
TypeError: an integer is required
Trying:
for grb in selgrbs: grb
Expecting:
1:Minimum temperature:K (instant):regular_gg:heightAboveGround:level 2 m:fcst time 108-120 hrs:from 200402291200
File "/builddir/build/BUILD/pygrib-2.1.6-build/pygrib-2.1.6-tmp-test/test/test.py", line 99, in main.test
Failed example:
for grb in selgrbs: grb
Exception raised:
Traceback (most recent call last):
File "<doctest main.test[37]>", line 1, in
for grb in selgrbs: grb
^^^^^^^
NameError: name 'selgrbs' is not defined
Trying:
selgrbs = grbindx(name='Maximum temperature',level=2,typeOfLevel='heightAboveGround')
Expecting nothing
File "/builddir/build/BUILD/pygrib-2.1.6-build/pygrib-2.1.6-tmp-test/test/test.py", line 101, in main.test
Failed example:
selgrbs = grbindx(name='Maximum temperature',level=2,typeOfLevel='heightAboveGround')
Exception raised:
Traceback (most recent call last):
File "<doctest main.test[38]>", line 1, in
selgrbs = grbindx(name='Maximum temperature',level=2,typeOfLevel='heightAboveGround')
File "src/pygrib/_pygrib.pyx", line 1879, in pygrib._pygrib.index.call
File "src/pygrib/_pygrib.pyx", line 1932, in pygrib._pygrib.index.select
TypeError: an integer is required
Trying:
for grb in selgrbs: grb
Expecting:
1:Maximum temperature:K (instant):regular_gg:heightAboveGround:level 2 m:fcst time 108-120 hrs:from 200402291200
File "/builddir/build/BUILD/pygrib-2.1.6-build/pygrib-2.1.6-tmp-test/test/test.py", line 102, in main.test
Failed example:
for grb in selgrbs: grb
Exception raised:
Traceback (most recent call last):
File "<doctest main.test[39]>", line 1, in
for grb in selgrbs: grb
^^^^^^^
NameError: name 'selgrbs' is not defined
Trying:
grbindx.write('flux.grb.idx') # save the index
Expecting nothing
ok
Trying:
grbindx.close()
Expecting nothing
ok
Trying:
grbindx = pygrib.index('flux.grb.idx')
Expecting nothing
ok
Trying:
selgrbs = grbindx(name='Minimum temperature',level=2,typeOfLevel='heightAboveGround')
Expecting nothing
File "/builddir/build/BUILD/pygrib-2.1.6-build/pygrib-2.1.6-tmp-test/test/test.py", line 109, in main.test
Failed example:
selgrbs = grbindx(name='Minimum temperature',level=2,typeOfLevel='heightAboveGround')
Exception raised:
Traceback (most recent call last):
File "<doctest main.test[43]>", line 1, in
selgrbs = grbindx(name='Minimum temperature',level=2,typeOfLevel='heightAboveGround')
File "src/pygrib/_pygrib.pyx", line 1879, in pygrib._pygrib.index.call
File "src/pygrib/_pygrib.pyx", line 1932, in pygrib._pygrib.index.select
TypeError: an integer is required
Trying:
for grb in selgrbs: grb
Expecting:
1:Minimum temperature:K (instant):regular_gg:heightAboveGround:level 2 m:fcst time 108-120 hrs:from 200402291200
File "/builddir/build/BUILD/pygrib-2.1.6-build/pygrib-2.1.6-tmp-test/test/test.py", line 110, in main.test
Failed example:
for grb in selgrbs: grb
Exception raised:
Traceback (most recent call last):
File "<doctest main.test[44]>", line 1, in
for grb in selgrbs: grb
^^^^^^^
NameError: name 'selgrbs' is not defined
Trying:
selgrbs = grbindx(name='Maximum temperature',level=2,typeOfLevel='heightAboveGround')
Expecting nothing
File "/builddir/build/BUILD/pygrib-2.1.6-build/pygrib-2.1.6-tmp-test/test/test.py", line 112, in main.test
Failed example:
selgrbs = grbindx(name='Maximum temperature',level=2,typeOfLevel='heightAboveGround')
Exception raised:
Traceback (most recent call last):
File "<doctest main.test[45]>", line 1, in
selgrbs = grbindx(name='Maximum temperature',level=2,typeOfLevel='heightAboveGround')
File "src/pygrib/_pygrib.pyx", line 1879, in pygrib._pygrib.index.call
File "src/pygrib/_pygrib.pyx", line 1932, in pygrib._pygrib.index.select
TypeError: an integer is required
Trying:
for grb in selgrbs: grb
Expecting:
1:Maximum temperature:K (instant):regular_gg:heightAboveGround:level 2 m:fcst time 108-120 hrs:from 200402291200
File "/builddir/build/BUILD/pygrib-2.1.6-build/pygrib-2.1.6-tmp-test/test/test.py", line 113, in main.test
Failed example:
for grb in selgrbs: grb
Exception raised:
Traceback (most recent call last):
File "<doctest main.test[46]>", line 1, in
for grb in selgrbs: grb
^^^^^^^
NameError: name 'selgrbs' is not defined
Trying:
grbindx.close()
Expecting nothing
ok
Trying:
grb = selgrbs[0]
Expecting nothing
File "/builddir/build/BUILD/pygrib-2.1.6-build/pygrib-2.1.6-tmp-test/test/test.py", line 117, in main.test
Failed example:
grb = selgrbs[0]
Exception raised:
Traceback (most recent call last):
File "<doctest main.test[48]>", line 1, in
grb = selgrbs[0]
^^^^^^^
NameError: name 'selgrbs' is not defined
Trying:
grb
Expecting:
1:Maximum temperature:K (instant):regular_gg:heightAboveGround:level 2 m:fcst time 108-120 hrs:from 200402291200
File "/builddir/build/BUILD/pygrib-2.1.6-build/pygrib-2.1.6-tmp-test/test/test.py", line 118, in main.test
Failed example:
grb
Expected:
1:Maximum temperature:K (instant):regular_gg:heightAboveGround:level 2 m:fcst time 108-120 hrs:from 200402291200
Got:
4:Minimum temperature:K (instant):regular_gg:heightAboveGround:level 2 m:fcst time 108-120 hrs:from 200402291200
Trying:
data = grb['values'] # 'values' returns the data
Expecting nothing
ok
It seems as if #266 did not have the intended effects, at least on our OS. However an appropriate fix would be to remove the mentions of "long" as it was only there to support Python 2 and it was removed in Cython 3.1.
This PR makes pygrib compile with Cython 3.1.2 and all the tests pass. It works for lower Cython versions as well.
See also: cython/cython#5830 and kivy/pyjnius#756
Fixes #265