From a7ad70c13b0c04528db430bc1b650fe29a7f3d82 Mon Sep 17 00:00:00 2001 From: Peter Urban Date: Fri, 25 Nov 2022 16:20:03 +0100 Subject: [PATCH 1/8] add unofficial 'install-tags' option --- mesonpy/__init__.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mesonpy/__init__.py b/mesonpy/__init__.py index f3c5ec807..a810f71ee 100644 --- a/mesonpy/__init__.py +++ b/mesonpy/__init__.py @@ -543,7 +543,7 @@ def build(self, directory: Path) -> pathlib.Path: return wheel_file -MesonArgsKeys = Literal['dist', 'setup', 'compile', 'install'] +MesonArgsKeys = Literal['dist', 'setup', 'compile', 'install', 'install-tags'] MesonArgs = Mapping[MesonArgsKeys, Collection[str]] @@ -735,7 +735,11 @@ def _wheel_builder(self) -> _WheelBuilder: def build(self) -> None: """Trigger the Meson build.""" self._meson('compile', *self._meson_args['compile'],) - self._meson('install', '--destdir', os.fspath(self._install_dir), *self._meson_args['install'],) + if self._meson_args['install-tags']: + install_tags = '--tags=' + ','.join(self._meson_args['install-tags']) + self._meson('install', '--destdir', os.fspath(self._install_dir), install_tags, *self._meson_args['install'],) + else: + self._meson('install', '--destdir', os.fspath(self._install_dir), *self._meson_args['install'],) @classmethod @contextlib.contextmanager @@ -760,6 +764,12 @@ def _info(self, name: str) -> Dict[str, Any]: @property def _install_plan(self) -> Dict[str, Dict[str, Dict[str, str]]]: + install_plan = self._info('intro-install_plan').copy() + + for files in install_plan.values(): + for file,details in list(files.items()): + if details['tag'] not in self._meson_args['install-tags']: + del files[file] """Meson install_plan metadata.""" return self._info('intro-install_plan').copy() From 794bf782b449e4657fce604bc55d46560f22b111 Mon Sep 17 00:00:00 2001 From: Brishen Hawkins Date: Tue, 17 Jan 2023 11:58:30 -0700 Subject: [PATCH 2/8] Update formatting in __init__.py --- mesonpy/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesonpy/__init__.py b/mesonpy/__init__.py index 2457e5f5c..09a844958 100644 --- a/mesonpy/__init__.py +++ b/mesonpy/__init__.py @@ -910,7 +910,7 @@ def _install_plan(self) -> Dict[str, Dict[str, Dict[str, str]]]: install_plan = self._info('intro-install_plan').copy() for files in install_plan.values(): - for file,details in list(files.items()): + for file, details in list(files.items()): if details['tag'] not in self._meson_args['install-tags']: del files[file] """Meson install_plan metadata.""" From bd05d113f8d122ab4340b1cca015bb2c02d69045 Mon Sep 17 00:00:00 2001 From: Peter Urban Date: Wed, 18 Jan 2023 01:41:45 +0100 Subject: [PATCH 3/8] parse install args instead of using an extra install-tags field --- mesonpy/__init__.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/mesonpy/__init__.py b/mesonpy/__init__.py index 09a844958..6d644a0fd 100644 --- a/mesonpy/__init__.py +++ b/mesonpy/__init__.py @@ -631,7 +631,7 @@ def build_editable(self, directory: Path, verbose: bool = False) -> pathlib.Path return wheel_file -MesonArgsKeys = Literal['dist', 'setup', 'compile', 'install', 'install-tags'] +MesonArgsKeys = Literal['dist', 'setup', 'compile', 'install'] MesonArgs = Mapping[MesonArgsKeys, List[str]] @@ -876,12 +876,8 @@ def build_commands(self, install_dir: Optional[pathlib.Path] = None) -> Sequence @functools.lru_cache(maxsize=None) def build(self) -> None: """Trigger the Meson build.""" - self._meson('compile', *self._meson_args['compile'],) - if self._meson_args['install-tags']: - install_tags = '--tags=' + ','.join(self._meson_args['install-tags']) - self._meson('install', '--destdir', os.fspath(self._install_dir), install_tags, *self._meson_args['install'],) - else: - self._meson('install', '--destdir', os.fspath(self._install_dir), *self._meson_args['install'],) + for cmd in self.build_commands(): + self._meson(*cmd[1:]) @classmethod @contextlib.contextmanager @@ -907,14 +903,27 @@ def _info(self, name: str) -> Dict[str, Any]: @property def _install_plan(self) -> Dict[str, Dict[str, Dict[str, str]]]: + """Meson install_plan metadata.""" + + # copy the install plan so we can modify it install_plan = self._info('intro-install_plan').copy() + # parse install args for install tags (--tags) + install_tags = [] + for arg in self._meson_args['install']: + if arg.strip().startswith('--tags='): + install_tags = arg.split('=', 1)[1].split(',') + break + else: + return install_plan + + # filter out files that do not fit the install tags for files in install_plan.values(): for file, details in list(files.items()): - if details['tag'] not in self._meson_args['install-tags']: + if details['tag'].strip() not in install_tags: del files[file] - """Meson install_plan metadata.""" - return self._info('intro-install_plan').copy() + + return install_plan @property def _copy_files(self) -> Dict[str, str]: From dbf0943d7f25209e06f887f9cc397fe587eef1ba Mon Sep 17 00:00:00 2001 From: Peter Urban Date: Wed, 18 Jan 2023 07:45:07 +0100 Subject: [PATCH 4/8] use argparse to parse the "install" args for "--tags" --- mesonpy/__init__.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/mesonpy/__init__.py b/mesonpy/__init__.py index 6d644a0fd..0bc74faaa 100644 --- a/mesonpy/__init__.py +++ b/mesonpy/__init__.py @@ -10,6 +10,7 @@ from __future__ import annotations +import argparse import collections import contextlib import functools @@ -909,19 +910,18 @@ def _install_plan(self) -> Dict[str, Dict[str, Dict[str, str]]]: install_plan = self._info('intro-install_plan').copy() # parse install args for install tags (--tags) - install_tags = [] - for arg in self._meson_args['install']: - if arg.strip().startswith('--tags='): - install_tags = arg.split('=', 1)[1].split(',') - break - else: - return install_plan - - # filter out files that do not fit the install tags - for files in install_plan.values(): - for file, details in list(files.items()): - if details['tag'].strip() not in install_tags: - del files[file] + 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 From 37f905c9672b00f4a41047aa5342752444385f23 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 31 Jan 2023 01:42:17 +0000 Subject: [PATCH 5/8] MAINT: bump repositories MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/charliermarsh/ruff-pre-commit: v0.0.236 → v0.0.238](https://github.com/charliermarsh/ruff-pre-commit/compare/v0.0.236...v0.0.238) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 05dee1a6d..37c2304ac 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,7 +21,7 @@ repos: hooks: - id: isort - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.0.236 + rev: v0.0.238 hooks: - id: ruff args: [--fix, --format, grouped] From 2f9d21f6ce9034fc4aefaf9f6219238423f99803 Mon Sep 17 00:00:00 2001 From: Peter Urban Date: Tue, 31 Jan 2023 15:25:59 +0100 Subject: [PATCH 6/8] Revert "MAINT: bump repositories" This reverts commit 37f905c9672b00f4a41047aa5342752444385f23. --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 37c2304ac..05dee1a6d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,7 +21,7 @@ repos: hooks: - id: isort - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.0.238 + rev: v0.0.236 hooks: - id: ruff args: [--fix, --format, grouped] From c50574e4893feb6607e9314cc68934865b48385b Mon Sep 17 00:00:00 2001 From: Peter Urban Date: Tue, 31 Jan 2023 19:21:35 +0100 Subject: [PATCH 7/8] added test suggested by FFY00 --- tests/test_project.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_project.py b/tests/test_project.py index 4cfb177b2..b5adee33a 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -95,3 +95,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 From 1ea1a53dd1c576b55bab0e082ee1dea357dd4eae Mon Sep 17 00:00:00 2001 From: Peter Urban Date: Tue, 31 Jan 2023 19:54:39 +0100 Subject: [PATCH 8/8] apply pre-commit changes --- mesonpy/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mesonpy/__init__.py b/mesonpy/__init__.py index d2d93f7ad..263c4121c 100644 --- a/mesonpy/__init__.py +++ b/mesonpy/__init__.py @@ -922,7 +922,7 @@ def _info(self, name: str) -> Dict[str, Any]: @property def _install_plan(self) -> Dict[str, Dict[str, Dict[str, str]]]: """Meson install_plan metadata.""" - + # copy the install plan so we can modify it install_plan = self._info('intro-install_plan').copy() @@ -930,11 +930,11 @@ def _install_plan(self) -> Dict[str, Dict[str, Dict[str, str]]]: 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: