Thanks to visit codestin.com
Credit goes to github.com

Skip to content

TST: Explicitly pass NumPy path to cython during tests (also speed them up) #25141

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

Merged
merged 2 commits into from
Nov 15, 2023
Merged
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
9 changes: 9 additions & 0 deletions numpy/_core/tests/examples/cython/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ npy_include_path = run_command(py, [
'import os; os.chdir(".."); import numpy; print(os.path.abspath(numpy.get_include()))'
], check: true).stdout().strip()

npy_path = run_command(py, [
'-c',
'import os; os.chdir(".."); import numpy; print(os.path.dirname(numpy.__file__).removesuffix("numpy"))'
], check: true).stdout().strip()

# TODO: This is a hack due to gh-25135, where cython may not find the right
# __init__.pyd file.
add_project_arguments('-I', npy_path, language : 'cython')
Copy link
Member Author

Choose a reason for hiding this comment

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

This was the best way I found, I tested it locally with an in-place build at least...

Copy link
Member

Choose a reason for hiding this comment

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

What if you unconditionally add the current working directory? For any other use case, I think the current Cython logic does the right thing.

Copy link
Member

Choose a reason for hiding this comment

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

OTOH, I see the lines above also use the cd .. trick in order to get the C include path, so this is reusing that hack.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't have a feeling on what is best here. Wasn't this run in a temporary folder though? Escaping that might be annoying.


py.extension_module(
'checks',
'checks.pyx',
Expand Down
6 changes: 3 additions & 3 deletions numpy/_core/tests/test_cython.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
pytestmark = pytest.mark.skipif(cython is None, reason="requires cython")


@pytest.fixture
def install_temp(tmp_path):
@pytest.fixture(scope='module')
def install_temp(tmpdir_factory):
# Based in part on test_cython from random.tests.test_extending
if IS_WASM:
pytest.skip("No subprocess")

srcdir = os.path.join(os.path.dirname(__file__), 'examples', 'cython')
build_dir = tmp_path / "build"
build_dir = tmpdir_factory.mktemp("cython_test") / "build"
os.makedirs(build_dir, exist_ok=True)
try:
subprocess.check_call(["meson", "--version"])
Expand Down