Skip to content
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

TST: convert remaining setup.py tests to meson instead #24206

Merged
merged 5 commits into from Aug 31, 2023

Conversation

mattip
Copy link
Member

@mattip mattip commented Jul 18, 2023

I tried to remove setuptools from test_requirements.txt, and found these tests were building c-extension modules using setup.py. I converted them to meson.

We still need setuptools to pass the numpy/tests/test_public_api.py tests. Some of the distutils modules fail to import if it is not found. I am leaving that for a further cleanup

@mattip
Copy link
Member Author

mattip commented Jul 18, 2023

Windows builds are failing to find python3.lib when building with the limited API. Is this a known problem with meson?

"link"  /MACHINE:x64 /OUT:limited_api.cp311-win_amd64.pyd limited_api.cp311-win_amd64.pyd.p/45439c8367f143d67c47043d0b62b0da35190854_core_tests_examples_limited_api_limited_api.c.obj "/nologo" "/release" "/nologo" "/OPT:REF" "/DLL" "/IMPLIB:limited_api.cp311-win_amd64.lib" "C:\hostedtoolcache\windows\Python\3.11.4\x64\libs\python311.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "comdlg32.lib" "advapi32.lib"

LINK : fatal error LNK1104: cannot open file 'python3.lib'
```

@eli-schwartz
Copy link

Yup, meson will need to implement support for setting a limited_api kwarg that:

  • defines the macro for you
  • makes sure to link to the right python DLL
  • adds the correct .abi3 extension

Copy link
Member

@rgommers rgommers left a comment

Choose a reason for hiding this comment

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

Thanks @mattip. Not touching the limited API test for now and updating the rest sounds good to me.

numpy/core/tests/examples/cython/meson.build Outdated Show resolved Hide resolved
numpy/core/tests/examples/cython/meson.build Outdated Show resolved Hide resolved
@@ -1,29 +0,0 @@
"""
Copy link
Member

Choose a reason for hiding this comment

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

Here we don't use numpy.distutils, so this should continue to work unchanged. Hence it may be useful to keep around as an example? No need to test it for me, because it's so simple that it should be robust.

Although if you prefer to clean it up, also okay - no strong feelings about it. For the numpy/random I didn't think about this, but also that used numpy.distutils I think, so needed to go anyway.

"limited_api",
sources=[os.path.join('.', "limited_api.c")],
include_dirs=[np.get_include()],
define_macros=macros,
Copy link
Member

Choose a reason for hiding this comment

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

This happens to work (perhaps, the test doesn't actually check that the extension is .abi3), but this seems wrong. setuptools.Extension expects a py_limited_api=True keyword: https://github.com/pypa/setuptools/blob/f7532b24c49b8285496734b544ea12a6fb6fdc52/setuptools/extension.py#L119.

@mattip
Copy link
Member Author

mattip commented Jul 21, 2023

Let's see how fast mesonbuild/meson#11745 to provide support for the limited API in meson progresses.

@charris charris added the 09 - Backport-Candidate PRs tagged should be backported label Jul 21, 2023
@charris charris added this to the 1.26.0 release milestone Jul 25, 2023
@mattip
Copy link
Member Author

mattip commented Aug 27, 2023

PR mesonbuild/meson#11745 which provides a python.allow_limited_api option. If set to true meson will build a limited API c-extension where possible (not on PyPy). It is targetted for a future meson 1.13 release. Should we merge it to our vendored meson code for tests?

@rgommers
Copy link
Member

Where would we use the limited API? Seems relevant to be for OpenBLAS wheels, but not for NumPy.

@eli-schwartz
Copy link

Where would we use the limited API?

Only in tests/test_limited_api.py, I guess. ;)

@mattip
Copy link
Member Author

mattip commented Aug 27, 2023

in tests/test_limited_api.py

Exactly. Maybe that test is too simple, but it checks that one can call import_array(); import_umath(); in a module compiled for the limited API. It came from #20818 in response to a regression identified in issue #13784, where our headers exposed non-limited-API C-API calls.

@rgommers
Copy link
Member

Thanks - that was obvious in hindsight - I was thinking this was a different PR.

Should we merge it to our vendored meson code for tests?

I like the idea of removing our last test dependencies on setuptools in principle, but this doesn't seem urgent. How about making the test only run if setuptools is installed, and otherwise skipping it?

The reason I'm a little hesitant is that the Meson change isn't a small/trivial diff, and it may make it more difficult to keep up with changes to the PR we actually need (the features module for SIMD support). And there's actually nothing wrong with the current test - code like that needs to stay working too.

@mattip
Copy link
Member Author

mattip commented Aug 28, 2023

Rebased and refactored to only modify the cython example for now, and to leave the setup.py file for reference.

@mattip
Copy link
Member Author

mattip commented Aug 28, 2023

Hmm. Testing setuptools imports it, but we have pinned to an older version. So the import hits a DeprecationWarning. It was debugged in scipy that this is due to pinning setuptools<62 together with python3.11.

@mattip
Copy link
Member Author

mattip commented Aug 28, 2023

I removed the check, let's see which tests still need a pytest skip

@rgommers
Copy link
Member

We only have a couple of CI jobs left that use setup.py; we should be able to unpin very soon (if not now).

@mattip
Copy link
Member Author

mattip commented Aug 28, 2023

cygwin is unhappy. If a test fails, it runs a "Check the extension modules on failure" CI step that is broken. One of the script's sed command is failing to get the module name (i.e. _multiarray_tests) from the dll (i.e. /usr/local/lib/python3.9/site-packages/numpy/core/_multiarray_tests.cpython-39-x86_64-cygwin.dll.a

@rgommers
Copy link
Member

I'm not quite sure what is going wrong there. @DWesl maybe you can help, as the author of that sed script?

@DWesl
Copy link
Contributor

DWesl commented Aug 28, 2023

Are you installing the import libraries on purpose? You shouldn't need any .dll.a files unless you want to link against them, and there's not too many reasons to link against a hidden test extension module.

If that is on purpose, tools/list_numpy_dlls.sh needs to be modified to exclude those files, which is easy enough to do here:

grep -F .dll); do echo ${site_packages}/${name}; done`

