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 3 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
6 changes: 3 additions & 3 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ jobs:
run: |
/opt/python/cp311-cp311/bin/python -m venv ~/virtualenvs/pandas-dev
. ~/virtualenvs/pandas-dev/bin/activate
python -m pip install --no-cache-dir -U pip wheel setuptools meson[ninja]==1.0.1 meson-python==0.13.1
python -m pip install --no-cache-dir -U pip wheel setuptools meson[ninja]==1.1.1 meson-python==0.13.1
python -m pip install --no-cache-dir versioneer[toml] cython numpy python-dateutil pytz pytest>=7.3.2 pytest-xdist>=2.2.0 pytest-asyncio>=0.17 hypothesis>=6.46.1
python -m pip install --no-cache-dir --no-build-isolation -e .
python -m pip list --no-cache-dir
Expand Down Expand Up @@ -276,7 +276,7 @@ jobs:
run: |
/opt/python/cp311-cp311/bin/python -m venv ~/virtualenvs/pandas-dev
. ~/virtualenvs/pandas-dev/bin/activate
python -m pip install --no-cache-dir -U pip wheel setuptools meson-python==0.13.1 meson[ninja]==1.0.1
python -m pip install --no-cache-dir -U pip wheel setuptools meson-python==0.13.1 meson[ninja]==1.1.1
python -m pip install --no-cache-dir versioneer[toml] cython numpy python-dateutil pytz pytest>=7.3.2 pytest-xdist>=2.2.0 pytest-asyncio>=0.17 hypothesis>=6.46.1
python -m pip install --no-cache-dir --no-build-isolation -e .
python -m pip list --no-cache-dir
Expand Down Expand Up @@ -348,7 +348,7 @@ jobs:
- name: Install dependencies
run: |
python --version
python -m pip install --upgrade pip setuptools wheel meson[ninja]==1.0.1 meson-python==0.13.1
python -m pip install --upgrade pip setuptools wheel meson[ninja]==1.1.1 meson-python==0.13.1
python -m pip install --pre --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy
python -m pip install versioneer[toml]
python -m pip install python-dateutil pytz tzdata cython hypothesis>=6.46.1 pytest>=7.3.2 pytest-xdist>=2.2.0 pytest-cov pytest-asyncio>=0.17
Expand Down
2 changes: 1 addition & 1 deletion ci/deps/actions-310.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dependencies:
# build dependencies
- versioneer[toml]
- cython>=3.0.0
- meson[ninja]=1.0.1
- meson[ninja]=1.1.1
- meson-python=0.13.1

# test dependencies
Expand Down
2 changes: 1 addition & 1 deletion ci/deps/actions-311-downstream_compat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies:
# build dependencies
- versioneer[toml]
- cython>=3.0.0
- meson[ninja]=1.0.1
- meson[ninja]=1.1.1
- meson-python=0.13.1

# test dependencies
Expand Down
2 changes: 1 addition & 1 deletion ci/deps/actions-311-numpydev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dependencies:

# build dependencies
- versioneer[toml]
- meson[ninja]=1.0.1
- meson[ninja]=1.1.1
- meson-python=0.13.1

# test dependencies
Expand Down
2 changes: 1 addition & 1 deletion ci/deps/actions-311-pyarrownightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dependencies:

# build dependencies
- versioneer[toml]
- meson[ninja]=1.0.1
- meson[ninja]=1.1.1
- cython>=3.0.0
- meson-python=0.13.1

Expand Down
2 changes: 1 addition & 1 deletion ci/deps/actions-311.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dependencies:
# build dependencies
- versioneer[toml]
- cython>=3.0.0
- meson[ninja]=1.0.1
- meson[ninja]=1.1.1
- meson-python=0.13.1

# test dependencies
Expand Down
2 changes: 1 addition & 1 deletion ci/deps/actions-39-minimum_versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies:
# build dependencies
- versioneer[toml]
- cython>=3.0.0
- meson[ninja]=1.0.1
- meson[ninja]=1.1.1
- meson-python=0.13.1

