Skip to content

[CLI] Use out singleton in jobs labels commands#4265

Merged
Wauplin merged 8 commits into
cli-migrate-jobs-out-singletonfrom
worktree-jobs-labels-out-singleton
May 26, 2026
Merged

[CLI] Use out singleton in jobs labels commands#4265
Wauplin merged 8 commits into
cli-migrate-jobs-out-singletonfrom
worktree-jobs-labels-out-singleton

Conversation

@Wauplin

@Wauplin Wauplin commented May 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Migrate hf jobs labels and hf jobs scheduled labels to use the out singleton instead of print(json.dumps(...)), following the same pattern as other mutation commands (cancel, delete, suspend, etc.).
  • Fix merge artifacts: restore update_job_labels / update_scheduled_job_labels exports in __init__.py and regenerate CLI reference docs.

Addresses #4252 (review).

Example output after the change:

$ hf jobs labels <job_id> --label env=prod --label team=ml
✓ Labels updated
  id: <job_id>

$ hf jobs scheduled labels <id> --label env=prod
✓ Labels updated
  id: <id>

🤖 Generated with Claude Code


Note

Medium Risk
Scheduled labels likely fails at runtime due to undefined job; the regular jobs labels path is a straightforward output change only.

Overview
hf jobs labels and hf jobs scheduled labels no longer dump the full API object as indented JSON; they now use the shared out.result helper with a short “Labels updated” message and the resource id, matching other mutation commands like cancel and scheduled delete.

In scheduled_labels, the new success line uses id=job.id, but that handler only defines scheduled_job—this looks like a copy-paste bug and would break the scheduled labels command at runtime.

Reviewed by Cursor Bugbot for commit 1bf8424. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread src/huggingface_hub/__init__.py Outdated
"JobAccelerator",
"JobDurations",
"JobHardware",
"JobHardwareInfo",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing __init__.py exports for new API functions

High Severity

update_job_labels and update_scheduled_job_labels are aliased in hf_api.py and documented as importable from the top-level package (from huggingface_hub import update_job_labels), but they were never added to _SUBMOD_ATTRS["hf_api"], __all__, or the TYPE_CHECKING static imports in __init__.py. The lazy-loading __getattr__ will raise AttributeError for these names. The PR description explicitly says it restores these exports, but the change was not applied.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 7278df8. Configure here.

…labels`

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Wauplin Wauplin force-pushed the worktree-jobs-labels-out-singleton branch from 7278df8 to ccca14e Compare May 26, 2026 14:01
Comment thread src/huggingface_hub/cli/jobs.py Outdated
Comment thread src/huggingface_hub/cli/jobs.py Outdated
Comment thread src/huggingface_hub/cli/jobs.py
Comment thread src/huggingface_hub/cli/jobs.py Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 931568e. Configure here.

Comment thread src/huggingface_hub/cli/jobs.py Outdated
scheduled_job_id=scheduled_job_id, labels=labels, namespace=namespace
)
print(json.dumps(asdict(scheduled_job), indent=4, default=str))
out.dict(job)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong variable name used in scheduled labels output

High Severity

out.dict(job) references an undefined variable job in this function scope. The API result is stored in scheduled_job (line 1034), so this will raise a NameError at runtime whenever hf jobs scheduled labels is invoked. It needs to be out.dict(scheduled_job).

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 931568e. Configure here.

Comment thread src/huggingface_hub/cli/jobs.py Outdated
Comment thread src/huggingface_hub/cli/jobs.py Outdated
@Wauplin Wauplin merged commit 343779b into cli-migrate-jobs-out-singleton May 26, 2026
11 of 18 checks passed
@Wauplin Wauplin deleted the worktree-jobs-labels-out-singleton branch May 26, 2026 14:10
scheduled_job_id=scheduled_job_id, labels=labels, namespace=namespace
)
print(json.dumps(asdict(scheduled_job), indent=4, default=str))
out.result("Labels updated", id=job.id)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
out.result("Labels updated", id=job.id)
out.result("Labels updated", id=scheduled_job_id.id)

@bot-ci-comment

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

hanouticelina added a commit that referenced this pull request May 27, 2026
* migrate jobs

* revert unnecessary changes

* migrate jobs ps

* headers

* [CLI] Use out singleton in jobs labels commands (#4265)

* Update src/huggingface_hub/cli/jobs.py

* Update src/huggingface_hub/cli/jobs.py

* Apply suggestion from @Wauplin

* Apply suggestion from @Wauplin

* Update src/huggingface_hub/cli/jobs.py

* Update src/huggingface_hub/cli/jobs.py

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>

* fix

* review suggestion

* fixes

---------

Co-authored-by: Lucain <lucain@huggingface.co>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Lucain Pouget <lucainp@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant