New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Cython 3 compatibility #2345
Conversation
Shoot:
Not sure what's going on here. |
Just a note. Maybe you can try to do migration in smaller steps. you can introduce |
Can you reproduce the failure locally? I'd suggest putting the tests into verbose mode ( |
Ok so I tested locally and the results are below. The same 2 tests failed but with different failures in one of the tests (race condition maybe). I think the Cython 3+ local failures
Cython <3 local failures
|
Good news (?), I get the same failures if I add the I'm unable to use this directive with master and building Cython 3 due to what I think is a bug in Cython 3. I'll post on the related issue about that. |
That looks like an exception is not passed correctly back through the HDF5 code. In the first example, it should fail to open the file (with the `test_exception_open` should get an exception with a traceback like this
|
Thanks @takluyver. Tests pass locally (Ubuntu) now that get_eof is except -1. Let's see how CI feels. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2345 +/- ##
=======================================
Coverage 89.53% 89.53%
=======================================
Files 17 17
Lines 2380 2380
=======================================
Hits 2131 2131
Misses 249 249 ☔ View full report in Codecov by Sentry. |
CI is all happy. The only other thing I can think of that I've had trouble with in my own projects is GIL access magically being added. However, in my cases this was due to poor error handling. h5py seems like it has that pretty under control and explicit nogil/gil definitions. Let me know if you want me to change anything or discuss something further. |
Hm I tried using this branch with my own project's unstable CI (building with Cython 3) and I get a compilation error. This is using HDF5 1.14.2 from conda-forge:
Edit: Ah this might be a numpy 2.0 incompatibility. |
I'm going to add some changes to fix numpy 2.0 compatibility. I wanted to add a nightly wheel environment, but I'm not a tox expert so not sure how to adapt it. I also see there is an (unused?) nightly environment already. Just in case I'm missing something I didn't want to start. |
Thanks! For future reference, I think two things like these (Cython 3.0 & Numpy 2.0 compatibility) are big enough to be two separate PRs, but now that they're both here, let's go with it. We have testing with pre-release versions already, but Numpy doesn't have a pre-release on PyPI yet. They say that they will have an RC at least 6 weeks before the final release, and I assume that will be on PyPI, so we can test then. That makes more sense to me than testing with nightly builds, which may well mean effort is spent fixing things that are changed again before release. However, the Numpy 2.0 status issue also says that it will break the C ABI. So for the near future, we're probably going to want to require |
Yeah I went back and forth on it. I ended up just being lazy given how small the change ended up being, but yeah understood. Thanks. For |
It's still possible for projects to test that, albeit a bit more effort to override h5py's requirement. Hopefully once there's a Numpy RC out, we can figure out what's needed for compatibility and remove the restriction again.
Unfortunately, in many scenarios, yes, that will happen. But I hope making it clear in the metadata for the latest version will help people understand when they manually investigate. |
Do you want me to make those changes here? |
pyproject.toml
Outdated
@@ -1,6 +1,6 @@ | |||
[build-system] | |||
requires = [ | |||
"Cython >=0.29.31,<1", | |||
"Cython >=3", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this actually no longer work with Cython 3.0, or did you just change this to ensure it's using a newer version on CI?
I don't think it's a problem if we require a recent version of Cython, but I'd like to check that if it really doesn't work on Cython 0.x any more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is fine on older Cython's for the syntax used in this PR. I've been doing this change in my own projects to avoid inconsistent builds. I haven't seen any major troubles between different builds beyond some Cython 3 bugs that were fixed. Just a little scared to let it choose whatever. Not a strong opinion on my part as a non-maintainer of this project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh! Maybe this should set a limit (not sure what to) since Cython is deprecating the IF
compiler condition (or whatever it is called in Cython-land). I'm not sure if a version has been set when it will actually be removed, but I also know people are still working on the best suggestions for migrating away from it (literal C code, macros, etc).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Let's put an upper bound of <4
on it, in the hope that actually removing IF
would trigger another major version. Last I heard, the warnings about it were being turned off for now while migration paths are worked out, so I don't think removal is imminent 🤞 .
And if the syntax still works on 0.29.x, let's leave the lower bound as it is for now. Although I don't think we actually test building with older Cythons, so it may break without us noticing. 🤷 Testing at the intersection of so many big dependencies (HDF5, Numpy, Python, Cython) is kind of a headache.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if the syntax still works on 0.29.x, let's leave the lower bound as it is for now
Leave it as it is in master
or leave it as it is in this PR? I'll assume 0.29 included.
I've done a separate PR (#2349) to restrict the Numpy requirement for now, so don't worry about that in this PR. |
Thanks @djhoese ! 🍪 |
h5py/h5py#2345 Signed-off-by: wangjiezhe <wangjiezhe@gmail.com>
Thank you @djhoese ! |
Closes #2268.
This is a first step in Cython 3 compatibility. This is based on a branch started by @takluyver. The basic idea so far is that functions needed to be defined with
except X
ornoexcept
to define how errors are handled. The complication was in h5py/h5fd.pyx which casts the h5py version of the file functions (which use a wrapper struct) to match the HDF5 version of the function. Due to what I think is a bug in Cython 3, you can't include anexcept X
statement in your casting so as suggested on the Cython mailing list I created ctypedefs for every function pointer that needed one.TODO:
Note the alternative suggested by da-woods (not tagging here to not be annoying) in the above mentioned issue of just specifying the Cython option to force the old behavior.
#2268 (comment)
Example of performance warning
List of performance warnings or similar warnings