
    Di                        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      Zerd d	lmZ  ed
      Zded<   yy)    )annotationsN)Path)TYPE_CHECKING)ArtifactNotFound)BinaryIOc                  8    e Zd ZdZddZd	dZd
dZddZddZy)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 ...
    c                H    t        |t              rt        |      }|| _        y )N)
isinstancestrr   
_base_path)self	base_paths     b/home/ubuntu/crypto_trading_bot/.venv/lib/python3.12/site-packages/optuna/artifacts/_filesystem.py__init__z FileSystemArtifactStore.__init__0   s    i%YI#    c                   t         j                  j                  |      rt        d|       | j                  |z  }t         j                  j                  t         j                  j                  | j                        t         j                  j                  |      g      t         j                  j                  | j                        k7  rt        d|       |S )NzInvalid artifact_id: )ospathisabs
ValueErrorr   
commonpathabspath)r   artifact_idfilepaths      r   _get_filepathz%FileSystemArtifactStore._get_filepath6   s    77==%4[MBCC??[077WW__T__-rwwx/HI
WW__T__-. 4[MBCCr   c                |    | j                  |      }	 t        |d      }|S # t        $ r}t        d      |d }~ww xY w)Nrb	not found)r   openFileNotFoundErrorr   )r   r   r   fes        r   open_readerz#FileSystemArtifactStore.open_readerA   sI    %%k2	7Xt$A  ! 	7";/Q6	7s   ! 	;6;c                    | j                  |      }t        |d      5 }t        j                  ||       d d d        y # 1 sw Y   y xY w)Nwb)r   r    shutilcopyfileobj)r   r   content_bodyr   r"   s        r   writezFileSystemArtifactStore.writeI   sC    %%k2(D! 	0Q|Q/	0 	0 	0s	   >Ac                    | j                  |      }	 t        j                  |       y # t        $ r}t	        d      |d }~ww xY w)Nr   )r   r   remover!   r   )r   r   r   r#   s       r   r,   zFileSystemArtifactStore.removeN   s@    %%k2	7IIh  	7";/Q6	7s   ) 	A>AN)r   z
str | PathreturnNone)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!    @$	0
7r   r	   )ArtifactStore r4   _)
__future__r   r   pathlibr   r'   typingr   optuna.artifacts.exceptionsr   r   r	   optuna.artifacts._protocolr4   r6   __annotations__r3   r   r   <module>r=      sJ    " 	     8 D7 D7N  9.r2A}2 r   