feat: add resource caching and progress spinner for init/pull/branch#50
Merged
amansingh1720 merged 2 commits intomainfrom Mar 27, 2026
Merged
feat: add resource caching and progress spinner for init/pull/branch#50amansingh1720 merged 2 commits intomainfrom
amansingh1720 merged 2 commits intomainfrom
Conversation
…switch Made-with: Cursor
This comment has been minimized.
This comment has been minimized.
Contributor
Author
|
adding tests with on_save and current/total |
Made-with: Cursor
Contributor
Coverage Report
Changed file coverage
|
Comment on lines
+891
to
+910
| ctx = ( | ||
| console.status("[info]Saving resources...[/info]") if not output_json else nullcontext() | ||
| ) | ||
| on_save = None | ||
|
|
||
| with ctx as status: | ||
| if status: | ||
|
|
||
| def on_save(current: int, total: int) -> None: | ||
| status.update(f"[info]Saving resources ({current}/{total})...[/info]") | ||
|
|
||
| project, projection = AgentStudioProject.init_project( | ||
| base_path=base_path, | ||
| region=region, | ||
| account_id=account_id, | ||
| project_id=project_id, | ||
| format=format, | ||
| projection_json=projection_json, | ||
| on_save=on_save, | ||
| ) |
Collaborator
There was a problem hiding this comment.
We shouldn't pass on save if doing --json output
Contributor
Author
There was a problem hiding this comment.
that is already handled with this - on_save=None is passed to the function and inside project.py, the callback is guarded by if on:save so its effectively a no-op.
when output_json is True then
ctx = nullcontext() (no-op) from this line
console.status("[info]Saving resources...[/info]") if not output_json else nullcontext()
on_save = None
status is None inside the with block
'if status: False', so on_save stays None and falls outside the if block
- This was done to try and avoid duplication
Contributor
Author
|
poly/cli.py | 30.6% | -0.7% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Batch
MultiResourceYamlResourcewrites duringpoly initso each YAML file is written once instead of once per resource, and add a progress spinner toinit,pull, andbranch switchso the CLI doesn't appear stuck on large projects.Also edited CONTRIBUTING.md to edit the clone url - changed org to PolyAI.
Motivation
poly initis very slow on projects with many pronunciations (or other multi-resource YAML types) becausesave()rewrites the full YAML file for every single item. On large projects like pacden, the process appears stuck with no output. Thesave_to_cache+write_cache_to_filepattern already exists forpoly pull— this reuses it forinitand adds a progress spinner across all three commands.Changes
Use
save_to_cache=Truefor allMultiResourceYamlResourcesaves duringinit_project(), then flush to disk once viawrite_cache_to_file()Add an optional
on_save(current, total)callback toinit_project(),pull_project(),_update_multi_resource_yaml_resources(),_update_pulled_resources(), andswitch_branch()for progress reportingWire up
console.status()spinners incli.pyforinit,pull, andbranch switch, usingnullcontextto skip the spinner in--jsonmodeProgress counter includes both multi-resource (per batch total) and non-multi-resource types for an accurate total
CONTRIBUTING.md to edit the clone url - changed org from PolyAI-LDN to PolyAI.
Test strategy
poly <command>)Checklist
ruff check .andruff format --check .passpytestpasses (361 tests, 0 failures)polyCLI interface (or migration path documented)Screenshots / Logs
Before:

After:
