From 56a128ab60bbf43c20255ad40fcde453434d9bf9 Mon Sep 17 00:00:00 2001 From: Karolina Surma Date: Wed, 13 Dec 2023 14:49:37 +0100 Subject: [PATCH] Don't use the removed importlib.resources.path with Python 3.13+ --- 12402.patch | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++ meson.spec | 3 ++ 2 files changed, 100 insertions(+) create mode 100644 12402.patch diff --git a/12402.patch b/12402.patch new file mode 100644 index 0000000..2d4f6bf --- /dev/null +++ b/12402.patch @@ -0,0 +1,97 @@ +From 2e92a786f56990ec7c40e239b8160666548e9e35 Mon Sep 17 00:00:00 2001 +From: Ralf Gommers +Date: Fri, 20 Oct 2023 17:29:26 +0200 +Subject: [PATCH] Stop using removed `importlib.resources` functions on Python + >=3.13 + +Closes gh-12401 +--- + mesonbuild/dependencies/python.py | 8 +++++++- + mesonbuild/mesondata.py | 11 +++++++---- + mesonbuild/modules/python.py | 7 +++++-- + 3 files changed, 19 insertions(+), 7 deletions(-) + +diff --git a/mesonbuild/dependencies/python.py b/mesonbuild/dependencies/python.py +index f044946..244cd31 100644 +--- a/mesonbuild/dependencies/python.py ++++ b/mesonbuild/dependencies/python.py +@@ -15,6 +15,7 @@ from __future__ import annotations + + import functools, json, os, textwrap + from pathlib import Path ++import sys + import typing as T + + from .. import mesonlib, mlog +@@ -110,8 +111,13 @@ class BasicPythonExternalProgram(ExternalProgram): + # Sanity check, we expect to have something that at least quacks in tune + + import importlib.resources ++ if sys.version_info >= (3, 13): ++ traversable = importlib.resources.files('mesonbuild.scripts').joinpath('python_info.py') ++ context_mgr = importlib.resources.as_file(traversable) ++ else: ++ context_mgr = importlib.resources.path('mesonbuild.scripts', 'python_info.py') + +- with importlib.resources.path('mesonbuild.scripts', 'python_info.py') as f: ++ with context_mgr as f: + cmd = self.get_command() + [str(f)] + env = os.environ.copy() + env['SETUPTOOLS_USE_DISTUTILS'] = 'stdlib' +diff --git a/mesonbuild/mesondata.py b/mesonbuild/mesondata.py +index da641fd..0f93a67 100644 +--- a/mesonbuild/mesondata.py ++++ b/mesonbuild/mesondata.py +@@ -16,6 +16,7 @@ from __future__ import annotations + + import importlib.resources + from pathlib import PurePosixPath, Path ++import sys + import typing as T + + if T.TYPE_CHECKING: +@@ -27,10 +28,12 @@ class DataFile: + + def write_once(self, path: Path) -> None: + if not path.exists(): +- data = importlib.resources.read_text( # [ignore encoding] it's on the next lines, Mr. Lint +- ('mesonbuild' / self.path.parent).as_posix().replace('/', '.'), +- self.path.name, +- encoding='utf-8') ++ ++ package = ('mesonbuild' / self.path.parent).as_posix().replace('/', '.') ++ if sys.version_info >= (3, 13): ++ data = importlib.resources.files(package).joinpath(self.path.name).read_text(encoding='utf-8') ++ else: ++ data = importlib.resources.read_text(package, self.path.name, encoding='utf-8') + path.write_text(data, encoding='utf-8') + + def write_to_private(self, env: 'Environment') -> Path: +diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py +index ac74e13..baeb859 100644 +--- a/mesonbuild/modules/python.py ++++ b/mesonbuild/modules/python.py +@@ -13,7 +13,7 @@ + # limitations under the License. + from __future__ import annotations + +-import copy, json, os, shutil ++import copy, json, os, shutil, sys + import typing as T + + from . import ExtensionModule, ModuleInfo +@@ -329,7 +329,10 @@ class PythonModule(ExtensionModule): + import importlib.resources + pycompile = os.path.join(self.interpreter.environment.get_scratch_dir(), 'pycompile.py') + with open(pycompile, 'wb') as f: +- f.write(importlib.resources.read_binary('mesonbuild.scripts', 'pycompile.py')) ++ if sys.version_info >= (3, 13): ++ f.write(importlib.resources.files('mesonbuild.scripts').joinpath('pycompile.py').read_bytes()) ++ else: ++ f.write(importlib.resources.read_binary('mesonbuild.scripts', 'pycompile.py')) + + for i in self.installations.values(): + if isinstance(i, PythonExternalProgram) and i.run_bytecompile[i.info['version']]: +-- +2.41.0 + diff --git a/meson.spec b/meson.spec index d6d0d32..22183b1 100644 --- a/meson.spec +++ b/meson.spec @@ -14,6 +14,9 @@ License: ASL 2.0 URL: https://mesonbuild.com/ Source: https://github.com/mesonbuild/meson/releases/download/%{version_no_tilde .}/meson-%{version_no_tilde %{quote:}}.tar.gz +# Don't use the removed importlib.resources.path with Python 3.13+ +Patch: https://github.com/mesonbuild/meson/pull/12402.patch + BuildArch: noarch BuildRequires: python3-devel