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

build failure if Cython is not available #962

Closed
1 task done
Kiskae opened this issue Nov 25, 2023 · 1 comment
Closed
1 task done

build failure if Cython is not available #962

Kiskae opened this issue Nov 25, 2023 · 1 comment

Comments

@Kiskae
Copy link

Kiskae commented Nov 25, 2023

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
@webknjaz
Copy link
Member

If you want a pure Python build, you must request it explicitly. If you want C-extensions, provision the build env properly. Cython is injected dynamically, only when building wheels is requested (including editable installs), through the corresponding PEP 517 hook, just like wheel.
Building with pypa/build in its default mode works because it follows the PEP and calls the corresponding hooks to determine all the deps, not just the statically listed ones.

I think that there's a CLI flag for build for verifying that the current env contains all the deps. Try using that as a self-check.

@webknjaz webknjaz closed this as not planned Won't fix, can't repro, duplicate, stale Nov 25, 2023
webknjaz added a commit to webknjaz/yarl that referenced this issue Nov 26, 2023
webknjaz added a commit to webknjaz/yarl that referenced this issue Nov 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants