Skip to content

Commit 673ff9a

Browse files
committed
Remove remove_hf_folder param and change tar check
Delete the remove_hf_folder parameter from download_huggingface_model (and its docstring) and remove the related unit test. Also modify the tar extraction logic in _handle_downloaded_file by switching the TarInfo check from member.isdir() to member.isfile(), changing which tar members are processed during extraction.
1 parent b6a32f6 commit 673ff9a

2 files changed

Lines changed: 1 addition & 25 deletions

File tree

dlclibrary/dlcmodelzoo/modelzoo_download.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def _handle_downloaded_file(
123123
try:
124124
with tarfile.open(file_path, mode="r:gz") as tar:
125125
for member in tar:
126-
if not member.isdir():
126+
if not member.isfile():
127127
fname = Path(member.name).name
128128
extracted_path = os.path.join(target_dir, fname)
129129
with tar.extractfile(member) as src, open(extracted_path, "wb") as dst:
@@ -137,7 +137,6 @@ def _handle_downloaded_file(
137137
def download_huggingface_model(
138138
model_name: str,
139139
target_dir: str = ".",
140-
remove_hf_folder: bool = True,
141140
rename_mapping: str | dict | None = None,
142141
):
143142
"""
@@ -150,10 +149,6 @@ def download_huggingface_model(
150149
target_dir (str, optional):
151150
Target directory where the model weights will be stored.
152151
Defaults to the current directory.
153-
remove_hf_folder (bool, optional):
154-
Whether to remove the directory structure created by HuggingFace
155-
after downloading and decompressing the data into DeepLabCut format.
156-
Defaults to True.
157152
rename_mapping (dict | str | None, optional):
158153
- If a dictionary, it should map the original Hugging Face filenames
159154
to new filenames (e.g. {"snapshot-12345.tar.gz": "mymodel.tar.gz"}).

tests/test_modeldownload.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -169,22 +169,3 @@ def test_download_with_rename_mapping_for_pt(tmp_path, mock_modelzoo):
169169
files = {p.name for p in folder.iterdir()}
170170
assert "renamed_weights.pt" in files
171171
assert not any(name.startswith("models--") for name in files)
172-
173-
174-
def test_remove_hf_folder_flag_no_longer_affects_target_dir(tmp_path, mock_modelzoo):
175-
folder = tmp_path / "keep_cache"
176-
folder.mkdir()
177-
178-
dlclibrary.download_huggingface_model(
179-
"full_cat",
180-
str(folder),
181-
remove_hf_folder=False,
182-
)
183-
184-
files = {p.name for p in folder.iterdir()}
185-
186-
# Final artifact should still be there
187-
assert "full_cat.pt" in files
188-
189-
# HF cache should no longer be created inside target_dir
190-
assert not any(name.startswith("models--") for name in files)

0 commit comments

Comments
 (0)