Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions mesonbuild/dependencies/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,20 @@ def _setup_cmake_dir(self, cmake_file: str) -> Path:
if cmake_cache.exists():
cmake_cache.unlink()
shutil.rmtree(cmake_files.as_posix(), ignore_errors=True)

# Insert language parameters into the CMakeLists.txt and write new CMakeLists.txt
cmake_txt = importlib.resources.read_text('mesonbuild.dependencies.data', cmake_file, encoding = 'utf-8')
import sys

if sys.version_info >= (3, 9):
cmake_txt = importlib.resources.files(
'mesonbuild.dependencies.data',
).joinpath(cmake_file).read_text(encoding='utf-8')
else:
cmake_txt = importlib.resources.read_text( # [ignore encoding] it's on the next lines, Mr. Lint
# ('mesonbuild' / self.path.parent).as_posix().replace('/', '.'),
'mesonbuild.dependencies.data',
# self.path.name,
cmake_file,
encoding='utf-8')

# In general, some Fortran CMake find_package() also require C language enabled,
# even if nothing from C is directly used. An easy Fortran example that fails
Expand Down
9 changes: 8 additions & 1 deletion mesonbuild/dependencies/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,15 @@ def sanity(self) -> bool:
# Sanity check, we expect to have something that at least quacks in tune

import importlib.resources
import sys
if sys.version_info >= (3, 9):
ctx = importlib.resources.as_file(
importlib.resources.files('mesonbuild.scripts').joinpath('python_info.py')
)
else:
ctx = importlib.resources.path('mesonbuild.scripts', 'python_info.py')

with importlib.resources.path('mesonbuild.scripts', 'python_info.py') as f:
with ctx as f:
cmd = self.get_command() + [str(f)]
env = os.environ.copy()
env['SETUPTOOLS_USE_DISTUTILS'] = 'stdlib'
Expand Down
8 changes: 7 additions & 1 deletion mesonbuild/mesondata.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ def __init__(self, path: str) -> None:

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
import sys
if sys.version_info >= (3, 9):
data = importlib.resources.files(
('mesonbuild' / self.path.parent).as_posix().replace('/', '.')
).joinpath(self.path.name).read_text(encoding='utf-8')
else:
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')
Expand Down
6 changes: 5 additions & 1 deletion mesonbuild/modules/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,11 @@ def should_append(f, isdir: bool = False):
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'))
import sys
if sys.version_info >= (3, 9):
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']]:
Expand Down