with an extra grep -F -v -e .dll.a, or changing the existing pattern to .dll$

@mattip
Copy link
Member Author

mattip commented Aug 28, 2023

Are you installing the import libraries on purpose?

We do not ship a wheel for cygwin, but apparently need to exclude some things when building the wheel in the CI build step. We do need a few import libraries to allow linking the various dlls that export numpy.random c-external functions.

I solved the immediate problem by getting the tests to pass, so the "on fail" build step is not executed.

@DWesl
Copy link
Contributor

DWesl commented Aug 28, 2023

Are you installing the import libraries on purpose?

We do not ship a wheel for cygwin, but apparently need to exclude some things when building the wheel in the CI build step. We do need a few import libraries to allow linking the various dlls that export numpy.random c-external functions.

I remember the rounds of fixing the numpy.random c-extensions so they work with both upstream Cython and the distribution Cython.

With those libraries in mind, I should look into fixing that regex. (EDIT: Done: #24570)

Copy link
Member

@rgommers rgommers left a comment

Choose a reason for hiding this comment

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

This LGTM now and CI is all green, so in it goes. Thanks @mattip & reviewers!

@rgommers rgommers merged commit 1195ff5 into numpy:main Aug 31, 2023
2 checks passed
charris pushed a commit to charris/numpy that referenced this pull request Sep 1, 2023
The limited-api test has to wait for a new Meson version (see numpygh-24206).
This converts the regular Cython test for `numpy.core`.

[skip ci]
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Sep 1, 2023
charris pushed a commit to charris/numpy that referenced this pull request Nov 11, 2023
The limited-api test has to wait for a new Meson version (see numpygh-24206).
This converts the regular Cython test for `numpy.core`.

[skip ci]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants