-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
BUG: Fix generated sources not being included as dependencies in cython transpilation #11000
Conversation
Codecov Report
@@ Coverage Diff @@
## master #11000 +/- ##
===========================================
+ Coverage 41.39% 68.81% +27.41%
===========================================
Files 207 414 +207
Lines 44609 90222 +45613
Branches 9159 20690 +11531
===========================================
+ Hits 18466 62086 +43620
+ Misses 24382 23467 -915
- Partials 1761 4669 +2908
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Thanks for looking into this.
I would write a test case in |
Thanks for working on this @lithomas1! I've started to look at this to see what it does, using the $ # first use Meson 0.64.0
$ meson setup build
$ ninja -C build -t inputs numpy/random/_generator.cpython-39-x86_64-linux-gnu.so.p/numpy/random/_generator.pyx.c
../numpy/random/_generator.pyx
numpy/random/_generator.pyx
# That shows the problem - the transpile step depends on nothing.
# Install Meson from this PR and repeat:
$ ninja -C build -t inputs numpy/random/_generator.cpython-39-x86_64-linux-gnu.so.p/numpy/random/_generator.pyx.c
../numpy/__init__.cython-30.pxd
../numpy/__init__.pxd
../numpy/__init__.py
../numpy/core/code_generators/generate_numpy_api.py
../numpy/core/code_generators/generate_umath.py
../numpy/core/src/npymath/npy_math_internal.h.src
../numpy/random/__init__.pxd
../numpy/random/__init__.py
../numpy/random/_bounded_integers.pxd.in
../numpy/random/_common.pxd
../numpy/random/_generator.pyx
../numpy/random/bit_generator.pxd
../numpy/random/c_distributions.pxd
/home/rgommers/code/numpy/numpy/_build_utils/process_src_template.py
/home/rgommers/code/numpy/numpy/_build_utils/tempita.py
/home/rgommers/mambaforge/envs/numpy-dev/bin/python3.9
numpy/__init__.cython-30.pxd
numpy/__init__.pxd
numpy/__init__.py
numpy/core/__multiarray_api.h
numpy/core/__umath_generated.c
numpy/core/npy_math_internal.h
numpy/random/__init__.pxd
numpy/random/__init__.py
numpy/random/_bounded_integers.pxd
numpy/random/_common.pxd
numpy/random/_generator.pyx
numpy/random/bit_generator.pxd
numpy/random/c_distributions.pxd So we went from the transpile step depending on nothing to it depending on everything it needs to. And it does not depend on the static libraries that are linked into the final
I'm not quite sure I understand if that tests the change here correctly. All that does is
Looking at the source code for test case 129 doesn't help me. If we're building the final |
Ah wait, I didn't realize we could build a single target directly:
That's going to turn up more dependency issues for me that may need fixing, if I build all intermediate targets one by one. |
If I may ask another random question. I did some searching, but couldn't turn up a prebaked tool/script to do something like this:
That would be fairly slow, but it only needs to run once in a while, and would smoke out a bunch of potential issues. Not too difficult to write from scratch, but would I be reinventing a wheel there? |
I'd probably do Since ninja 1.11, you can do I've pondered writing a smoketest script for Meson and making it invokable via |
Nice, thanks @eli-schwartz. I'll give it a go for Cython then. Depfiles won't cut it there, because the issues are mostly coming in because of Cython's output depending on the whole source tree (including |
Sorry, I'm not following here. Just to be clear, this does work for numpy/scipy? |
Yes, this does fix a race condition for |
Circling back to this - this is a fairly minimal patch, that fixes issues in the Pandas and NumPy builds and seems correct from the dependency graph. The change doesn't affect SciPy. Testing with SciPy after changing how it uses Cython is quite low on my prio list and doesn't seem needed. Is there a reason not to merge this? |
Adding a test case, IIRC. |
3bff8bb
to
5d512b9
Compare
@eli-schwartz This is ready now. |
unittests/allplatformstests.py
Outdated
target = next(filter(lambda t: "includestuff.cpython" in t["name"], targets)) # Only will be one target | ||
# Meson introspection doesn't give us the pyx.c target :( | ||
# This is really hacky | ||
name = target["target_sources"][0]["generated_sources"][0] |
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 guess in theory you could also check to see which targets have a target_sources -> generated_sources ending in "includestuff.pyx.c"? Not sure whether this matters.
I guess it hardcodes cpython but we don't currently run tests for anything else.
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. I've updated this.
mesonbuild/backend/ninjabackend.py
Outdated
# TODO: introspection? | ||
cython_sources.append(output) | ||
else: | ||
generated_sources[ssrc] = mesonlib.File.from_built_file(gen.get_subdir(), ssrc) | ||
# Following logic in L883-900 where we determine whether to add generated source | ||
# as a header(order-only) dep to the .so compilation rule | ||
if not self.environment.is_source(ssrc) and not self.environment.is_object(ssrc) and not self.environment.is_library(ssrc) and not modules.is_module_library(ssrc): |
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.
This line is very long and should really be broken up.
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.
Split it into four, hopefully the style is good.
The file passes flake8 FWIW, but meson's flake8 config seems to be very lax.
941eb65
to
164a76d
Compare
164a76d
to
def41be
Compare
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.
Thanks! Looks great.
Generated graph looks correct.
xref #8961.
(Note: This is for the .pyx-> c phase for a target for pandas)
In pandas, we are including the generated .pxi as sources, but I also tested using them as dependencies, and it still works.
I'm not sure how to test this, though.
Ideas could be write test cases and compare against a golden ninja.build file, or running ninja directly against the pyx target to make sure the deps work correctly (not sure how to hook into the build system to invoke ninja directly)
cc @rgommers @eli-schwartz @xclaesse (Sorry for pinging so close to the weekend).