o
    }oiI                     @  s   d dl mZ d dlmZ d dlmZ d dlZd dlZd dlZd dlm	Z	 d dl
Z
d dlmZ d dlmZ d dlmZ d d	lmZ e	rNd d
lmZ d dlmZ dZdZeG dd dZeg ddddddddd#d!d"ZdS )$    )annotations)asdict)	dataclassN)TYPE_CHECKING)convert_positional_args)Study)FrozenTrial)Trial)ArtifactStore)BaseStoragez
artifacts:zapplication/octet-streamc                   @  s2   e Zd ZU dZded< ded< ded< ded< dS )	ArtifactMetaa  Meta information for an artifact.

    .. note::
        All the artifact meta linked to a study or trial can be listed by
        :func:`~optuna.artifacts.get_all_artifact_meta`.
        The artifact meta can be used for :func:`~optuna.artifacts.download_artifact`.

    Args:
        artifact_id:
            The identifier of the artifact.
        filename:
            The artifact file name used for the upload.
        mimetype:
            A MIME type of the artifact.
            If not specified, the MIME type is guessed from the file extension.
        encoding:
            An encoding of the artifact, which is suitable for use as a Content-Encoding header,
            e.g., gzip. If not specified, the encoding is guessed from the file extension.
    strartifact_idfilenamemimetype
str | NoneencodingN)__name__
__module____qualname____doc____annotations__ r   r   L/home/ubuntu/.local/lib/python3.10/site-packages/optuna/artifacts/_upload.pyr      s   
 r   )study_or_trial	file_pathartifact_storez4.0.0z6.0.0)previous_positional_arg_namesdeprecated_versionremoved_version)storager   r   r   r
   r   r   r   Trial | FrozenTrial | Studyr    BaseStorage | Noner   r   r   returnc                 C  s  t j|}t|tr|du r|j}nt|tr|du r|j}|du r'tdt	t
 }t|\}}	t|||p<|p<t|p?|	d}
t| }t|ttfr]|j}|||tt|
 n|j}|||tt|
 t|d}| || W d   |S 1 sw   Y  |S )as  Upload an artifact to the artifact store.

    Args:
        artifact_store:
            An artifact store.
        file_path:
            A path to the file to be uploaded.
        study_or_trial:
            A :class:`~optuna.trial.Trial` object, a :class:`~optuna.trial.FrozenTrial`, or
            a :class:`~optuna.study.Study` object.
        storage:
            A storage object. This argument is required only if ``study_or_trial`` is
            :class:`~optuna.trial.FrozenTrial`.
        mimetype:
            A MIME type of the artifact. If not specified, the MIME type is guessed from the file
            extension.
        encoding:
            An encoding of the artifact, which is suitable for use as a ``Content-Encoding``
            header (e.g. gzip). If not specified, the encoding is guessed from the file extension.

    Returns:
        An artifact ID.
    Nz$storage is required for FrozenTrial.)r   r   r   r   rb)ospathbasename
isinstancer	   r    r   _storage
ValueErrorr   uuiduuid4	mimetypes
guess_typer   DEFAULT_MIME_TYPEARTIFACTS_ATTR_PREFIXr   	_trial_idset_trial_system_attrjsondumpsr   	_study_idset_study_system_attropenwrite)r   r   r   r    r   r   r   r   guess_mimetypeguess_encodingartifactattr_keytrial_idstudy_idfr   r   r   upload_artifact5   s6   &

r@   )r   r
   r   r   r   r!   r    r"   r   r   r   r   r#   r   )
__future__r   dataclassesr   r   r3   r-   r%   typingr   r+   optuna._convert_positional_argsr   optuna.studyr   optuna.trialr   r	   optuna.artifacts._protocolr
   optuna.storagesr   r0   r/   r   r@   r   r   r   r   <module>   s8    
