pluginhandler: fix stage-snaps for v2 plugins
Metadata
Current evaluation
Merged fix for v2 plugin AttributeError caused by missing stage_snaps attribute. Updated logging to use part_install_dir and resolved prepare_build clearing the install directory. Approved and passed CI.
Suggested action: —
No scores available.
Issue body
- [x] Have you followed the [guidelines for contributing](https://github.com/snapcore/snapcraft/blob/master/CONTRIBUTING.md)?
- [x] Have you signed the [CLA](http://www.ubuntu.com/legal/contributors/)?
- [x] Have you successfully run `./runtests.sh static`?
- [x] Have you successfully run `./runtests.sh tests/unit`?
-----
The `PluginHandler._unpack_stage_snaps` method makes use of an attribute on the plugin object that does not seem to exist on v2 plugins, leading to errors like:
```
...
File "/snap/snapcraft/5143/lib/python3.6/site-packages/snapcraft/internal/lifecycle/_runner.py", line 247, in _run_pull
self._run_step(step=steps.PULL, part=part, progress="Pulling")
File "/snap/snapcraft/5143/lib/python3.6/site-packages/snapcraft/internal/lifecycle/_runner.py", line 322, in _run_step
self._prepare_step(step=step, part=part)
File "/snap/snapcraft/5143/lib/python3.6/site-packages/snapcraft/internal/lifecycle/_runner.py", line 313, in _prepare_step
preparation_function()
File "/snap/snapcraft/5143/lib/python3.6/site-packages/snapcraft/internal/pluginhandler/__init__.py", line 469, in prepare_pull
self._unpack_stage_snaps()
File "/snap/snapcraft/5143/lib/python3.6/site-packages/snapcraft/internal/pluginhandler/__init__.py", line 434, in _unpack_stage_snaps
logger.debug("Unpacking stage-snaps to {!r}".format(self.plugin.stage_snaps))
AttributeError: 'NilPlugin' object has no attribute 'stage_snaps'
```
The value being substituted into the log message doesn't really match the text of the log message, so I switched it to use `self.part_install_dir` instead.
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| qwen/qwen3.6-35b-a3b | — | — | Merged fix for v2 plugin AttributeError caused by missing stage_snaps attribute. Updated logging to use part_install_dir and resolved prepare_build clearing the install directory. Approved and passed CI. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Merged fix for AttributeError in _unpack_stage_snaps with v2 plugins. prepare_build() cleared the install directory, deleting unpacked stage snaps. Updated logic preserves and re-unpacks stage snaps during build preparation. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Merged fix for v2 plugin stage-snap failures. Resolved an AttributeError and premature deletion of unpacked snaps during prepare_build() by switching logging to part_install_dir and ensuring staged snaps are correctly re-unpacked. |
Update history
No update history recorded yet.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #3126 pluginhandler: allow cleaning the build step | snapcraft | merged | Merged fix resolving PluginV2 part cleanup failures caused by an improper guard in the clean_build method. Approved by reviewer, passed CI, and integrated into the codebase. | |
| #3317 plugin handler: properly handle snapcraftctl errors | snapcraft | merged | Merged fix for plugin handler to properly catch snapcraftctl errors. Replaced specific exception handling with a broad catch in the scriptlet runner to prevent silent failures and redundant output. Approved, passed CI, and increased coverage. |