|
1 | 1 | import logging |
2 | | -from pathlib import Path |
3 | 2 | from typing import Optional, Union |
4 | 3 |
|
5 | | -from model_signing.api import SigningConfig |
6 | | - |
7 | 4 | from kagglehub import registry |
8 | 5 | from kagglehub.gcs_upload import normalize_patterns, upload_files_and_directories |
9 | 6 | from kagglehub.handle import parse_model_handle |
10 | 7 | from kagglehub.logger import EXTRA_CONSOLE_BLOCK |
11 | | -from kagglehub.models_helpers import create_model_if_missing, create_model_instance_or_version, signing_token |
| 8 | +from kagglehub.models_helpers import create_model_if_missing, create_model_instance_or_version |
| 9 | +from kagglehub.signing import sign_with_sigstore |
12 | 10 |
|
13 | 11 | logger = logging.getLogger(__name__) |
14 | 12 |
|
@@ -76,23 +74,14 @@ def model_upload( |
76 | 74 | # Model can be non-existent. Get token after model creation so signing token can be authorized. |
77 | 75 | try: |
78 | 76 | if sigstore: |
79 | | - token = signing_token(h.owner, h.model) |
80 | | - if token: |
81 | | - signing_file = Path(local_model_dir) / ".kaggle" / "signing.json" |
82 | | - signing_file.parent.mkdir(exist_ok=True, parents=True) |
83 | | - signing_file.unlink(missing_ok=True) |
84 | | - # The below will throw an exception if the token can't be verified (Needs to be a production token) |
85 | | - # Setting KAGGLE_API_ENDPOINT to localhost will throw the exception as stated above. |
86 | | - SigningConfig().set_sigstore_signer(identity_token=token, use_staging=False).sign( |
87 | | - Path(local_model_dir), signing_file |
88 | | - ) |
89 | | - else: |
90 | | - # skips transparency log publishing as we are unable to get a token |
91 | | - sigstore = False |
92 | | - logger.warning("Unable to retrieve identity token. Skipping signing...") |
93 | | - except Exception: |
94 | | - logger.exception("Signing failed. Skipping signing...") |
95 | | - sigstore = False |
| 77 | + sigstore = sign_with_sigstore(local_model_dir, h) |
| 78 | + except ImportError: |
| 79 | + import_warning_message = ( |
| 80 | + "The 'model_upload(...sign=True)' function requires the 'kagglehub[signing]' extras. " |
| 81 | + "Install them with 'pip install kagglehub[signing]'" |
| 82 | + ) |
| 83 | + # Inform the user if we detect that they didn't install everything |
| 84 | + raise ImportError(import_warning_message) from None |
96 | 85 |
|
97 | 86 | # Upload the model files to GCS |
98 | 87 | tokens = upload_files_and_directories( |
|
0 commit comments