perf: avoid heavy imports in snap config model
Metadata
Current evaluation
Merged PR #6427 to make snap_config.py lightweight, avoiding heavy imports in the configure hook. Replaces CraftBaseModel with pydantic.BaseModel and inlines helper functions. Fixes #6422.
Resolution: closed resolved
Reason: Merged as PR #6427. The PR refactors snap_config.py to use pydantic.BaseModel and inlines is_snapcraft_running_from_snap(), reducing import overhead in the configure hook and resolving #6422.
Evaluated by: mr-cal-bot
No scores available.
Issue body
Makes `snapcraft/snap_config.py` lightweight so the configure hook no longer
loads craft-application, craft-parts, or craft-providers.
- `SnapConfig` now subclasses `pydantic.BaseModel` with the same
`model_config` and `unmarshal()` behavior as `CraftBaseModel`.
- Inlines `is_snapcraft_running_from_snap()` to avoid importing
`snapcraft.utils`.
- Non-string providers (for example `provider=1`) now fail with the normal
validation error instead of an uncaught `AttributeError`.
- Adds tests for the import set, a fresh-process check that heavy libraries
aren't loaded, provider validation, and snap detection.
- Adds a 9.1.4 release note.
Fixes #6422
Describe your changes.
---
- [x] I've followed the [contribution guidelines](https://github.com/canonical/snapcraft/blob/main/CONTRIBUTING.md).
- [x] I've signed the [CLA](http://www.ubuntu.com/legal/contributors/).
- [x] I've successfully run `make lint && make test`.
- [x] I've added or updated any relevant documentation.
- [x] In documents I changed, I [added a meta description](https://canonical-starflow.readthedocs-hosted.com/how-to/add-a-page-meta-description/) if one was missing.
- [ ] I've updated the relevant release notes.
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| qwen/qwen3.6-35b-a3b | — | closed resolved | Merged PR #6427 to make snap_config.py lightweight, avoiding heavy imports in the configure hook. Replaces CraftBaseModel with pydantic.BaseModel and inlines helper functions. Fixes #6422. | |
| qwen/qwen3.6-35b-a3b | — | closed resolved | PR #6427 merged, refactoring snap_config.py to use pydantic.BaseModel to avoid heavy imports in the configure hook and resolve #6422. | |
| ~deepseek/deepseek-pro-latest |
Impact:
50
Quick Win:
9
Complexity:
50
Confidence:
70
Actionability:
35
|
keep open | Lightens snap_config.py so the configure hook avoids heavy craft-application/parts/providers imports; SnapConfig now subclasses pydantic.BaseModel; adds tests and a 9.1.4 release note. Under rework with failing CI and unresolved review feedback. | |
| ~deepseek/deepseek-pro-latest |
Impact:
58
Quick Win:
10
Complexity:
50
Confidence:
65
Actionability:
35
|
keep open | Reworks snap_config.py to avoid heavy imports in the configure hook; SnapConfig now subclasses pydantic.BaseModel, inlines snap detection, adds tests and a 9.1.4 release note. Under active rework; lint/files CI failing. | |
| ~deepseek/deepseek-pro-latest |
Impact:
55
Quick Win:
11
Complexity:
45
Confidence:
70
Actionability:
35
|
keep open | Makes snap_config.py lightweight so the configure hook avoids importing craft-application/parts/providers; SnapConfig now subclasses pydantic.BaseModel, inlines snap detection, adds tests and a 9.1.4 release note. Under active rework; lint/files CI failing. | |
| ~deepseek/deepseek-pro-latest |
Impact:
55
Quick Win:
10
Complexity:
60
Confidence:
60
Actionability:
45
|
needs review | Reworks configure hook to avoid importing snapcraft; SnapConfig now uses pydantic.BaseModel directly, inlines snap detection, keeps craft_cli. Awaiting re-review; OSV-scanner failing, lint/files pending. | |
| ~deepseek/deepseek-pro-latest |
Impact:
55
Quick Win:
8
Complexity:
40
Confidence:
70
Actionability:
25
|
keep open | Removes SnapConfig import from configure hook, validating provider via snaphelpers only; core tests pass but lint, publish, and OpenStack 24.04 CI fail; awaiting author response. | |
| stealth/space-bunny-alpha |
Impact:
52
Quick Win:
20
Complexity:
31
Confidence:
94
Actionability:
55
|
needs review | Removes heavy SnapConfig imports from the configure hook and validates only lxd or multipass. Core tests pass, but lint, publish, and OpenStack 24.04 CI jobs fail; maintainer review is pending. | |
| stealth/space-bunny-alpha |
Impact:
37
Quick Win:
12
Complexity:
32
Confidence:
66
Actionability:
46
|
needs review | Replaces the snapcraft snap configure hook's SnapConfig (pydantic/craft-*) import with snaphelpers-only validation of the `provider` key, cutting hook import time to avoid snapd timeouts. 0 reviews; `lint / files` and one spread job failing. | |
| stealth/space-bunny-alpha |
Impact:
50
Quick Win:
20
Complexity:
30
Confidence:
82
Actionability:
58
|
needs review | Removes the configure hook’s SnapConfig import and validates provider with snaphelpers, addressing #6422. Most checks pass, but lint/files and three additional jobs fail; maintainer review is pending. | |
| qwen/qwen3.6-35b-a3b |
Impact:
55
Quick Win:
27
Complexity:
25
Confidence:
75
Actionability:
65
|
needs review | Optimizes the configure hook to avoid importing heavy snapcraft dependencies, reducing startup time on slow hardware. Awaiting review with CI still running. |
Update history
| Date | Change |
|---|---|
| updated | |
| merged | |
| updated | |
| updated | |
| updated | |
| updated | |
| updated | |
| updated | |
| updated | |
| updated | |
| updated | |
| updated | |
| updated | |
| updated | |
| updated | |
| updated | |
| updated | |
| updated | |
| updated | |
| updated | |
| updated | |
| created |
Related work
-
Likely Fixed By:
canonical/snapcraft#6422
(confidence 100%)
The PR body explicitly states it fixes #6422.
-
Related To:
canonical/snapcraft#6493
(confidence 80%)
Mentioned by reviewer as addressing lint failures that were blocking this PR.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #6422 Optimize configure hook | snapcraft | closed | Optimized configure hook by reducing imports in snap_config.py; resolved by merged PR #6427 which makes SnapConfig lightweight. | |
| #239 feat(snap_config): add snap_config model and utilities | craft-application | merged | Merged PR #239 as commit 21393ee7, adding generic snap_config models and utilities imported from Snapcraft for CRAFT-2477 build-mode support. |