o
    }oip	                     @  s   U d dl mZ d dlZd dlmZ d dlZd dlmZ d dlm	Z	 er)d dlm
Z
 G dd dZerBd d	lmZ ed
Zded< dS dS )    )annotationsN)Path)TYPE_CHECKING)ArtifactNotFound)BinaryIOc                   @  s8   e Zd ZdZdddZdddZdddZdddZdS )FileSystemArtifactStoreay  An artifact store for file systems.

    Args:
        base_path:
            The base path to a directory to store artifacts.

    Example:
        .. code-block:: python

            import os

            import optuna
            from optuna.artifacts import FileSystemArtifactStore
            from optuna.artifacts import upload_artifact


            base_path = "./artifacts"
            os.makedirs(base_path, exist_ok=True)
            artifact_store = FileSystemArtifactStore(base_path=base_path)


            def objective(trial: optuna.Trial) -> float:
                ... = trial.suggest_float("x", -10, 10)
                file_path = generate_example(...)
                upload_artifact(
                    artifact_store=artifact_store,
                    file_path=file_path,
                    study_or_trial=trial,
                )
                return ...
    	base_path
str | PathreturnNonec                 C  s   t |tr	t|}|| _d S )N)
isinstancestrr   
_base_path)selfr    r   P/home/ubuntu/.local/lib/python3.10/site-packages/optuna/artifacts/_filesystem.py__init__0   s   

z FileSystemArtifactStore.__init__artifact_idr   r   c              
   C  sD   t j| j|}zt|d}W |S  ty! } ztd|d }~ww )Nrb	not found)ospathjoinr   openFileNotFoundErrorr   )r   r   filepathfer   r   r   open_reader6   s   
z#FileSystemArtifactStore.open_readercontent_bodyc                 C  sL   t j| j|}t|d}t|| W d    d S 1 sw   Y  d S )Nwb)r   r   r   r   r   shutilcopyfileobj)r   r   r   r   r   r   r   r   write>   s   "zFileSystemArtifactStore.writec              
   C  sD   t j| j|}zt | W d S  ty! } ztd|d }~ww )Nr   )r   r   r   r   remover   r   )r   r   r   r   r   r   r   r$   C   s   
zFileSystemArtifactStore.removeN)r   r	   r
   r   )r   r   r
   r   )r   r   r   r   r
   r   )r   r   r
   r   )__name__
__module____qualname____doc__r   r   r#   r$   r   r   r   r   r      s    
 

r   )ArtifactStore r)   _)
__future__r   r   pathlibr   r!   typingr   optuna.artifacts.exceptionsr   r   r   optuna.artifacts._protocolr)   r+   __annotations__r   r   r   r   <module>   s    <