Skip to content

Commit 067efcb

Browse files
authored
Merge pull request #4 from rgommers/py313
Stop using removed `importlib.resources` functions on Python >=3.13
2 parents 66ba7db + 7ade382 commit 067efcb

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

mesonbuild/dependencies/python.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import functools, json, os, textwrap
1717
from pathlib import Path
18+
import sys
1819
import typing as T
1920

2021
from .. import mesonlib, mlog
@@ -110,8 +111,13 @@ def sanity(self) -> bool:
110111
# Sanity check, we expect to have something that at least quacks in tune
111112

112113
import importlib.resources
114+
if sys.version_info >= (3, 13):
115+
traversable = importlib.resources.files('mesonbuild.scripts').joinpath('python_info.py')
116+
context_mgr = importlib.resources.as_file(traversable)
117+
else:
118+
context_mgr = importlib.resources.path('mesonbuild.scripts', 'python_info.py')
113119

114-
with importlib.resources.path('mesonbuild.scripts', 'python_info.py') as f:
120+
with context_mgr as f:
115121
cmd = self.get_command() + [str(f)]
116122
p, stdout, stderr = mesonlib.Popen_safe(cmd)
117123

mesonbuild/modules/python.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414
from __future__ import annotations
1515

16-
import copy, json, os, shutil
16+
import copy, json, os, shutil, sys
1717
import typing as T
1818

1919
from . import ExtensionModule, ModuleInfo
@@ -329,7 +329,10 @@ 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+
if sys.version_info >= (3, 13):
333+
f.write(importlib.resources.files('mesonbuild.scripts').joinpath('pycompile.py').read_bytes())
334+
else:
335+
f.write(importlib.resources.read_binary('mesonbuild.scripts', 'pycompile.py'))
333336

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

0 commit comments

Comments
 (0)