Skip to content

BLD: Add Cython Coverage option #54453

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

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ add_project_arguments('-DNPY_NO_DEPRECATED_API=0', language : 'cpp')
add_project_arguments('-DNPY_TARGET_VERSION=NPY_1_21_API_VERSION', language : 'c')
add_project_arguments('-DNPY_TARGET_VERSION=NPY_1_21_API_VERSION', language : 'cpp')

cython_coverage = get_option('CYTHON_COVERAGE')

if fs.exists('_version_meson.py')
py.install_sources('_version_meson.py', subdir: 'pandas')
Expand Down
1 change: 1 addition & 0 deletions meson.options
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
option('CYTHON_COVERAGE', type: 'boolean', value: false)
13 changes: 11 additions & 2 deletions pandas/_libs/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ _intervaltree_helper = custom_target('intervaltree_helper_pxi',
)
_khash_primitive_helper_dep = declare_dependency(sources: _khash_primitive_helper)

subdir('tslibs')

libs_sources = {
# Dict of extension name -> dict of {sources, include_dirs, and deps}
# numpy include dir is implicitly included
Expand Down Expand Up @@ -109,6 +107,17 @@ cython_args = [
if get_option('buildtype') == 'debug'
cython_args += ['--gdb']
endif
if cython_coverage
cython_args += ['-X linetrace=true']
# Linetrace is not enough to ensure coverage is turned on
add_project_arguments('-DCYTHON_TRACE=1', language : 'c')
add_project_arguments('-DCYTHON_TRACE=1', language : 'cpp')

add_project_arguments('-DCYTHON_TRACE_NOGIL=1', language : 'c')
add_project_arguments('-DCYTHON_TRACE_NOGIL=1', language : 'cpp')
endif

subdir('tslibs')

foreach ext_name, ext_dict : libs_sources
py.extension_module(
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/parsers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ cdef double round_trip_wrapper(const char *p, char **q, char decimal,

cdef char* buffer_rd_bytes_wrapper(void *source, size_t nbytes,
size_t *bytes_read, int *status,
const char *encoding_errors) noexcept:
const char *encoding_errors) noexcept nogil:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed to mark this as nogil or we would segfault since the tracing code would try to use GIL requiring code (and this function would be called in a nogil block).

I'm pretty sure the C code can acquire the GIL for itself when it needs it so nogil isn't needed?

cc @WillAyd

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea it looks like the C code does ensure the GIL. I'm a little unclear then though - isn't marking this nogil incorrect since it actually uses the GIL?

return buffer_rd_bytes(source, nbytes, bytes_read, status, encoding_errors)

cdef void del_rd_source_wrapper(void *src) noexcept:
Expand Down
4 changes: 2 additions & 2 deletions pandas/_libs/window/meson.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
py.extension_module(
'aggregations',
['aggregations.pyx'],
cython_args: ['-X always_allow_keywords=true'],
cython_args: cython_args,
include_directories: [inc_np, inc_pd],
subdir: 'pandas/_libs/window',
override_options : ['cython_language=cpp'],
Expand All @@ -11,7 +11,7 @@ py.extension_module(
py.extension_module(
'indexers',
['indexers.pyx'],
cython_args: ['-X always_allow_keywords=true'],
cython_args: cython_args, #['-X always_allow_keywords=true'],
include_directories: [inc_np, inc_pd],
subdir: 'pandas/_libs/window',
install: true
Expand Down