diff --git a/mesonpy/__init__.py b/mesonpy/__init__.py index d478eca2e..263c4121c 100644 --- a/mesonpy/__init__.py +++ b/mesonpy/__init__.py @@ -11,6 +11,7 @@ from __future__ import annotations +import argparse import collections import contextlib import functools @@ -921,7 +922,25 @@ def _info(self, name: str) -> Dict[str, Any]: @property def _install_plan(self) -> Dict[str, Dict[str, Dict[str, str]]]: """Meson install_plan metadata.""" - return self._info('intro-install_plan').copy() + + # copy the install plan so we can modify it + install_plan = self._info('intro-install_plan').copy() + + # parse install args for install tags (--tags) + parser = argparse.ArgumentParser() + parser.add_argument('--tags') + args, _ = parser.parse_known_args(self._meson_args['install']) + + # filter the install_plan for files that do not fit the install tags + if args.tags: + install_tags = args.tags.split(',') + + for files in install_plan.values(): + for file, details in list(files.items()): + if details['tag'].strip() not in install_tags: + del files[file] + + return install_plan @property def _copy_files(self) -> Dict[str, str]: diff --git a/tests/test_project.py b/tests/test_project.py index 79b950ee9..726238131 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -97,3 +97,14 @@ def last_two_meson_args(): def test_unknown_user_args(package, tmp_path_session): with pytest.raises(mesonpy.ConfigError): mesonpy.Project(package_dir / f'unknown-user-args-{package}', tmp_path_session) + + +def test_install_tags(package_purelib_and_platlib, tmp_path_session): + project = mesonpy.Project( + package_purelib_and_platlib, + tmp_path_session, + meson_args={ + 'install': ['--tags', 'purelib'], + } + ) + assert project.is_pure