Skip to content

build failure if Cython is not available #962

@Kiskae

Description

@Kiskae

Describe the bug

If cython isn't available, then the import fails but gets suppressed:

with suppress(ImportError):
# NOTE: Only available for wheel builds that bundle C-extensions. Declared
# NOTE: by `get_requires_for_build_wheel()` and
# NOTE: `get_requires_for_build_editable()`, when `--pure-python`
# NOTE: is not passed.
from Cython.Build.Cythonize import main as _cythonize_cli_cmd

However the imported function is always invoked during the build:

_cythonize_cli_cmd(cythonize_args)

Since there is no fallback, this causes a NameError and a subsequent build failure

To Reproduce

  1. Set up build environment without Cython
  2. python -m build

Expected behavior

Succesful compilation without cython support.

Logs/tracebacks

Running command Building wheel for yarl (pyproject.toml)
  **********************
  * Accelerated build *
  **********************
  Traceback (most recent call last):
    File "/nix/store/slhj69him45n2pck7wkknnffi4ay0jy0-python3.11-pip-23.2.1/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
      main()
    File "/nix/store/slhj69him45n2pck7wkknnffi4ay0jy0-python3.11-pip-23.2.1/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/nix/store/slhj69him45n2pck7wkknnffi4ay0jy0-python3.11-pip-23.2.1/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 251, in build_wheel
      return _build_backend().build_wheel(wheel_directory, config_settings,
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/nix/store/qp5zys77biz7imbk6yy85q5pdv7qk84j-python3-3.11.6/lib/python3.11/contextlib.py", line 81, in inner
      return func(*args, **kwds)
             ^^^^^^^^^^^^^^^^^^^
    File "/build/yarl-1.9.3/packaging/pep517_backend/_backend.py", line 325, in build_wheel
      with maybe_prebuild_c_extensions(
    File "/nix/store/qp5zys77biz7imbk6yy85q5pdv7qk84j-python3-3.11.6/lib/python3.11/contextlib.py", line 137, in __enter__
      return next(self.gen)
             ^^^^^^^^^^^^^^
    File "/build/yarl-1.9.3/packaging/pep517_backend/_backend.py", line 304, in maybe_prebuild_c_extensions
      _cythonize_cli_cmd(cythonize_args)
      ^^^^^^^^^^^^^^^^^^
  NameError: name '_cythonize_cli_cmd' is not defined

Python Version

3.11.6

multidict Version

6.0.4

yarl Version

1.9.3

OS

NixOS 23.05

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions