Support setting Label in Jobs API - #3719
Conversation
- Add labels field to JobInfo and JobSpec dataclasses - Update _create_job_spec function to handle labels parameter - Add labels parameter to run_job and create_scheduled_job methods - Add CLI support for --label/-l flag in jobs run and scheduled run commands - Labels are passed as key-value pairs (e.g., --label KEY=VALUE) This matches the implementation in huggingface.js PR #1926 Co-authored-by: lucain <lucain@huggingface.co>
- Add labels parameter to run_uv_job and create_scheduled_uv_job - Add CLI support for labels in uv run and scheduled uv run commands - Update docstrings to document labels parameter Co-authored-by: lucain <lucain@huggingface.co>
- Add labels=None to all job-related test assertions - Update run_job, run_uv_job, and create_scheduled_job test expectations Co-authored-by: lucain <lucain@huggingface.co>
|
Cursor Agent can help with this pull request. Just |
Update CLI reference to document the new --label/-l flag for: - jobs run - jobs uv run - jobs scheduled run - jobs scheduled uv run Co-authored-by: lucain <lucain@huggingface.co>
|
@cursor can you factorize the logic labels => labels_map that is duplicated 3 times in the CLI ? |
|
Done! I've successfully refactored the duplicated label parsing logic. Here's what I did: Refactoring Summary Created a helper function Replaced 4 instances of duplicated code (9 lines each) across:
Result: The refactoring maintains the exact same functionality while making the codebase cleaner and more maintainable. |
Create _parse_labels_map() helper function to eliminate code duplication. The label parsing logic was duplicated 4 times across: - jobs_run - jobs_uv_run - scheduled_run - scheduled_uv_run This refactoring makes the code more maintainable and DRY. Co-authored-by: lucain <lucain@huggingface.co>
|
@cursor update signature to |
- Update _parse_labels_map to return Optional[dict[str, str]] - Return None when no labels provided (instead of empty dict) - Inline function calls: use labels=_parse_labels_map(label) directly - Remove unnecessary 'if labels_map else None' checks - Fix trailing whitespace in docstring (ruff W293) This makes the code cleaner and more Pythonic as suggested by @Wauplin. Co-authored-by: lucain <lucain@huggingface.co>
|
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. |
|
I also opened #3721 with basic docs on usage of |
* Add job labeling instructions to CLI guide Added documentation for labeling jobs in CLI. * Document Labels for Jobs in guides Added documentation for Labels in jobs, including examples.
Co-authored-by: Quentin Lhoest <42851186+lhoestq@users.noreply.github.com>
Makes perfect sense yes! I've merged your suggestions. I've also merged you docs update (#3721). Thanks! |
Update the jobs API to support labels, matching the implementation in the JS client (huggingface/huggingface.js#1926).
Slack Thread