mesonbuild / meson-python

Meson PEP 517 Python build backend
https://mesonbuild.com/meson-python/
MIT License
120 stars 59 forks source link

test_wheel: account for `sys.platform`s that include `uname -r` appended #514

Closed vishwin closed 8 months ago

vishwin commented 9 months ago

https://github.com/mesonbuild/meson-python/blob/8b0733fd85c98b7e8528e68edb86c629a0958adf/tests/test_wheel.py#L36 https://github.com/mesonbuild/meson-python/blob/8b0733fd85c98b7e8528e68edb86c629a0958adf/tests/test_wheel.py#L41 With sys.platform in the Unix-like systems category, only Linux, AIX, and Darwin do not append a version string derived from uname -r. The entire test suite fails to run at all on these other Unix-like systems due to the ensuing KeyError. This can be hacked around on a local system using sys.platform.strip('0123456789'), but wouldn't work for the win32 case generally. Perhaps there's a better way to enumerate the different LIB_SUFFIXes proliferated?

rgommers commented 9 months ago

That looks incorrect indeed. Could you add the actual platform you're seeing a failure on and a traceback @vishwin? That helps with both a fix and with searchability when someone else runs into the same problem.

dnicolodi commented 9 months ago

I'm surprised to learn that it does not work on Windows, our CI runs on Windows too and it works, and the documentation says it should work https://docs.python.org/3/library/sys.html#sys.platform

The same documentation states that it should also work on AIX since Python 3.8 and, while we still support it, Python 3.7 is end-of-life, thus I'm not sure we should put work into supporting it.

This leaves out only the *BSD systems. But I'm sure there are other aspects of the test suite that most likely break there.

vishwin commented 9 months ago

The part about the hack not working on Windows stems from the .strip('0123456789') that leaves the key as 'win'.

On FreeBSD:

==================================== ERRORS ====================================
___________________ ERROR collecting tests/test_editable.py ____________________
/usr/local/lib/python3.11/site-packages/_pytest/runner.py:341: in from_call
    result: Optional[TResult] = func()
/usr/local/lib/python3.11/site-packages/_pytest/runner.py:372: in <lambda>
    call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
/usr/local/lib/python3.11/site-packages/_pytest/python.py:531: in collect
    self._inject_setup_module_fixture()
/usr/local/lib/python3.11/site-packages/_pytest/python.py:545: in _inject_setup_module_fixture
    self.obj, ("setUpModule", "setup_module")
/usr/local/lib/python3.11/site-packages/_pytest/python.py:310: in obj
    self._obj = obj = self._getobj()
/usr/local/lib/python3.11/site-packages/_pytest/python.py:528: in _getobj
    return self._importtestmodule()
/usr/local/lib/python3.11/site-packages/_pytest/python.py:617: in _importtestmodule
    mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
/usr/local/lib/python3.11/site-packages/_pytest/pathlib.py:567: in import_path
    importlib.import_module(module_name)
/usr/local/lib/python3.11/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1204: in _gcd_import
    ???
<frozen importlib._bootstrap>:1176: in _find_and_load
    ???
<frozen importlib._bootstrap>:1147: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:690: in _load_unlocked
    ???
/usr/local/lib/python3.11/site-packages/_pytest/assertion/rewrite.py:178: in exec_module
    exec(co, module.__dict__)
tests/test_editable.py:15: in <module>
    from .test_wheel import EXT_SUFFIX
<frozen importlib._bootstrap>:1176: in _find_and_load
    ???
<frozen importlib._bootstrap>:1147: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:690: in _load_unlocked
    ???
/usr/local/lib/python3.11/site-packages/_pytest/assertion/rewrite.py:178: in exec_module
    exec(co, module.__dict__)
tests/test_wheel.py:36: in <module>
    LIB_SUFFIX = {
E   KeyError: 'freebsd15'
_____________________ ERROR collecting tests/test_wheel.py _____________________
/usr/local/lib/python3.11/site-packages/_pytest/runner.py:341: in from_call
    result: Optional[TResult] = func()
/usr/local/lib/python3.11/site-packages/_pytest/runner.py:372: in <lambda>
    call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
/usr/local/lib/python3.11/site-packages/_pytest/python.py:531: in collect
    self._inject_setup_module_fixture()
/usr/local/lib/python3.11/site-packages/_pytest/python.py:545: in _inject_setup_module_fixture
    self.obj, ("setUpModule", "setup_module")
/usr/local/lib/python3.11/site-packages/_pytest/python.py:310: in obj
    self._obj = obj = self._getobj()
/usr/local/lib/python3.11/site-packages/_pytest/python.py:528: in _getobj
    return self._importtestmodule()
/usr/local/lib/python3.11/site-packages/_pytest/python.py:617: in _importtestmodule
    mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
/usr/local/lib/python3.11/site-packages/_pytest/pathlib.py:567: in import_path
    importlib.import_module(module_name)
/usr/local/lib/python3.11/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1204: in _gcd_import
    ???
<frozen importlib._bootstrap>:1176: in _find_and_load
    ???
<frozen importlib._bootstrap>:1147: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:690: in _load_unlocked
    ???
/usr/local/lib/python3.11/site-packages/_pytest/assertion/rewrite.py:178: in exec_module
    exec(co, module.__dict__)
tests/test_wheel.py:36: in <module>
    LIB_SUFFIX = {
E   KeyError: 'freebsd15'
!!!!!!!!!!!!!!!!!!! Interrupted: 2 errors during collection !!!!!!!!!!!!!!!!!!!!
dnicolodi commented 9 months ago

I'm not sure I understand what the numerical suffix in sys.platform has to do with the issue you report. The dictionary does not have a key for freebsd either, thus the lookup would anyhow fail if we strip the numerical suffix. Does the test suite work if you add an entry for freebsd15 in this dictionary?

vishwin commented 8 months ago

Not stripping the uname -r part from sys.platforms will cause this dictionary to get unwieldy real quick, especially when more often than not the shared object suffix is .so. There's no real point to keep adding freebsd15, freebsd14, netbsd7, openbsd6 et al. Additionally, the current fixed items in the dictionary preclude running the test suite on anything other than those in the dictionary.

dnicolodi commented 8 months ago

Fixing the dictionary lookup is trivial, trust me on this. But would the testsuite pass on FreeBSD if the dictionary lookup works?

vishwin commented 8 months ago

Once past this point the test suite runs. I can't conclude if it completely passes or not due to numerous errors that look like git running into filesystem permissions issues, but that's for another topic if I get a chance to look further.

dnicolodi commented 8 months ago

There are a couple of small fixes to make the tests pass on FreeBSD, but nothing major, and nothing that makes meson-python not work on the platform, see #515. I'm pleasantly surprised, given that we never tested or actively thought about UNIX platforms different from Linux.