Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Keep a Data Recipes publish private when the Hub repo already exists (#12482)
Nilay0479621c26c8
diff --git a/studio/backend/core/data_recipe/huggingface.py b/studio/backend/core/data_recipe/huggingface.pyindex 1be9b4f00d7..a377d73179e 100644--- a/studio/backend/core/data_recipe/huggingface.py+++ b/studio/backend/core/data_recipe/huggingface.py@@ -55,6 +55,24 @@ def _drop_seed_token(builder_config: dict) -> None:seed_config.get("source", {}).pop("token", None)+def _ensure_hub_repo_private(hf_api, repo_id: str) -> None:+ # create_repo ignores `private` when the repo already exists.+ try:+ hf_api.update_repo_settings(repo_id = repo_id, private = True, repo_type = "dataset")+ return+ except Exception as exc:+ try:+ info = hf_api.repo_info(repo_id = repo_id, repo_type = "dataset")+ if bool(getattr(info, "private", False)):+ return+ except Exception:+ pass+ raise RecipeDatasetPublishError(+ f"Could not make {repo_id} private, so nothing was uploaded. The token likely "+ "lacks permission to change this repo's settings."+ ) from exc++def publish_recipe_dataset(*,artifact_path: str,@@ -91,6 +109,8 @@ def publish_recipe_dataset(client._validate_repo_id(repo_id = repo_id)client._validate_dataset_path(base_dataset_path = dataset_path)client._create_or_get_repo(repo_id = repo_id, private = private)+ if private:+ _ensure_hub_repo_private(client._api, repo_id)metadata_path = dataset_path / METADATA_FILENAMEbuilder_config_path = dataset_path / SDG_CONFIG_FILENAMEdiff --git a/studio/backend/tests/test_data_recipe_publish_private.py b/studio/backend/tests/test_data_recipe_publish_private.pynew file mode 100644index 00000000000..ff00e098587--- /dev/null+++ b/studio/backend/tests/test_data_recipe_publish_private.py@@ -0,0 +1,136 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++import sys+from types import ModuleType, SimpleNamespace++import pytest++from core.data_recipe import huggingface as recipe_hf+++class _Hub:+ def __init__(+ self,+ *,+ private,+ deny_settings = False,+ ):+ self.private = private+ self.deny_settings = deny_settings+ self.calls = []+ self.uploads = []++ def create_repo(self, *, repo_id, repo_type, exist_ok, private):+ self.calls.append("create_repo")++ def update_repo_settings(self, *, repo_id, private, repo_type):+ self.calls.append("update_repo_settings")+ assert repo_type == "dataset"+ if self.deny_settings:+ raise PermissionError("403 Forbidden")+ self.private = private++ def repo_info(self, *, repo_id, repo_type):+ return SimpleNamespace(private = self.private)++ def upload(self, name):+ self.uploads.append((name, self.private))+++def _stub_data_designer(monkeypatch, hub):+ class _UploadError(Exception):+ pass++ class _Client:+ def __init__(self, token):+ self._api = hub++ def _validate_repo_id(self, *, repo_id):+ pass++ def _validate_dataset_path(self, *, base_dataset_path):+ pass++ def _create_or_get_repo(self, *, repo_id, private):+ hub.create_repo(repo_id = repo_id, repo_type = "dataset", exist_ok = True, private = private)++ def _upload_main_dataset_files(self, *, repo_id, parquet_folder):+ hub.upload("data")++ def _upload_images_folder(self, *, repo_id, images_folder):+ hub.upload("images")++ def _upload_processor_files(self, *, repo_id, processors_folder):+ hub.upload("processors")++ def _upload_config_files(self, *, repo_id, metadata_path, builder_config_path):+ hub.upload("metadata.json")++ class _Card:+ @classmethod+ def from_metadata(cls, **kwargs):+ return SimpleNamespace(+ text = "", push_to_hub = lambda *args, **kwargs: hub.upload("README.md")+ )++ modules = {+ "data_designer.engine.storage.artifact_storage": {+ "FINAL_DATASET_FOLDER_NAME": "parquet-files",+ "METADATA_FILENAME": "metadata.json",+ "PROCESSORS_OUTPUTS_FOLDER_NAME": "processors-files",+ "SDG_CONFIG_FILENAME": "builder_config.json",+ },+ "data_designer.integrations.huggingface.client": {+ "HuggingFaceHubClient": _Client,+ "HuggingFaceHubClientUploadError": _UploadError,+ },+ "data_designer.integrations.huggingface.dataset_card": {+ "DataDesignerDatasetCard": _Card,+ },+ }+ for name, attrs in modules.items():+ module = ModuleType(name)+ for key, value in attrs.items():+ setattr(module, key, value)+ monkeypatch.setitem(sys.modules, name, module)+++def _publish(monkeypatch, tmp_path, hub, *, private):+ _stub_data_designer(monkeypatch, hub)+ monkeypatch.setattr(recipe_hf, "_resolve_recipe_artifact_path", lambda _: tmp_path)+ (tmp_path / "metadata.json").write_text("{}", encoding = "utf-8")+ return recipe_hf.publish_recipe_dataset(+ artifact_path = str(tmp_path),+ repo_id = "org/dataset",+ description = "d",+ hf_token = "hf_publish",+ private = private,+ )+++def test_private_publish_to_an_existing_public_repo_makes_it_private_first(monkeypatch, tmp_path):+ hub = _Hub(private = False)+ _publish(monkeypatch, tmp_path, hub, private = True)++ assert hub.private is True+ assert hub.uploads+ assert all(private for _, private in hub.uploads)+++def test_private_publish_uploads_nothing_when_the_repo_cannot_be_made_private(+ monkeypatch, tmp_path+):+ hub = _Hub(private = False, deny_settings = True)+ with pytest.raises(recipe_hf.RecipeDatasetPublishError, match = "private"):+ _publish(monkeypatch, tmp_path, hub, private = True)++ assert hub.uploads == []+++def test_public_publish_leaves_repo_settings_alone(monkeypatch, tmp_path):+ hub = _Hub(private = True)+ _publish(monkeypatch, tmp_path, hub, private = False)++ assert "update_repo_settings" not in hub.calls+ assert hub.private is True