Commit 540ff6d
[adapter,docs] refactor: hoist HF imports to module top; codify rule
Move the two `huggingface_hub` imports added in the previous commit
out of function bodies and up to the module's import block:
- `from huggingface_hub import snapshot_download` in
`src/flow_factory/utils/checkpoint.py`
- `from huggingface_hub.errors import RepositoryNotFoundError,
HfHubHTTPError` in `src/flow_factory/models/abc.py`
`huggingface_hub` is already a hard dependency (`pyproject.toml:39`),
so there is no import-cost concern; lazy-loading only hid the
dependency surface from readers and `isort`.
Codify the rule so this pattern is caught in review going forward:
- Extend constraint X-GenGroup#22 ("Import Style") in
`.agents/knowledge/constraints.md` with an explicit "Top-level imports
only" bullet, listing the three sanctioned exceptions (optional deps
via `try/except ImportError`, backend-gated imports under runtime
feature checks like DeepSpeed/FSDP, and unresolvable circular imports).
- Add a matching checklist item to the Code Style section of
`.agents/skills/ff-review/SKILL.md`.
Pre-existing inline FSDP/DeepSpeed imports in `models/abc.py` (lines
~997-1152) are grandfathered under the new rule's exception (b).
Co-authored-by: Cursor <cursoragent@cursor.com>1 parent 2207c92 commit 540ff6d
4 files changed
Lines changed: 4 additions & 4 deletions
File tree
- .agents
- knowledge
- skills/ff-review
- src/flow_factory
- models
- utils
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| 134 | + | |
134 | 135 | | |
135 | 136 | | |
136 | 137 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| 63 | + | |
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| |||
1484 | 1485 | | |
1485 | 1486 | | |
1486 | 1487 | | |
1487 | | - | |
1488 | | - | |
1489 | 1488 | | |
1490 | 1489 | | |
1491 | 1490 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
223 | 224 | | |
224 | 225 | | |
225 | 226 | | |
226 | | - | |
227 | | - | |
228 | 227 | | |
229 | 228 | | |
230 | 229 | | |
| |||
0 commit comments