Skip to content

Commit 000c5be

Browse files
authored
Merge pull request #67 from deepghs/dev/duplicate
dev(narugo): add duplicate operation into hfutils command
2 parents 2aea1db + 67452aa commit 000c5be

File tree

5 files changed

+79
-7
lines changed

5 files changed

+79
-7
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ jobs:
5757
fail-fast: false
5858
matrix:
5959
os:
60-
- 'ubuntu-20.04'
60+
- 'ubuntu-22.04'
6161
- 'windows-2019'
6262
- 'macos-13'
6363
python-version:
64-
- '3.8.0'
64+
- '3.8'
6565

6666
steps:
6767
- name: Get system version for Linux

.github/workflows/release_test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
fail-fast: false
1313
matrix:
1414
os:
15-
- 'ubuntu-20.04'
15+
- 'ubuntu-22.04'
1616
python-version:
1717
- '3.8'
1818

@@ -51,11 +51,11 @@ jobs:
5151
fail-fast: false
5252
matrix:
5353
os:
54-
- 'ubuntu-20.04'
54+
- 'ubuntu-22.04'
5555
- 'windows-2019'
5656
- 'macos-13'
5757
python-version:
58-
- '3.8.0'
58+
- '3.8'
5959

6060
steps:
6161
- name: Get system version for Linux

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ jobs:
129129
fail-fast: false
130130
matrix:
131131
os:
132-
- 'ubuntu-20.04'
132+
- 'ubuntu-22.04'
133133
- 'windows-2019'
134134
- 'macos-13'
135135
python-version:
136-
- '3.8.0'
136+
- '3.8'
137137

138138
steps:
139139
- name: Get system version for Linux

hfutils/entry/cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from .clone import _add_clone_subcommand
22
from .dispatch import hfutilcli
33
from .download import _add_download_subcommand
4+
from .duplicate import _add_duplicate_subcommand
45
from .ils import _add_ils_subcommand
56
from .index import _add_index_subcommand
67
from .ls import _add_ls_subcommand
@@ -23,6 +24,7 @@
2324
_add_tree_subcommand,
2425
_add_ils_subcommand,
2526
_add_squash_subcommand,
27+
_add_duplicate_subcommand,
2628
]
2729

2830
cli = hfutilcli

hfutils/entry/duplicate.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
"""
2+
HuggingFace Repository Duplication Module
3+
4+
This module provides functionality for duplicating repositories on HuggingFace Hub via command line interface.
5+
It includes commands and utilities to copy repositories while preserving their content and structure.
6+
"""
7+
8+
import click
9+
from huggingface_hub import configure_http_backend
10+
11+
from .base import CONTEXT_SETTINGS, command_wrap
12+
from ..operate import hf_repo_duplicate
13+
from ..operate.base import REPO_TYPES, RepoTypeTyping
14+
from ..utils import get_requests_session
15+
16+
17+
def _add_duplicate_subcommand(cli: click.Group) -> click.Group:
18+
"""
19+
Add the duplicate subcommand to the CLI group.
20+
21+
This function adds a 'duplicate' command to the provided Click CLI group that enables
22+
repository duplication on HuggingFace Hub. It configures all necessary options and
23+
handles the execution flow.
24+
25+
:param cli: The Click command group to add the duplicate command to
26+
:type cli: click.Group
27+
28+
:return: The modified CLI group with the duplicate command added
29+
:rtype: click.Group
30+
"""
31+
32+
@cli.command('duplicate', help='Duplicate Repository on HuggingFace.\n\n'
33+
'Set environment $HF_TOKEN to use your own access token.',
34+
context_settings=CONTEXT_SETTINGS)
35+
@click.option('-r', '--src_repo', 'src_repo_id', type=str, required=True,
36+
help='Repository to be duplicated.')
37+
@click.option('-R', '--dst_repo', 'dst_repo_id', type=str, required=True,
38+
help='Repository to duplicate to.')
39+
@click.option('-t', '--type', 'repo_type', type=click.Choice(REPO_TYPES), default='dataset',
40+
help='Type of the HuggingFace repository.', show_default=True)
41+
@click.option('--private', 'private', type=bool, is_flag=True, default=False,
42+
help='Duplicate as a private repository.')
43+
@command_wrap()
44+
def duplicate(src_repo_id: str, dst_repo_id: str, repo_type: RepoTypeTyping, private: bool):
45+
"""
46+
Duplicate a HuggingFace repository to a new location.
47+
48+
This command duplicates an existing HuggingFace repository to a new destination,
49+
with options to specify the repository type and visibility settings.
50+
51+
:param src_repo_id: The source repository ID to duplicate from
52+
:type src_repo_id: str
53+
:param dst_repo_id: The destination repository ID to duplicate to
54+
:type dst_repo_id: str
55+
:param repo_type: The type of repository (dataset, model, etc.)
56+
:type repo_type: RepoTypeTyping
57+
:param private: Whether the duplicated repository should be private
58+
:type private: bool
59+
60+
:raises: Various exceptions from huggingface_hub based on operation status
61+
"""
62+
configure_http_backend(get_requests_session)
63+
hf_repo_duplicate(
64+
src_repo_id=src_repo_id,
65+
dst_repo_id=dst_repo_id,
66+
repo_type=repo_type,
67+
private=private,
68+
)
69+
70+
return cli

0 commit comments

Comments
 (0)