Skip to content

Commit 0b2dca1

Browse files
committed
FIX: account for removals in py313 in importlib
243fdcb40ebeb177ce723911c1f7fad8a1fdf6cb / python/cpython#106532 removes functions deprecated in py311.
1 parent 7824ff8 commit 0b2dca1

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

mesonbuild/dependencies/python.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,15 @@ def sanity(self) -> bool:
110110
# Sanity check, we expect to have something that at least quacks in tune
111111

112112
import importlib.resources
113+
import sys
114+
if sys.version_info >= (3, 9):
115+
ctx = importlib.resources.as_file(
116+
importlib.resources.files('mesonbuild.scripts').joinpath('python_info.py')
117+
)
118+
else:
119+
ctx = importlib.resources.path('mesonbuild.scripts', 'python_info.py')
113120

114-
with importlib.resources.path('mesonbuild.scripts', 'python_info.py') as f:
121+
with ctx as f:
115122
cmd = self.get_command() + [str(f)]
116123
p, stdout, stderr = mesonlib.Popen_safe(cmd)
117124

mesonbuild/modules/python.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,11 @@ def should_append(f, isdir: bool = False):
329329
import importlib.resources
330330
pycompile = os.path.join(self.interpreter.environment.get_scratch_dir(), 'pycompile.py')
331331
with open(pycompile, 'wb') as f:
332-
f.write(importlib.resources.read_binary('mesonbuild.scripts', 'pycompile.py'))
332+
import sys
333+
if sys.version_info >= (3, 9):
334+
f.write(importlib.resources.files('mesonbuild.scripts').joinpath('pycompile.py').read_bytes())
335+
else:
336+
f.write(importlib.resources.read_binary('mesonbuild.scripts', 'pycompile.py'))
333337

334338
for i in self.installations.values():
335339
if isinstance(i, PythonExternalProgram) and i.run_bytecompile[i.info['version']]:

0 commit comments

Comments
 (0)