Add install-tags filtering for wheel generation#267
Add install-tags filtering for wheel generation#267Brishen wants to merge 6 commits intomesonbuild:mainfrom
Conversation
# Conflicts: # mesonpy/__init__.py
| for cmd in self.build_commands(): | ||
| self._meson(*cmd[1:]) | ||
| 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'],) |
There was a problem hiding this comment.
I think this may have happened because of the merge, but this code now needs to go into build_commands.
There was a problem hiding this comment.
True, this is a merge error, my code was still based on a very old version of meson-python
There was a problem hiding this comment.
if install-tags is not separated from the "install" args, this whole block can be reverted to
for cmd in self.build_commands(): self._meson(*cmd[1:])
|
|
||
|
|
||
| MesonArgsKeys = Literal['dist', 'setup', 'compile', 'install'] | ||
| MesonArgsKeys = Literal['dist', 'setup', 'compile', 'install', 'install-tags'] |
There was a problem hiding this comment.
I wonder it wouldn't just be better to parse this from the install args.
There was a problem hiding this comment.
good point, I'll implement this
| MesonArgsKeys = Literal['dist', 'setup', 'compile', 'install', 'install-tags'] | |
| MesonArgsKeys = Literal['dist', 'setup', 'compile', 'install'] |
There was a problem hiding this comment.
Thanks! This can be done with argparse and parse_known_args.
| 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] |
There was a problem hiding this comment.
I'm not sure if we should do it here.
There was a problem hiding this comment.
i updated this block to parse the "install" args instead of using an extra 'install-tags' field
| 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] | |
| 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'].strip() not in install_tags: | |
| del files[file] | |
| return install_plan |
There was a problem hiding this comment.
@FFY00 This is just a suggestion (it was easy to implement it here).
If you give me some hints or thoughts on your doubts I could look for a better place to put this filter.
There was a problem hiding this comment.
This is a bit fragile, and I'd prefer not having to maintain it. I think it should be pretty easy to use argparse, as I mentioned in #267 (comment). What do you think?
There was a problem hiding this comment.
Oh ja, I didn't see the comment 🙂 I'll update the suggestion tomorrow
There was a problem hiding this comment.
Updated the suggestion to use argparse
| 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] | |
| 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) | |
| 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 |
naturally this needs import argparse at the beginning of the file
|
@Brishen I implemented the above made code suggestions in my fork. Could you update your PR? :-) |
|
@Brishen is it possible for you to update this pull request to adapt it to FFY00s comments? |
|
Closed in favor of #288. |
This is a PR for #68 comprising entirely of @peter-urban's work.