huggingface-hub 0.34.6__py3-none-any.whl → 0.35.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of huggingface-hub might be problematic. Click here for more details.
- huggingface_hub/__init__.py +19 -1
- huggingface_hub/_jobs_api.py +159 -2
- huggingface_hub/_tensorboard_logger.py +9 -10
- huggingface_hub/cli/auth.py +1 -1
- huggingface_hub/cli/cache.py +3 -9
- huggingface_hub/cli/jobs.py +551 -1
- huggingface_hub/cli/repo.py +6 -4
- huggingface_hub/commands/delete_cache.py +2 -2
- huggingface_hub/commands/scan_cache.py +1 -1
- huggingface_hub/commands/user.py +1 -1
- huggingface_hub/hf_api.py +522 -78
- huggingface_hub/hf_file_system.py +3 -1
- huggingface_hub/hub_mixin.py +5 -3
- huggingface_hub/inference/_client.py +17 -180
- huggingface_hub/inference/_common.py +72 -70
- huggingface_hub/inference/_generated/_async_client.py +34 -200
- huggingface_hub/inference/_generated/types/chat_completion.py +2 -0
- huggingface_hub/inference/_mcp/_cli_hacks.py +3 -3
- huggingface_hub/inference/_mcp/cli.py +1 -1
- huggingface_hub/inference/_mcp/constants.py +1 -1
- huggingface_hub/inference/_mcp/mcp_client.py +28 -11
- huggingface_hub/inference/_mcp/types.py +3 -0
- huggingface_hub/inference/_mcp/utils.py +7 -3
- huggingface_hub/inference/_providers/_common.py +28 -4
- huggingface_hub/inference/_providers/black_forest_labs.py +1 -1
- huggingface_hub/inference/_providers/fal_ai.py +2 -2
- huggingface_hub/inference/_providers/hf_inference.py +15 -7
- huggingface_hub/inference/_providers/replicate.py +1 -1
- huggingface_hub/repocard.py +2 -1
- huggingface_hub/utils/_git_credential.py +1 -1
- huggingface_hub/utils/_typing.py +24 -4
- huggingface_hub/utils/_xet_progress_reporting.py +31 -10
- {huggingface_hub-0.34.6.dist-info → huggingface_hub-0.35.0.dist-info}/METADATA +7 -4
- {huggingface_hub-0.34.6.dist-info → huggingface_hub-0.35.0.dist-info}/RECORD +38 -38
- {huggingface_hub-0.34.6.dist-info → huggingface_hub-0.35.0.dist-info}/LICENSE +0 -0
- {huggingface_hub-0.34.6.dist-info → huggingface_hub-0.35.0.dist-info}/WHEEL +0 -0
- {huggingface_hub-0.34.6.dist-info → huggingface_hub-0.35.0.dist-info}/entry_points.txt +0 -0
- {huggingface_hub-0.34.6.dist-info → huggingface_hub-0.35.0.dist-info}/top_level.txt +0 -0
huggingface_hub/cli/jobs.py
CHANGED
|
@@ -68,6 +68,7 @@ class JobsCommands(BaseHuggingfaceCLICommand):
|
|
|
68
68
|
RunCommand.register_subcommand(jobs_subparsers)
|
|
69
69
|
CancelCommand.register_subcommand(jobs_subparsers)
|
|
70
70
|
UvCommand.register_subcommand(jobs_subparsers)
|
|
71
|
+
ScheduledJobsCommands.register_subcommand(jobs_subparsers)
|
|
71
72
|
|
|
72
73
|
|
|
73
74
|
class RunCommand(BaseHuggingfaceCLICommand):
|
|
@@ -299,7 +300,7 @@ class PsCommand(BaseHuggingfaceCLICommand):
|
|
|
299
300
|
command_str = " ".join(command) if command else "N/A"
|
|
300
301
|
|
|
301
302
|
# Extract creation time
|
|
302
|
-
created_at = job.created_at
|
|
303
|
+
created_at = job.created_at.strftime("%Y-%m-%d %H:%M:%S") if job.created_at else "N/A"
|
|
303
304
|
|
|
304
305
|
# Create a dict with all job properties for filtering
|
|
305
306
|
job_properties = {
|
|
@@ -548,3 +549,552 @@ def _get_extended_environ() -> Dict[str, str]:
|
|
|
548
549
|
if (token := get_token()) is not None:
|
|
549
550
|
extended_environ["HF_TOKEN"] = token
|
|
550
551
|
return extended_environ
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
class ScheduledJobsCommands(BaseHuggingfaceCLICommand):
|
|
555
|
+
@staticmethod
|
|
556
|
+
def register_subcommand(parser: _SubParsersAction):
|
|
557
|
+
scheduled_jobs_parser = parser.add_parser("scheduled", help="Create and manage scheduled Jobs on the Hub.")
|
|
558
|
+
scheduled_jobs_subparsers = scheduled_jobs_parser.add_subparsers(
|
|
559
|
+
help="huggingface.co scheduled jobs related commands"
|
|
560
|
+
)
|
|
561
|
+
|
|
562
|
+
# Show help if no subcommand is provided
|
|
563
|
+
scheduled_jobs_parser.set_defaults(func=lambda args: scheduled_jobs_subparsers.print_help())
|
|
564
|
+
|
|
565
|
+
# Register commands
|
|
566
|
+
ScheduledRunCommand.register_subcommand(scheduled_jobs_subparsers)
|
|
567
|
+
ScheduledPsCommand.register_subcommand(scheduled_jobs_subparsers)
|
|
568
|
+
ScheduledInspectCommand.register_subcommand(scheduled_jobs_subparsers)
|
|
569
|
+
ScheduledDeleteCommand.register_subcommand(scheduled_jobs_subparsers)
|
|
570
|
+
ScheduledSuspendCommand.register_subcommand(scheduled_jobs_subparsers)
|
|
571
|
+
ScheduledResumeCommand.register_subcommand(scheduled_jobs_subparsers)
|
|
572
|
+
ScheduledUvCommand.register_subcommand(scheduled_jobs_subparsers)
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
class ScheduledRunCommand(BaseHuggingfaceCLICommand):
|
|
576
|
+
@staticmethod
|
|
577
|
+
def register_subcommand(parser: _SubParsersAction) -> None:
|
|
578
|
+
run_parser = parser.add_parser("run", help="Schedule a Job")
|
|
579
|
+
run_parser.add_argument(
|
|
580
|
+
"schedule",
|
|
581
|
+
type=str,
|
|
582
|
+
help="One of annually, yearly, monthly, weekly, daily, hourly, or a CRON schedule expression.",
|
|
583
|
+
)
|
|
584
|
+
run_parser.add_argument("image", type=str, help="The Docker image to use.")
|
|
585
|
+
run_parser.add_argument(
|
|
586
|
+
"--suspend",
|
|
587
|
+
action="store_true",
|
|
588
|
+
help="Suspend (pause) the scheduled Job",
|
|
589
|
+
default=None,
|
|
590
|
+
)
|
|
591
|
+
run_parser.add_argument(
|
|
592
|
+
"--concurrency",
|
|
593
|
+
action="store_true",
|
|
594
|
+
help="Allow multiple instances of this Job to run concurrently",
|
|
595
|
+
default=None,
|
|
596
|
+
)
|
|
597
|
+
run_parser.add_argument("-e", "--env", action="append", help="Set environment variables. E.g. --env ENV=value")
|
|
598
|
+
run_parser.add_argument(
|
|
599
|
+
"-s",
|
|
600
|
+
"--secrets",
|
|
601
|
+
action="append",
|
|
602
|
+
help=(
|
|
603
|
+
"Set secret environment variables. E.g. --secrets SECRET=value "
|
|
604
|
+
"or `--secrets HF_TOKEN` to pass your Hugging Face token."
|
|
605
|
+
),
|
|
606
|
+
)
|
|
607
|
+
run_parser.add_argument("--env-file", type=str, help="Read in a file of environment variables.")
|
|
608
|
+
run_parser.add_argument("--secrets-file", type=str, help="Read in a file of secret environment variables.")
|
|
609
|
+
run_parser.add_argument(
|
|
610
|
+
"--flavor",
|
|
611
|
+
type=str,
|
|
612
|
+
help=f"Flavor for the hardware, as in HF Spaces. Defaults to `cpu-basic`. Possible values: {', '.join(SUGGESTED_FLAVORS)}.",
|
|
613
|
+
)
|
|
614
|
+
run_parser.add_argument(
|
|
615
|
+
"--timeout",
|
|
616
|
+
type=str,
|
|
617
|
+
help="Max duration: int/float with s (seconds, default), m (minutes), h (hours) or d (days).",
|
|
618
|
+
)
|
|
619
|
+
run_parser.add_argument(
|
|
620
|
+
"--namespace",
|
|
621
|
+
type=str,
|
|
622
|
+
help="The namespace where the scheduled Job will be created. Defaults to the current user's namespace.",
|
|
623
|
+
)
|
|
624
|
+
run_parser.add_argument(
|
|
625
|
+
"--token",
|
|
626
|
+
type=str,
|
|
627
|
+
help="A User Access Token generated from https://huggingface.co/settings/tokens",
|
|
628
|
+
)
|
|
629
|
+
run_parser.add_argument("command", nargs="...", help="The command to run.")
|
|
630
|
+
run_parser.set_defaults(func=ScheduledRunCommand)
|
|
631
|
+
|
|
632
|
+
def __init__(self, args: Namespace) -> None:
|
|
633
|
+
self.schedule: str = args.schedule
|
|
634
|
+
self.image: str = args.image
|
|
635
|
+
self.command: List[str] = args.command
|
|
636
|
+
self.suspend: Optional[bool] = args.suspend
|
|
637
|
+
self.concurrency: Optional[bool] = args.concurrency
|
|
638
|
+
self.env: dict[str, Optional[str]] = {}
|
|
639
|
+
if args.env_file:
|
|
640
|
+
self.env.update(load_dotenv(Path(args.env_file).read_text(), environ=os.environ.copy()))
|
|
641
|
+
for env_value in args.env or []:
|
|
642
|
+
self.env.update(load_dotenv(env_value, environ=os.environ.copy()))
|
|
643
|
+
self.secrets: dict[str, Optional[str]] = {}
|
|
644
|
+
extended_environ = _get_extended_environ()
|
|
645
|
+
if args.secrets_file:
|
|
646
|
+
self.secrets.update(load_dotenv(Path(args.secrets_file).read_text(), environ=extended_environ))
|
|
647
|
+
for secret in args.secrets or []:
|
|
648
|
+
self.secrets.update(load_dotenv(secret, environ=extended_environ))
|
|
649
|
+
self.flavor: Optional[SpaceHardware] = args.flavor
|
|
650
|
+
self.timeout: Optional[str] = args.timeout
|
|
651
|
+
self.namespace: Optional[str] = args.namespace
|
|
652
|
+
self.token: Optional[str] = args.token
|
|
653
|
+
|
|
654
|
+
def run(self) -> None:
|
|
655
|
+
api = HfApi(token=self.token)
|
|
656
|
+
scheduled_job = api.create_scheduled_job(
|
|
657
|
+
image=self.image,
|
|
658
|
+
command=self.command,
|
|
659
|
+
schedule=self.schedule,
|
|
660
|
+
suspend=self.suspend,
|
|
661
|
+
concurrency=self.concurrency,
|
|
662
|
+
env=self.env,
|
|
663
|
+
secrets=self.secrets,
|
|
664
|
+
flavor=self.flavor,
|
|
665
|
+
timeout=self.timeout,
|
|
666
|
+
namespace=self.namespace,
|
|
667
|
+
)
|
|
668
|
+
# Always print the scheduled job ID to the user
|
|
669
|
+
print(f"Scheduled Job created with ID: {scheduled_job.id}")
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
class ScheduledPsCommand(BaseHuggingfaceCLICommand):
|
|
673
|
+
@staticmethod
|
|
674
|
+
def register_subcommand(parser: _SubParsersAction) -> None:
|
|
675
|
+
run_parser = parser.add_parser("ps", help="List scheduled Jobs")
|
|
676
|
+
run_parser.add_argument(
|
|
677
|
+
"-a",
|
|
678
|
+
"--all",
|
|
679
|
+
action="store_true",
|
|
680
|
+
help="Show all scheduled Jobs (default hides suspended)",
|
|
681
|
+
)
|
|
682
|
+
run_parser.add_argument(
|
|
683
|
+
"--namespace",
|
|
684
|
+
type=str,
|
|
685
|
+
help="The namespace from where it lists the jobs. Defaults to the current user's namespace.",
|
|
686
|
+
)
|
|
687
|
+
run_parser.add_argument(
|
|
688
|
+
"--token",
|
|
689
|
+
type=str,
|
|
690
|
+
help="A User Access Token generated from https://huggingface.co/settings/tokens",
|
|
691
|
+
)
|
|
692
|
+
# Add Docker-style filtering argument
|
|
693
|
+
run_parser.add_argument(
|
|
694
|
+
"-f",
|
|
695
|
+
"--filter",
|
|
696
|
+
action="append",
|
|
697
|
+
default=[],
|
|
698
|
+
help="Filter output based on conditions provided (format: key=value)",
|
|
699
|
+
)
|
|
700
|
+
# Add option to format output
|
|
701
|
+
run_parser.add_argument(
|
|
702
|
+
"--format",
|
|
703
|
+
type=str,
|
|
704
|
+
help="Format output using a custom template",
|
|
705
|
+
)
|
|
706
|
+
run_parser.set_defaults(func=ScheduledPsCommand)
|
|
707
|
+
|
|
708
|
+
def __init__(self, args: Namespace) -> None:
|
|
709
|
+
self.all: bool = args.all
|
|
710
|
+
self.namespace: Optional[str] = args.namespace
|
|
711
|
+
self.token: Optional[str] = args.token
|
|
712
|
+
self.format: Optional[str] = args.format
|
|
713
|
+
self.filters: Dict[str, str] = {}
|
|
714
|
+
|
|
715
|
+
# Parse filter arguments (key=value pairs)
|
|
716
|
+
for f in args.filter:
|
|
717
|
+
if "=" in f:
|
|
718
|
+
key, value = f.split("=", 1)
|
|
719
|
+
self.filters[key.lower()] = value
|
|
720
|
+
else:
|
|
721
|
+
print(f"Warning: Ignoring invalid filter format '{f}'. Use key=value format.")
|
|
722
|
+
|
|
723
|
+
def run(self) -> None:
|
|
724
|
+
"""
|
|
725
|
+
Fetch and display scheduked job information for the current user.
|
|
726
|
+
Uses Docker-style filtering with -f/--filter flag and key=value pairs.
|
|
727
|
+
"""
|
|
728
|
+
try:
|
|
729
|
+
api = HfApi(token=self.token)
|
|
730
|
+
|
|
731
|
+
# Fetch jobs data
|
|
732
|
+
scheduled_jobs = api.list_scheduled_jobs(namespace=self.namespace)
|
|
733
|
+
|
|
734
|
+
# Define table headers
|
|
735
|
+
table_headers = [
|
|
736
|
+
"ID",
|
|
737
|
+
"SCHEDULE",
|
|
738
|
+
"IMAGE/SPACE",
|
|
739
|
+
"COMMAND",
|
|
740
|
+
"LAST RUN",
|
|
741
|
+
"NEXT RUN",
|
|
742
|
+
"SUSPEND",
|
|
743
|
+
]
|
|
744
|
+
|
|
745
|
+
# Process jobs data
|
|
746
|
+
rows = []
|
|
747
|
+
|
|
748
|
+
for scheduled_job in scheduled_jobs:
|
|
749
|
+
# Extract job data for filtering
|
|
750
|
+
suspend = scheduled_job.suspend
|
|
751
|
+
|
|
752
|
+
# Skip job if not all jobs should be shown and status doesn't match criteria
|
|
753
|
+
if not self.all and suspend:
|
|
754
|
+
continue
|
|
755
|
+
|
|
756
|
+
# Extract job ID
|
|
757
|
+
scheduled_job_id = scheduled_job.id
|
|
758
|
+
|
|
759
|
+
# Extract schedule
|
|
760
|
+
schedule = scheduled_job.schedule
|
|
761
|
+
|
|
762
|
+
# Extract image or space information
|
|
763
|
+
image_or_space = scheduled_job.job_spec.docker_image or "N/A"
|
|
764
|
+
|
|
765
|
+
# Extract and format command
|
|
766
|
+
command = scheduled_job.job_spec.command or []
|
|
767
|
+
command_str = " ".join(command) if command else "N/A"
|
|
768
|
+
|
|
769
|
+
# Extract status
|
|
770
|
+
last_job_at = (
|
|
771
|
+
scheduled_job.status.last_job.at.strftime("%Y-%m-%d %H:%M:%S")
|
|
772
|
+
if scheduled_job.status.last_job
|
|
773
|
+
else "N/A"
|
|
774
|
+
)
|
|
775
|
+
next_job_run_at = (
|
|
776
|
+
scheduled_job.status.next_job_run_at.strftime("%Y-%m-%d %H:%M:%S")
|
|
777
|
+
if scheduled_job.status.next_job_run_at
|
|
778
|
+
else "N/A"
|
|
779
|
+
)
|
|
780
|
+
|
|
781
|
+
# Create a dict with all job properties for filtering
|
|
782
|
+
job_properties = {
|
|
783
|
+
"id": scheduled_job_id,
|
|
784
|
+
"image": image_or_space,
|
|
785
|
+
"suspend": str(suspend),
|
|
786
|
+
"command": command_str,
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
# Check if job matches all filters
|
|
790
|
+
if not self._matches_filters(job_properties):
|
|
791
|
+
continue
|
|
792
|
+
|
|
793
|
+
# Create row
|
|
794
|
+
rows.append(
|
|
795
|
+
[
|
|
796
|
+
scheduled_job_id,
|
|
797
|
+
schedule,
|
|
798
|
+
image_or_space,
|
|
799
|
+
command_str,
|
|
800
|
+
last_job_at,
|
|
801
|
+
next_job_run_at,
|
|
802
|
+
suspend,
|
|
803
|
+
]
|
|
804
|
+
)
|
|
805
|
+
|
|
806
|
+
# Handle empty results
|
|
807
|
+
if not rows:
|
|
808
|
+
filters_msg = ""
|
|
809
|
+
if self.filters:
|
|
810
|
+
filters_msg = f" matching filters: {', '.join([f'{k}={v}' for k, v in self.filters.items()])}"
|
|
811
|
+
|
|
812
|
+
print(f"No scheduled jobs found{filters_msg}")
|
|
813
|
+
return
|
|
814
|
+
|
|
815
|
+
# Apply custom format if provided or use default tabular format
|
|
816
|
+
self._print_output(rows, table_headers)
|
|
817
|
+
|
|
818
|
+
except requests.RequestException as e:
|
|
819
|
+
print(f"Error fetching scheduled jobs data: {e}")
|
|
820
|
+
except (KeyError, ValueError, TypeError) as e:
|
|
821
|
+
print(f"Error processing scheduled jobs data: {e}")
|
|
822
|
+
except Exception as e:
|
|
823
|
+
print(f"Unexpected error - {type(e).__name__}: {e}")
|
|
824
|
+
|
|
825
|
+
def _matches_filters(self, job_properties: Dict[str, str]) -> bool:
|
|
826
|
+
"""Check if scheduled job matches all specified filters."""
|
|
827
|
+
for key, pattern in self.filters.items():
|
|
828
|
+
# Check if property exists
|
|
829
|
+
if key not in job_properties:
|
|
830
|
+
return False
|
|
831
|
+
|
|
832
|
+
# Support pattern matching with wildcards
|
|
833
|
+
if "*" in pattern or "?" in pattern:
|
|
834
|
+
# Convert glob pattern to regex
|
|
835
|
+
regex_pattern = pattern.replace("*", ".*").replace("?", ".")
|
|
836
|
+
if not re.search(f"^{regex_pattern}$", job_properties[key], re.IGNORECASE):
|
|
837
|
+
return False
|
|
838
|
+
# Simple substring matching
|
|
839
|
+
elif pattern.lower() not in job_properties[key].lower():
|
|
840
|
+
return False
|
|
841
|
+
|
|
842
|
+
return True
|
|
843
|
+
|
|
844
|
+
def _print_output(self, rows, headers):
|
|
845
|
+
"""Print output according to the chosen format."""
|
|
846
|
+
if self.format:
|
|
847
|
+
# Custom template formatting (simplified)
|
|
848
|
+
template = self.format
|
|
849
|
+
for row in rows:
|
|
850
|
+
line = template
|
|
851
|
+
for i, field in enumerate(
|
|
852
|
+
["id", "schedule", "image", "command", "last_job_at", "next_job_run_at", "suspend"]
|
|
853
|
+
):
|
|
854
|
+
placeholder = f"{{{{.{field}}}}}"
|
|
855
|
+
if placeholder in line:
|
|
856
|
+
line = line.replace(placeholder, str(row[i]))
|
|
857
|
+
print(line)
|
|
858
|
+
else:
|
|
859
|
+
# Default tabular format
|
|
860
|
+
print(
|
|
861
|
+
_tabulate(
|
|
862
|
+
rows,
|
|
863
|
+
headers=headers,
|
|
864
|
+
)
|
|
865
|
+
)
|
|
866
|
+
|
|
867
|
+
|
|
868
|
+
class ScheduledInspectCommand(BaseHuggingfaceCLICommand):
|
|
869
|
+
@staticmethod
|
|
870
|
+
def register_subcommand(parser: _SubParsersAction) -> None:
|
|
871
|
+
run_parser = parser.add_parser("inspect", help="Display detailed information on one or more scheduled Jobs")
|
|
872
|
+
run_parser.add_argument(
|
|
873
|
+
"--namespace",
|
|
874
|
+
type=str,
|
|
875
|
+
help="The namespace where the scheduled job is. Defaults to the current user's namespace.",
|
|
876
|
+
)
|
|
877
|
+
run_parser.add_argument(
|
|
878
|
+
"--token", type=str, help="A User Access Token generated from https://huggingface.co/settings/tokens"
|
|
879
|
+
)
|
|
880
|
+
run_parser.add_argument("scheduled_job_ids", nargs="...", help="The scheduled jobs to inspect")
|
|
881
|
+
run_parser.set_defaults(func=ScheduledInspectCommand)
|
|
882
|
+
|
|
883
|
+
def __init__(self, args: Namespace) -> None:
|
|
884
|
+
self.namespace: Optional[str] = args.namespace
|
|
885
|
+
self.token: Optional[str] = args.token
|
|
886
|
+
self.scheduled_job_ids: List[str] = args.scheduled_job_ids
|
|
887
|
+
|
|
888
|
+
def run(self) -> None:
|
|
889
|
+
api = HfApi(token=self.token)
|
|
890
|
+
scheduled_jobs = [
|
|
891
|
+
api.inspect_scheduled_job(scheduled_job_id=scheduled_job_id, namespace=self.namespace)
|
|
892
|
+
for scheduled_job_id in self.scheduled_job_ids
|
|
893
|
+
]
|
|
894
|
+
print(json.dumps([asdict(scheduled_job) for scheduled_job in scheduled_jobs], indent=4, default=str))
|
|
895
|
+
|
|
896
|
+
|
|
897
|
+
class ScheduledDeleteCommand(BaseHuggingfaceCLICommand):
|
|
898
|
+
@staticmethod
|
|
899
|
+
def register_subcommand(parser: _SubParsersAction) -> None:
|
|
900
|
+
run_parser = parser.add_parser("delete", help="Delete a scheduled Job")
|
|
901
|
+
run_parser.add_argument("scheduled_job_id", type=str, help="Scheduled Job ID")
|
|
902
|
+
run_parser.add_argument(
|
|
903
|
+
"--namespace",
|
|
904
|
+
type=str,
|
|
905
|
+
help="The namespace where the scheduled job is. Defaults to the current user's namespace.",
|
|
906
|
+
)
|
|
907
|
+
run_parser.add_argument(
|
|
908
|
+
"--token", type=str, help="A User Access Token generated from https://huggingface.co/settings/tokens"
|
|
909
|
+
)
|
|
910
|
+
run_parser.set_defaults(func=ScheduledDeleteCommand)
|
|
911
|
+
|
|
912
|
+
def __init__(self, args: Namespace) -> None:
|
|
913
|
+
self.scheduled_job_id: str = args.scheduled_job_id
|
|
914
|
+
self.namespace = args.namespace
|
|
915
|
+
self.token: Optional[str] = args.token
|
|
916
|
+
|
|
917
|
+
def run(self) -> None:
|
|
918
|
+
api = HfApi(token=self.token)
|
|
919
|
+
api.delete_scheduled_job(scheduled_job_id=self.scheduled_job_id, namespace=self.namespace)
|
|
920
|
+
|
|
921
|
+
|
|
922
|
+
class ScheduledSuspendCommand(BaseHuggingfaceCLICommand):
|
|
923
|
+
@staticmethod
|
|
924
|
+
def register_subcommand(parser: _SubParsersAction) -> None:
|
|
925
|
+
run_parser = parser.add_parser("suspend", help="Suspend (pause) a scheduled Job")
|
|
926
|
+
run_parser.add_argument("scheduled_job_id", type=str, help="Scheduled Job ID")
|
|
927
|
+
run_parser.add_argument(
|
|
928
|
+
"--namespace",
|
|
929
|
+
type=str,
|
|
930
|
+
help="The namespace where the scheduled job is. Defaults to the current user's namespace.",
|
|
931
|
+
)
|
|
932
|
+
run_parser.add_argument(
|
|
933
|
+
"--token", type=str, help="A User Access Token generated from https://huggingface.co/settings/tokens"
|
|
934
|
+
)
|
|
935
|
+
run_parser.set_defaults(func=ScheduledSuspendCommand)
|
|
936
|
+
|
|
937
|
+
def __init__(self, args: Namespace) -> None:
|
|
938
|
+
self.scheduled_job_id: str = args.scheduled_job_id
|
|
939
|
+
self.namespace = args.namespace
|
|
940
|
+
self.token: Optional[str] = args.token
|
|
941
|
+
|
|
942
|
+
def run(self) -> None:
|
|
943
|
+
api = HfApi(token=self.token)
|
|
944
|
+
api.suspend_scheduled_job(scheduled_job_id=self.scheduled_job_id, namespace=self.namespace)
|
|
945
|
+
|
|
946
|
+
|
|
947
|
+
class ScheduledResumeCommand(BaseHuggingfaceCLICommand):
|
|
948
|
+
@staticmethod
|
|
949
|
+
def register_subcommand(parser: _SubParsersAction) -> None:
|
|
950
|
+
run_parser = parser.add_parser("resume", help="Resume (unpause) a scheduled Job")
|
|
951
|
+
run_parser.add_argument("scheduled_job_id", type=str, help="Scheduled Job ID")
|
|
952
|
+
run_parser.add_argument(
|
|
953
|
+
"--namespace",
|
|
954
|
+
type=str,
|
|
955
|
+
help="The namespace where the scheduled job is. Defaults to the current user's namespace.",
|
|
956
|
+
)
|
|
957
|
+
run_parser.add_argument(
|
|
958
|
+
"--token", type=str, help="A User Access Token generated from https://huggingface.co/settings/tokens"
|
|
959
|
+
)
|
|
960
|
+
run_parser.set_defaults(func=ScheduledResumeCommand)
|
|
961
|
+
|
|
962
|
+
def __init__(self, args: Namespace) -> None:
|
|
963
|
+
self.scheduled_job_id: str = args.scheduled_job_id
|
|
964
|
+
self.namespace = args.namespace
|
|
965
|
+
self.token: Optional[str] = args.token
|
|
966
|
+
|
|
967
|
+
def run(self) -> None:
|
|
968
|
+
api = HfApi(token=self.token)
|
|
969
|
+
api.resume_scheduled_job(scheduled_job_id=self.scheduled_job_id, namespace=self.namespace)
|
|
970
|
+
|
|
971
|
+
|
|
972
|
+
class ScheduledUvCommand(BaseHuggingfaceCLICommand):
|
|
973
|
+
"""Schedule UV scripts on Hugging Face infrastructure."""
|
|
974
|
+
|
|
975
|
+
@staticmethod
|
|
976
|
+
def register_subcommand(parser):
|
|
977
|
+
"""Register UV run subcommand."""
|
|
978
|
+
uv_parser = parser.add_parser(
|
|
979
|
+
"uv",
|
|
980
|
+
help="Schedule UV scripts (Python with inline dependencies) on HF infrastructure",
|
|
981
|
+
)
|
|
982
|
+
|
|
983
|
+
subparsers = uv_parser.add_subparsers(dest="uv_command", help="UV commands", required=True)
|
|
984
|
+
|
|
985
|
+
# Run command only
|
|
986
|
+
run_parser = subparsers.add_parser(
|
|
987
|
+
"run",
|
|
988
|
+
help="Run a UV script (local file or URL) on HF infrastructure",
|
|
989
|
+
)
|
|
990
|
+
run_parser.add_argument(
|
|
991
|
+
"schedule",
|
|
992
|
+
type=str,
|
|
993
|
+
help="One of annually, yearly, monthly, weekly, daily, hourly, or a CRON schedule expression.",
|
|
994
|
+
)
|
|
995
|
+
run_parser.add_argument("script", help="UV script to run (local file or URL)")
|
|
996
|
+
run_parser.add_argument("script_args", nargs="...", help="Arguments for the script", default=[])
|
|
997
|
+
run_parser.add_argument(
|
|
998
|
+
"--suspend",
|
|
999
|
+
action="store_true",
|
|
1000
|
+
help="Suspend (pause) the scheduled Job",
|
|
1001
|
+
default=None,
|
|
1002
|
+
)
|
|
1003
|
+
run_parser.add_argument(
|
|
1004
|
+
"--concurrency",
|
|
1005
|
+
action="store_true",
|
|
1006
|
+
help="Allow multiple instances of this Job to run concurrently",
|
|
1007
|
+
default=None,
|
|
1008
|
+
)
|
|
1009
|
+
run_parser.add_argument("--image", type=str, help="Use a custom Docker image with `uv` installed.")
|
|
1010
|
+
run_parser.add_argument(
|
|
1011
|
+
"--repo",
|
|
1012
|
+
help="Repository name for the script (creates ephemeral if not specified)",
|
|
1013
|
+
)
|
|
1014
|
+
run_parser.add_argument(
|
|
1015
|
+
"--flavor",
|
|
1016
|
+
type=str,
|
|
1017
|
+
help=f"Flavor for the hardware, as in HF Spaces. Defaults to `cpu-basic`. Possible values: {', '.join(SUGGESTED_FLAVORS)}.",
|
|
1018
|
+
)
|
|
1019
|
+
run_parser.add_argument("-e", "--env", action="append", help="Environment variables")
|
|
1020
|
+
run_parser.add_argument(
|
|
1021
|
+
"-s",
|
|
1022
|
+
"--secrets",
|
|
1023
|
+
action="append",
|
|
1024
|
+
help=(
|
|
1025
|
+
"Set secret environment variables. E.g. --secrets SECRET=value "
|
|
1026
|
+
"or `--secrets HF_TOKEN` to pass your Hugging Face token."
|
|
1027
|
+
),
|
|
1028
|
+
)
|
|
1029
|
+
run_parser.add_argument("--env-file", type=str, help="Read in a file of environment variables.")
|
|
1030
|
+
run_parser.add_argument(
|
|
1031
|
+
"--secrets-file",
|
|
1032
|
+
type=str,
|
|
1033
|
+
help="Read in a file of secret environment variables.",
|
|
1034
|
+
)
|
|
1035
|
+
run_parser.add_argument("--timeout", type=str, help="Max duration (e.g., 30s, 5m, 1h)")
|
|
1036
|
+
run_parser.add_argument("-d", "--detach", action="store_true", help="Run in background")
|
|
1037
|
+
run_parser.add_argument(
|
|
1038
|
+
"--namespace",
|
|
1039
|
+
type=str,
|
|
1040
|
+
help="The namespace where the Job will be created. Defaults to the current user's namespace.",
|
|
1041
|
+
)
|
|
1042
|
+
run_parser.add_argument("--token", type=str, help="HF token")
|
|
1043
|
+
# UV options
|
|
1044
|
+
run_parser.add_argument("--with", action="append", help="Run with the given packages installed", dest="with_")
|
|
1045
|
+
run_parser.add_argument(
|
|
1046
|
+
"-p", "--python", type=str, help="The Python interpreter to use for the run environment"
|
|
1047
|
+
)
|
|
1048
|
+
run_parser.set_defaults(func=ScheduledUvCommand)
|
|
1049
|
+
|
|
1050
|
+
def __init__(self, args: Namespace) -> None:
|
|
1051
|
+
"""Initialize the command with parsed arguments."""
|
|
1052
|
+
self.schedule: str = args.schedule
|
|
1053
|
+
self.script = args.script
|
|
1054
|
+
self.script_args = args.script_args
|
|
1055
|
+
self.suspend: Optional[bool] = args.suspend
|
|
1056
|
+
self.concurrency: Optional[bool] = args.concurrency
|
|
1057
|
+
self.dependencies = args.with_
|
|
1058
|
+
self.python = args.python
|
|
1059
|
+
self.image = args.image
|
|
1060
|
+
self.env: dict[str, Optional[str]] = {}
|
|
1061
|
+
if args.env_file:
|
|
1062
|
+
self.env.update(load_dotenv(Path(args.env_file).read_text(), environ=os.environ.copy()))
|
|
1063
|
+
for env_value in args.env or []:
|
|
1064
|
+
self.env.update(load_dotenv(env_value, environ=os.environ.copy()))
|
|
1065
|
+
self.secrets: dict[str, Optional[str]] = {}
|
|
1066
|
+
extended_environ = _get_extended_environ()
|
|
1067
|
+
if args.secrets_file:
|
|
1068
|
+
self.secrets.update(load_dotenv(Path(args.secrets_file).read_text(), environ=extended_environ))
|
|
1069
|
+
for secret in args.secrets or []:
|
|
1070
|
+
self.secrets.update(load_dotenv(secret, environ=extended_environ))
|
|
1071
|
+
self.flavor: Optional[SpaceHardware] = args.flavor
|
|
1072
|
+
self.timeout: Optional[str] = args.timeout
|
|
1073
|
+
self.detach: bool = args.detach
|
|
1074
|
+
self.namespace: Optional[str] = args.namespace
|
|
1075
|
+
self.token: Optional[str] = args.token
|
|
1076
|
+
self._repo = args.repo
|
|
1077
|
+
|
|
1078
|
+
def run(self) -> None:
|
|
1079
|
+
"""Schedule UV command."""
|
|
1080
|
+
logging.set_verbosity(logging.INFO)
|
|
1081
|
+
api = HfApi(token=self.token)
|
|
1082
|
+
job = api.create_scheduled_uv_job(
|
|
1083
|
+
script=self.script,
|
|
1084
|
+
script_args=self.script_args,
|
|
1085
|
+
schedule=self.schedule,
|
|
1086
|
+
suspend=self.suspend,
|
|
1087
|
+
concurrency=self.concurrency,
|
|
1088
|
+
dependencies=self.dependencies,
|
|
1089
|
+
python=self.python,
|
|
1090
|
+
image=self.image,
|
|
1091
|
+
env=self.env,
|
|
1092
|
+
secrets=self.secrets,
|
|
1093
|
+
flavor=self.flavor,
|
|
1094
|
+
timeout=self.timeout,
|
|
1095
|
+
namespace=self.namespace,
|
|
1096
|
+
_repo=self._repo,
|
|
1097
|
+
)
|
|
1098
|
+
|
|
1099
|
+
# Always print the job ID to the user
|
|
1100
|
+
print(f"Scheduled Job created with ID: {job.id}")
|
huggingface_hub/cli/repo.py
CHANGED
|
@@ -183,7 +183,9 @@ class RepoTagCommand:
|
|
|
183
183
|
|
|
184
184
|
class RepoTagCreateCommand(RepoTagCommand):
|
|
185
185
|
def run(self):
|
|
186
|
-
print(
|
|
186
|
+
print(
|
|
187
|
+
f"You are about to create tag {ANSI.bold(str(self.args.tag))} on {self.repo_type} {ANSI.bold(self.repo_id)}"
|
|
188
|
+
)
|
|
187
189
|
try:
|
|
188
190
|
self.api.create_tag(
|
|
189
191
|
repo_id=self.repo_id,
|
|
@@ -196,14 +198,14 @@ class RepoTagCreateCommand(RepoTagCommand):
|
|
|
196
198
|
print(f"{self.repo_type.capitalize()} {ANSI.bold(self.repo_id)} not found.")
|
|
197
199
|
exit(1)
|
|
198
200
|
except RevisionNotFoundError:
|
|
199
|
-
print(f"Revision {ANSI.bold(getattr(self.args, 'revision', None))} not found.")
|
|
201
|
+
print(f"Revision {ANSI.bold(str(getattr(self.args, 'revision', None)))} not found.")
|
|
200
202
|
exit(1)
|
|
201
203
|
except HfHubHTTPError as e:
|
|
202
204
|
if e.response.status_code == 409:
|
|
203
|
-
print(f"Tag {ANSI.bold(self.args.tag)} already exists on {ANSI.bold(self.repo_id)}")
|
|
205
|
+
print(f"Tag {ANSI.bold(str(self.args.tag))} already exists on {ANSI.bold(self.repo_id)}")
|
|
204
206
|
exit(1)
|
|
205
207
|
raise e
|
|
206
|
-
print(f"Tag {ANSI.bold(self.args.tag)} created on {ANSI.bold(self.repo_id)}")
|
|
208
|
+
print(f"Tag {ANSI.bold(str(self.args.tag))} created on {ANSI.bold(self.repo_id)}")
|
|
207
209
|
|
|
208
210
|
|
|
209
211
|
class RepoTagListCommand(RepoTagCommand):
|
|
@@ -22,7 +22,7 @@ Usage:
|
|
|
22
22
|
|
|
23
23
|
NOTE:
|
|
24
24
|
This command is based on `InquirerPy` to build the multiselect menu in the terminal.
|
|
25
|
-
This dependency has to be installed with `pip install huggingface_hub[cli]`. Since
|
|
25
|
+
This dependency has to be installed with `pip install "huggingface_hub[cli]"`. Since
|
|
26
26
|
we want to avoid as much as possible cross-platform issues, I chose a library that
|
|
27
27
|
is built on top of `python-prompt-toolkit` which seems to be a reference in terminal
|
|
28
28
|
GUI (actively maintained on both Unix and Windows, 7.9k stars).
|
|
@@ -88,7 +88,7 @@ def require_inquirer_py(fn: Callable) -> Callable:
|
|
|
88
88
|
if not _inquirer_py_available:
|
|
89
89
|
raise ImportError(
|
|
90
90
|
"The `delete-cache` command requires extra dependencies to work with"
|
|
91
|
-
|
|
91
|
+
' the TUI.\nPlease run `pip install "huggingface_hub[cli]"` to install'
|
|
92
92
|
" them.\nOtherwise, disable TUI using the `--disable-tui` flag."
|
|
93
93
|
)
|
|
94
94
|
|
|
@@ -77,7 +77,7 @@ class ScanCacheCommand(BaseHuggingfaceCLICommand):
|
|
|
77
77
|
if self.verbosity >= 3:
|
|
78
78
|
print(ANSI.gray(message))
|
|
79
79
|
for warning in hf_cache_info.warnings:
|
|
80
|
-
print(ANSI.gray(warning))
|
|
80
|
+
print(ANSI.gray(str(warning)))
|
|
81
81
|
else:
|
|
82
82
|
print(ANSI.gray(message + " Use -vvv to print details."))
|
|
83
83
|
|
huggingface_hub/commands/user.py
CHANGED
|
@@ -195,7 +195,7 @@ class WhoamiCommand(BaseUserCommand):
|
|
|
195
195
|
exit()
|
|
196
196
|
try:
|
|
197
197
|
info = self._api.whoami(token)
|
|
198
|
-
print(
|
|
198
|
+
print(info["name"])
|
|
199
199
|
orgs = [org["name"] for org in info["orgs"]]
|
|
200
200
|
if orgs:
|
|
201
201
|
print(ANSI.bold("orgs: "), ",".join(orgs))
|