Skip to content

ERROR running test_sycl_queue.py::test_cython_api on editable install #2146

@sycloid

Description

@sycloid

With editable install, execute

$ ONEAPI_DEVICE_SELECTOR=opencl:cpu python -m pytest dpctl/tests/test_sycl_queue.py::test_cython_api

This results Cythonization failure.

Test failure backtrace
$ ONEAPI_DEVICE_SELECTOR=opencl:cpu python -m pytest dpctl/tests/test_sycl_queue.py::test_cython_api
==================================================================== test session starts ====================================================================
platform linux -- Python 3.13.7, pytest-8.4.2, pluggy-1.6.0
rootdir: /home/sycloid/repos/dpctl
configfile: pyproject.toml
collected 1 item

dpctl/tests/test_sycl_queue.py E                                                                                                                      [100%]

========================================================================== ERRORS ===========================================================================
_____________________________________________________________ ERROR at setup of test_cython_api _____________________________________________________________

tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7f5fac487a80>, _basetemp=PosixPath('/tmp/pytest-of-sycloid/pytest-11'), _retention_count=3, _retention_policy='all')

    @pytest.fixture(scope="session")
    def dpctl_cython_extension(tmp_path_factory):
        import os
        import os.path
        import shutil
        import subprocess
        import sys
        import sysconfig

        curr_dir = os.path.dirname(__file__)
        dr = tmp_path_factory.mktemp("_cython_api")
        for fn in ["_cython_api.pyx", "setup_cython_api.py"]:
            shutil.copy(
                src=os.path.join(curr_dir, fn),
                dst=dr,
                follow_symlinks=False,
            )
        res = subprocess.run(
            [sys.executable, "setup_cython_api.py", "build_ext", "--inplace"],
            cwd=dr,
            env=os.environ,
        )
        if res.returncode == 0:
            import glob
            from importlib.util import module_from_spec, spec_from_file_location

            sfx = sysconfig.get_config_vars()["EXT_SUFFIX"]
            pth = glob.glob(os.path.join(dr, "_cython_api*" + sfx))
            if not pth:
                pytest.fail("Cython extension was not built")
            spec = spec_from_file_location("_cython_api", pth[0])
            builder_module = module_from_spec(spec)
            spec.loader.exec_module(builder_module)
            return builder_module
        else:
>           pytest.fail("Cython extension could not be built")
E           Failed: Cython extension could not be built

dpctl/tests/test_sycl_queue.py:393: Failed
------------------------------------------------------------------- Captured stdout setup -------------------------------------------------------------------
running build_ext
Compiling _cython_api.pyx because it changed.
[1/1] Cythonizing _cython_api.pyx
------------------------------------------------------------------- Captured stderr setup -------------------------------------------------------------------

Error compiling Cython file:
------------------------------------------------------------
...
# limitations under the License.

# cython: language=c++
# cython: language_level=3

cimport dpctl as c_dpctl
        ^
------------------------------------------------------------

_cython_api.pyx:20:8: 'dpctl.pxd' not found

Error compiling Cython file:
------------------------------------------------------------
...

import dpctl


def call_create_from_context_and_devices():
    cdef c_dpctl.SyclQueue q
         ^
------------------------------------------------------------

_cython_api.pyx:26:9: 'SyclQueue' is not a type identifier

