diff options
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/coredata.py | 2 | ||||
-rw-r--r-- | mesonbuild/modules/python.py | 21 |
2 files changed, 23 insertions, 0 deletions
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index 4a84467..e5c0287 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -1218,6 +1218,8 @@ BUILTIN_CORE_OPTIONS: 'KeyedOptionDictType' = OrderedDict([ (OptionKey('force_fallback_for'), BuiltinOption(UserArrayOption, 'Force fallback for those subprojects', [])), # Python module + (OptionKey('install_env', module='python'), + BuiltinOption(UserComboOption, 'Which python environment to install to', 'prefix', choices=['auto', 'prefix', 'system', 'venv'])), (OptionKey('platlibdir', module='python'), BuiltinOption(UserStringOption, 'Directory for site-specific, platform-specific files.', '')), (OptionKey('purelibdir', module='python'), diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py index 2b62ea3..a91ec58 100644 --- a/mesonbuild/modules/python.py +++ b/mesonbuild/modules/python.py @@ -338,11 +338,13 @@ variables.update({'base_prefix': getattr(sys, 'base_prefix', sys.prefix)}) print(json.dumps({ 'variables': variables, 'paths': paths, + 'sysconfig_paths': sysconfig.get_paths(), 'install_paths': install_paths, 'sys_paths': sys.path, 'version': sysconfig.get_python_version(), 'platform': sysconfig.get_platform(), 'is_pypy': '__pypy__' in sys.builtin_module_names, + 'is_venv': sys.prefix != variables['base_prefix'], 'link_libpython': links_against_libpython(), })) ''' @@ -352,7 +354,9 @@ if T.TYPE_CHECKING: install_paths: T.Dict[str, str] is_pypy: bool + is_venv: bool link_libpython: bool + sysconfig_paths: T.Dict[str, str] paths: T.Dict[str, str] platform: str suffix: str @@ -377,7 +381,9 @@ class PythonExternalProgram(ExternalProgram): self.info: 'PythonIntrospectionDict' = { 'install_paths': {}, 'is_pypy': False, + 'is_venv': False, 'link_libpython': False, + 'sysconfig_paths': {}, 'paths': {}, 'platform': 'sentinal', 'variables': {}, @@ -422,7 +428,22 @@ class PythonExternalProgram(ExternalProgram): return rel_path value = state.get_option(f'{key}dir', module='python') if value: + if state.is_user_defined_option('install_env', module='python'): + raise mesonlib.MesonException(f'python.{key}dir and python.install_env are mutually exclusive') return value + + install_env = state.get_option('install_env', module='python') + if install_env == 'auto': + install_env = 'venv' if self.info['is_venv'] else 'system' + + if install_env == 'system': + rel_path = os.path.join(self.info['variables']['prefix'], rel_path) + elif install_env == 'venv': + if not self.info['is_venv']: + raise mesonlib.MesonException('python.install_env cannot be set to "venv" unless you are in a venv!') + # inside a venv, deb_system is *never* active hence info['paths'] may be wrong + rel_path = self.info['sysconfig_paths'][key] + # Use python's path relative to prefix, and warn if that's not a location # python will lookup for modules. abs_path = Path(state.get_option('prefix'), rel_path) |