mirror of
https://github.com/mesonbuild/meson.git
synced 2026-08-12 12:15:41 +00:00
python module: allow specifying the pure kwarg in the installation object
Fixes #10523
This commit is contained in:
8
docs/markdown/snippets/python-installation-pure.md
Normal file
8
docs/markdown/snippets/python-installation-pure.md
Normal file
@@ -0,0 +1,8 @@
|
||||
## python.find_installation() now accepts pure argument
|
||||
|
||||
The default value of `pure:` for `py.install_sources()` and
|
||||
`py.get_install_dir()` can now be changed by explicitly passing a `pure:` kwarg
|
||||
to `find_installation()`.
|
||||
|
||||
This can be used to ensure that multiple `install_sources()` invocations do not
|
||||
forget to specify the kwarg each time.
|
||||
@@ -14,6 +14,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
import copy
|
||||
import functools
|
||||
import json
|
||||
import os
|
||||
@@ -67,7 +68,7 @@ if T.TYPE_CHECKING:
|
||||
|
||||
class PyInstallKw(TypedDict):
|
||||
|
||||
pure: bool
|
||||
pure: T.Optional[bool]
|
||||
subdir: str
|
||||
install_tag: T.Optional[str]
|
||||
|
||||
@@ -75,6 +76,7 @@ if T.TYPE_CHECKING:
|
||||
|
||||
disabler: bool
|
||||
modules: T.List[str]
|
||||
pure: T.Optional[bool]
|
||||
|
||||
_Base = ExternalDependency
|
||||
else:
|
||||
@@ -409,6 +411,7 @@ class PythonExternalProgram(ExternalProgram):
|
||||
'variables': {},
|
||||
'version': '0.0',
|
||||
}
|
||||
self.pure: bool = True
|
||||
|
||||
def _check_version(self, version: str) -> bool:
|
||||
if self.name == 'python2':
|
||||
@@ -472,7 +475,7 @@ class PythonExternalProgram(ExternalProgram):
|
||||
return rel_path
|
||||
|
||||
|
||||
_PURE_KW = KwargInfo('pure', bool, default=True)
|
||||
_PURE_KW = KwargInfo('pure', (bool, NoneType))
|
||||
_SUBDIR_KW = KwargInfo('subdir', str, default='')
|
||||
|
||||
|
||||
@@ -485,6 +488,7 @@ class PythonInstallation(ExternalProgramHolder):
|
||||
self.variables = info['variables']
|
||||
self.suffix = info['suffix']
|
||||
self.paths = info['paths']
|
||||
self.pure = python.pure
|
||||
self.platlib_install_path = os.path.join(prefix, python.platlib)
|
||||
self.purelib_install_path = os.path.join(prefix, python.purelib)
|
||||
self.version = info['version']
|
||||
@@ -599,7 +603,8 @@ class PythonInstallation(ExternalProgramHolder):
|
||||
def install_sources_method(self, args: T.Tuple[T.List[T.Union[str, mesonlib.File]]],
|
||||
kwargs: 'PyInstallKw') -> 'Data':
|
||||
tag = kwargs['install_tag'] or 'runtime'
|
||||
install_dir = self._get_install_dir_impl(kwargs['pure'], kwargs['subdir'])
|
||||
pure = kwargs['pure'] if kwargs['pure'] is not None else self.pure
|
||||
install_dir = self._get_install_dir_impl(pure, kwargs['subdir'])
|
||||
return self.interpreter.install_data_impl(
|
||||
self.interpreter.source_strings_to_files(args[0]),
|
||||
install_dir,
|
||||
@@ -610,7 +615,8 @@ class PythonInstallation(ExternalProgramHolder):
|
||||
@noPosargs
|
||||
@typed_kwargs('python_installation.install_dir', _PURE_KW, _SUBDIR_KW)
|
||||
def get_install_dir_method(self, args: T.List['TYPE_var'], kwargs: 'PyInstallKw') -> str:
|
||||
return self._get_install_dir_impl(kwargs['pure'], kwargs['subdir'])
|
||||
pure = kwargs['pure'] if kwargs['pure'] is not None else self.pure
|
||||
return self._get_install_dir_impl(pure, kwargs['subdir'])
|
||||
|
||||
def _get_install_dir_impl(self, pure: bool, subdir: str) -> P_OBJ.OptionString:
|
||||
if pure:
|
||||
@@ -733,6 +739,7 @@ class PythonModule(ExtensionModule):
|
||||
KwargInfo('required', (bool, UserFeatureOption), default=True),
|
||||
KwargInfo('disabler', bool, default=False, since='0.49.0'),
|
||||
KwargInfo('modules', ContainerTypeInfo(list, str), listify=True, default=[], since='0.51.0'),
|
||||
_PURE_KW.evolve(default=True, since='0.64.0'),
|
||||
)
|
||||
def find_installation(self, state: 'ModuleState', args: T.Tuple[T.Optional[str]],
|
||||
kwargs: 'FindInstallationKw') -> ExternalProgram:
|
||||
@@ -797,6 +804,8 @@ class PythonModule(ExtensionModule):
|
||||
raise mesonlib.MesonException('{} is missing modules: {}'.format(name_or_path or 'python', ', '.join(missing_modules)))
|
||||
return NonExistingExternalProgram()
|
||||
else:
|
||||
python = copy.copy(python)
|
||||
python.pure = kwargs['pure']
|
||||
return python
|
||||
|
||||
raise mesonlib.MesonBugException('Unreachable code was reached (PythonModule.find_installation).')
|
||||
|
||||
@@ -8,5 +8,13 @@ project('install path',
|
||||
py = import('python').find_installation()
|
||||
py.install_sources('test.py')
|
||||
py.install_sources('test.py', pure: false)
|
||||
install_data('test.py', install_dir: py.get_install_dir() / 'data')
|
||||
install_data('test.py', install_dir: py.get_install_dir(pure: false) / 'data')
|
||||
|
||||
py_plat = import('python').find_installation(pure: false)
|
||||
py_plat.install_sources('test.py', subdir: 'kw')
|
||||
py_plat.install_sources('test.py', pure: true, subdir: 'kwrevert')
|
||||
install_data('test.py', install_dir: py_plat.get_install_dir() / 'kw/data')
|
||||
install_data('test.py', install_dir: py_plat.get_install_dir(pure: true) / 'kwrevert/data')
|
||||
|
||||
subdir('structured')
|
||||
|
||||
@@ -6,7 +6,13 @@
|
||||
{"type": "file", "file": "pure/alpha/two.py"},
|
||||
{"type": "file", "file": "pure/alpha/three.py"},
|
||||
{"type": "file", "file": "pure/beta/one.py"},
|
||||
{"type": "file", "file": "plat/kw/test.py"},
|
||||
{"type": "file", "file": "pure/kwrevert/test.py"},
|
||||
{"type": "file", "file": "plat/test.py"},
|
||||
{"type": "file", "file": "pure/test.py"}
|
||||
{"type": "file", "file": "pure/test.py"},
|
||||
{"type": "file", "file": "plat/data/test.py"},
|
||||
{"type": "file", "file": "pure/data/test.py"},
|
||||
{"type": "file", "file": "plat/kw/data/test.py"},
|
||||
{"type": "file", "file": "pure/kwrevert/data/test.py"}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user