Error compiling Cython file:
------------------------------------------------------------
...
def call_create_from_context_and_devices():
    cdef c_dpctl.SyclQueue q
    d = dpctl.SyclDevice()
    ctx = dpctl.SyclContext(d)
    # calling static method
    q = c_dpctl.SyclQueue._create_from_context_and_device(
               ^
------------------------------------------------------------

_cython_api.pyx:30:15: cimported module has no attribute 'SyclQueue'

Error compiling Cython file:
------------------------------------------------------------
...
    cdef c_dpctl.SyclQueue q
    d = dpctl.SyclDevice()
    ctx = dpctl.SyclContext(d)
    # calling static method
    q = c_dpctl.SyclQueue._create_from_context_and_device(
        <c_dpctl.SyclContext> ctx,
         ^
------------------------------------------------------------

_cython_api.pyx:31:9: 'SyclContext' is not a type identifier

Error compiling Cython file:
------------------------------------------------------------
...
    d = dpctl.SyclDevice()
    ctx = dpctl.SyclContext(d)
    # calling static method
    q = c_dpctl.SyclQueue._create_from_context_and_device(
        <c_dpctl.SyclContext> ctx,
        <c_dpctl.SyclDevice> d
         ^
------------------------------------------------------------

_cython_api.pyx:32:9: 'SyclDevice' is not a type identifier
Traceback (most recent call last):
  File "/tmp/pytest-of-sycloid/pytest-11/_cython_api0/setup_cython_api.py", line 29, in <module>
    setuptools.setup(
    ~~~~~~~~~~~~~~~~^
        name="test_cython_api",
        ^^^^^^^^^^^^^^^^^^^^^^^
    ...<2 lines>...
        cmdclass={"build_ext": build_ext},
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/home/sycloid/miniforge/envs/dev_dpctl/lib/python3.13/site-packages/setuptools/__init__.py", line 115, in setup
    return distutils.core.setup(**attrs)
           ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/home/sycloid/miniforge/envs/dev_dpctl/lib/python3.13/site-packages/setuptools/_distutils/core.py", line 186, in setup
    return run_commands(dist)
  File "/home/sycloid/miniforge/envs/dev_dpctl/lib/python3.13/site-packages/setuptools/_distutils/core.py", line 202, in run_commands
    dist.run_commands()
    ~~~~~~~~~~~~~~~~~^^
  File "/home/sycloid/miniforge/envs/dev_dpctl/lib/python3.13/site-packages/setuptools/_distutils/dist.py", line 1002, in run_commands
    self.run_command(cmd)
    ~~~~~~~~~~~~~~~~^^^^^
  File "/home/sycloid/miniforge/envs/dev_dpctl/lib/python3.13/site-packages/setuptools/dist.py", line 1102, in run_command
    super().run_command(command)
    ~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/home/sycloid/miniforge/envs/dev_dpctl/lib/python3.13/site-packages/setuptools/_distutils/dist.py", line 1021, in run_command
    cmd_obj.run()
    ~~~~~~~~~~~^^
  File "/home/sycloid/miniforge/envs/dev_dpctl/lib/python3.13/site-packages/setuptools/_distutils/command/build_ext.py", line 368, in run
    self.build_extensions()
    ~~~~~~~~~~~~~~~~~~~~~^^
  File "/home/sycloid/miniforge/envs/dev_dpctl/lib/python3.13/site-packages/setuptools/_distutils/command/build_ext.py", line 484, in build_extensions
    self._build_extensions_serial()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/home/sycloid/miniforge/envs/dev_dpctl/lib/python3.13/site-packages/setuptools/_distutils/command/build_ext.py", line 510, in _build_extensions_serial
    self.build_extension(ext)
    ~~~~~~~~~~~~~~~~~~~~^^^^^
  File "/home/sycloid/miniforge/envs/dev_dpctl/lib/python3.13/site-packages/Cython/Distutils/build_ext.py", line 131, in build_extension
    new_ext = cythonize(
              ~~~~~~~~~^
        ext,force=self.force, quiet=self.verbose == 0, **options
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )[0]
    ^
  File "/home/sycloid/miniforge/envs/dev_dpctl/lib/python3.13/site-packages/Cython/Build/Dependencies.py", line 1154, in cythonize
    cythonize_one(*args)
    ~~~~~~~~~~~~~^^^^^^^
  File "/home/sycloid/miniforge/envs/dev_dpctl/lib/python3.13/site-packages/Cython/Build/Dependencies.py", line 1298, in cythonize_one
    raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: _cython_api.pyx
================================================================== short test summary info ==================================================================
ERROR dpctl/tests/test_sycl_queue.py::test_cython_api - Failed: Cython extension could not be built
===================================================================== 1 error in 0.95s ======================================================================

My Cython version is 3.1.3, Python version is 3.13.7 on Ubuntu 24.04 run in WSL.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions