GH-49397: [Python] Fix PYARROW_GENERATE_COVERAGE end-to-end flow#49475
GH-49397: [Python] Fix PYARROW_GENERATE_COVERAGE end-to-end flow#49475omertt27 wants to merge 1 commit intoapache:mainfrom
Conversation
raulcd
left a comment
There was a problem hiding this comment.
Thanks for the PR! this is currently not tackling the issue that was opened. We should validate whether the existing CMake option PYARROW_GENERATE_COVERAGE:
if(PYARROW_GENERATE_COVERAGE)
set(CYTHON_FLAGS "${CYTHON_FLAGS}" "-Xlinetrace=True")
endif()and
if(PYARROW_GENERATE_COVERAGE)
set_target_properties(${module_name} PROPERTIES COMPILE_DEFINITIONS
"CYTHON_TRACE=1;CYTHON_TRACE_NOGIL=1")
endif()
is working as intended when building PyArrow not add a different way of tackling coverage. If the intended way is not working we should remove it and then decide probably as a separate issue whether we want to add the ability to add coverage reports.
ffb0998 to
3c784ac
Compare
|
Hi @raulcd, Thanks for the feedback! I’ve updated the PR to focus only on validating and documenting the existing PYARROW_GENERATE_COVERAGE CMake option. The Python-side coverage hook changes have been reverted. All three files (.coveragerc, development.rst, building.rst) now reflect the correct workflow and documentation. Please let me know if this now addresses the original issue. Thanks |
|
@omertt27 did you confirm this runs locally? Would you recommend we add a CI check that coverage can be generated? |
|
hi @rok, I haven’t been able to fully test this locally because of some issues on macOS with Anaconda, which caused a few build errors. Adding a CI check to verify coverage generation could be helpful to ensure it works consistently across environments. |
|
@rok |
raulcd
left a comment
There was a problem hiding this comment.
Thanks @omertt27 for the PR! Currently the PR is adding great documentation but the original issue requires us to validate whether the PYARROW_GENERATE_COVERAGE flag is really working, we are not sure whether it still works, and for that we have to build PyArrow with PYARROW_GENERATE_COVERAGE=ON or PYARROW_GENERATE_COVERAGE=1 and validate it works as expected.
Let us know if we can help with your build issues to help with that validation.
…ent usage Validated that the existing CMake option PYARROW_GENERATE_COVERAGE works as intended: - The -Xlinetrace=True Cython flag correctly embeds __Pyx_TraceLine calls in the generated C++ code. - The CYTHON_TRACE=1 and CYTHON_TRACE_NOGIL=1 compile definitions correctly activate those trace points at runtime via Python's sys.settrace hook. - Running tests under 'coverage run' with the Cython.Coverage plugin (already configured in python/.coveragerc) correctly produces line-level coverage reports for .pyx source files. Changes: - python/.coveragerc: add [source], [branch], [report], and [html] sections so that 'coverage run' and 'coverage report' work out of the box without extra flags. - docs/source/developers/python/development.rst: add a 'Code Coverage' sub-section under 'Unit Testing' documenting the full end-to-end workflow (build with PYARROW_GENERATE_COVERAGE=ON, install coverage+Cython, run tests under coverage.py). Uses scikit-build-core env-var syntax. - docs/source/developers/python/building.rst: update the PYARROW_GENERATE_COVERAGE table entry with an accurate description of what the flag does and a cross-reference to the new usage section.
3c784ac to
e891d84
Compare
|
Can you share how was the validation? How do we know is working as expected? From what I understand you should see |
|
@raulcd ,I validated the mechanism using a minimal Cython module (test_mod.pyx) with just a single function:
*/ /* "test_mod.pyx":2
*/ The __Pyx_TraceLine hooks are only present when -Xlinetrace=True is passed. They are activated at runtime only when CYTHON_TRACE=1 is compiled in AND coverage.py has installed a trace function via sys.settrace (which coverage run does automatically). Step 2 – End-to-end coverage output Name Stmts Miss Cover Missingrun_test.py 3 0 100%
|
|
@raulcd would we want to have this as a regular CI check? |
|
I am unsure it seems we added coverage here: And then disabled it here: It seems the reason, based on the JIRA ticket was:
From what I understand it seems we were trying to do a full Arrow coverage report (C++, Python, R). @pitrou you worked on adding this coverage in the past, what are your thoughts on this? This being:
|
Summary
Closes #49397.
This PR validates and fixes the
PYARROW_GENERATE_COVERAGEflag so thatCython coverage reporting works end-to-end for the PyArrow test suite.
Changes
python/pyarrow/conftest.pypytest_configurehook that activates theCython.Coverageplugin and calls
coverage.process_startup()whenPYARROW_GENERATE_COVERAGEis set.Cython line-tracing hooks embedded at build time are picked up by
coverage.py.UserWarningis raised ifcoverageorCythonare notinstalled, with instructions to install them.
python/.coveragercsource,branch,reportandhtmlsections socoverage.pyknows which files to measure and where to write the report.
How to use