# test dependencies
Expand Down
2 changes: 1 addition & 1 deletion ci/deps/actions-39.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dependencies:
# build dependencies
- versioneer[toml]
- cython>=3.0.0
- meson[ninja]=1.0.1
- meson[ninja]=1.1.1
- meson-python=0.13.1

# test dependencies
Expand Down
2 changes: 1 addition & 1 deletion ci/deps/actions-pypy-39.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies:
# build dependencies
- versioneer[toml]
- cython>=3.0.0
- meson[ninja]=1.0.1
- meson[ninja]=1.1.1
- meson-python=0.13.1

# test dependencies
Expand Down
2 changes: 1 addition & 1 deletion ci/deps/circle-310-arm64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dependencies:
# build dependencies
- versioneer[toml]
- cython>=3.0.0
- meson[ninja]=1.0.1
- meson[ninja]=1.1.1
- meson-python=0.13.1

# test dependencies
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies:
# build dependencies
- versioneer[toml]
- cython=3.0.0
- meson[ninja]=1.0.1
- meson[ninja]=1.1.1
- meson-python=0.13.1

# test dependencies
Expand Down
3 changes: 2 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ project(
'c', 'cpp', 'cython',
version: run_command(['python', 'generate_version.py', '--print'], check: true).stdout().strip(),
license: 'BSD-3',
meson_version: '>=1.0.1',
meson_version: '>=1.1',
default_options: [
# TODO: investigate, does meson try to compile against debug Python
# when buildtype = debug, this seems to be causing problems on CI
Expand Down Expand Up @@ -33,6 +33,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', pure: false, 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)
16 changes: 13 additions & 3 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 @@ -100,12 +98,24 @@ libs_sources = {
'writers': {'sources': ['writers.pyx']}
}

cython_args = ['--include-dir', meson.current_build_dir(), '-X always_allow_keywords=true']
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(
ext_name,
ext_dict.get('sources'),
cython_args: ['--include-dir', meson.current_build_dir(), '-X always_allow_keywords=true'],
cython_args: cython_args,
include_directories: [inc_np, inc_pd],
dependencies: ext_dict.get('deps', ''),
subdir: 'pandas/_libs',
Expand Down
6 changes: 3 additions & 3 deletions pandas/_libs/parsers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ cdef extern from "pandas/parser/pd_parser.h":

int del_rd_source(void *src)

void* buffer_rd_bytes(void *source, size_t nbytes,
size_t *bytes_read, int *status, const char *encoding_errors)
void* buffer_rd_bytes(void *source, size_t nbytes, size_t *bytes_read,
int *status, const char *encoding_errors) nogil

void uint_state_init(uint_state *self)
int uint64_conflict(uint_state *self)
Expand Down Expand Up @@ -325,7 +325,7 @@ cdef double round_trip_wrapper(const char *p, char **q, char decimal,

cdef void* 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 int del_rd_source_wrapper(void *src) noexcept:
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ foreach ext_name, ext_dict : tslibs_sources
py.extension_module(
ext_name,
ext_dict.get('sources'),
cython_args: ['--include-dir', meson.current_build_dir(), '-X always_allow_keywords=true'],
cython_args: cython_args,
include_directories: [inc_np, inc_pd],
dependencies: ext_dict.get('deps', ''),
subdir: 'pandas/_libs/tslibs',
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],
dependencies: [py_dep],
subdir: 'pandas/_libs/window',
Expand All @@ -12,7 +12,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],
dependencies: [py_dep],
subdir: 'pandas/_libs/window',
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# See https://github.com/scipy/scipy/pull/12940 for the AIX issue.
requires = [
"meson-python==0.13.1",
"meson==1.0.1",
"meson==1.1.1",
"wheel",
"Cython>=3.0.0", # Note: sync with setup.py, environment.yml and asv.conf.json
# Note: numpy 1.25 has a backwards compatible C API by default
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
pip
versioneer[toml]
cython==3.0.0
meson[ninja]==1.0.1
meson[ninja]==1.1.1
meson-python==0.13.1
pytest>=7.3.2
pytest-cov
Expand Down