2023-12-13 14:04:07 +00:00
|
|
|
From ddcc8b038c325cec8e1a0517b1b16e06213419b0 Mon Sep 17 00:00:00 2001
|
2023-12-13 13:49:37 +00:00
|
|
|
From: Ralf Gommers <ralf.gommers@gmail.com>
|
2023-12-13 14:04:07 +00:00
|
|
|
Date: Wed, 13 Dec 2023 15:03:07 +0100
|
|
|
|
Subject: [PATCH] Don't use the removed importlib.resources.path with Python
|
|
|
|
3.13+
|
2023-12-13 13:49:37 +00:00
|
|
|
|
|
|
|
---
|
|
|
|
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
|
2023-12-13 14:04:07 +00:00
|
|
|
index fe778af..55d9c1a 100644
|
2023-12-13 13:49:37 +00:00
|
|
|
--- 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
|
2023-12-13 14:04:07 +00:00
|
|
|
@@ -112,8 +113,13 @@ class BasicPythonExternalProgram(ExternalProgram):
|
2023-12-13 13:49:37 +00:00
|
|
|
# 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
|
2023-12-13 14:04:07 +00:00
|
|
|
index ec95374..926a09b 100644
|
2023-12-13 13:49:37 +00:00
|
|
|
--- a/mesonbuild/modules/python.py
|
|
|
|
+++ b/mesonbuild/modules/python.py
|
|
|
|
@@ -13,7 +13,7 @@
|
|
|
|
# limitations under the License.
|
|
|
|
from __future__ import annotations
|
|
|
|
|
2023-12-13 14:04:07 +00:00
|
|
|
-import copy, json, os, shutil, re
|
|
|
|
+import copy, json, os, shutil, re, sys
|
2023-12-13 13:49:37 +00:00
|
|
|
import typing as T
|
|
|
|
|
|
|
|
from . import ExtensionModule, ModuleInfo
|
2023-12-13 14:04:07 +00:00
|
|
|
@@ -407,7 +407,10 @@ class PythonModule(ExtensionModule):
|
2023-12-13 13:49:37 +00:00
|
|
|
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']]:
|
|
|
|
--
|
2023-12-13 14:04:07 +00:00
|
|
|
2.43.0
|
2023-12-13 13:49:37 +00:00
|
|
|
|