Patrick Williams | 705982a | 2024-01-12 09:51:57 -0600 | [diff] [blame] | 1 | From 9cc23db56add79357b8f8257fe6fc0d6879d4579 Mon Sep 17 00:00:00 2001 |
| 2 | From: "Andrew J. Hesford" <ajh@sideband.org> |
| 3 | Date: Fri, 21 Jul 2023 09:50:00 -0400 |
| 4 | Subject: [PATCH] Fix builds with Cython 3 |
| 5 | |
| 6 | This is a *de minimis* fix for building with Cython 3. Recent Cython<3 |
| 7 | releases provided `Cython.Distutils.build_ext` as an alias to |
| 8 | `Cython.Distutils.old_build_ext.old_build_ext`; Cython 3 drops this |
| 9 | alias and instead uses a wholly new `Cython.Distutils.build_ext` that |
| 10 | does not provide the `cython_sources` function used in `setup.py`. |
| 11 | |
| 12 | Explicitly importing `old_build_ext` preserves the existing behavior for |
| 13 | recent Cython<3 and uses the correct behavior for Cython 3. Should the |
| 14 | import fail (*e.g.*, because the version of Cython available predates |
| 15 | the availability of `old_build_ext`), the import falls back to just |
| 16 | `Cython.Distutils.build_ext`. |
| 17 | |
| 18 | Signed-off-by: Andrew J. Hesford <ajh@sideband.org> |
| 19 | Upstream-Status: Denied [https://github.com/yaml/pyyaml/pull/731] |
| 20 | Signed-off-by: Alexander Kanavin <alex@linutronix.de> |
| 21 | --- |
| 22 | pyproject.toml | 2 +- |
| 23 | setup.py | 6 +++++- |
| 24 | 2 files changed, 6 insertions(+), 2 deletions(-) |
| 25 | |
| 26 | diff --git a/pyproject.toml b/pyproject.toml |
| 27 | index 4bc04c0..2bf5ec8 100644 |
| 28 | --- a/pyproject.toml |
| 29 | +++ b/pyproject.toml |
| 30 | @@ -1,3 +1,3 @@ |
| 31 | [build-system] |
| 32 | -requires = ["setuptools", "wheel", "Cython<3.0"] |
| 33 | +requires = ["setuptools", "wheel", "Cython"] |
| 34 | build-backend = "setuptools.build_meta" |
| 35 | diff --git a/setup.py b/setup.py |
| 36 | index 65b0ea0..4461580 100644 |
| 37 | --- a/setup.py |
| 38 | +++ b/setup.py |
| 39 | @@ -82,7 +82,11 @@ if 'sdist' in sys.argv or os.environ.get('PYYAML_FORCE_CYTHON') == '1': |
| 40 | with_cython = True |
| 41 | try: |
| 42 | from Cython.Distutils.extension import Extension as _Extension |
| 43 | - from Cython.Distutils import build_ext as _build_ext |
| 44 | + try: |
| 45 | + from Cython.Distutils.old_build_ext import old_build_ext as _build_ext |
| 46 | + except ImportError: |
| 47 | + from Cython.Distutils import build_ext as _build_ext |
| 48 | + |
| 49 | with_cython = True |
| 50 | except ImportError: |
| 51 | if with_cython: |
| 52 | -- |
| 53 | 2.39.2 |
| 54 | |