
    (^ip	                        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                  0    e Zd Z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     ]/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/optuna/artifacts/_filesystem.py__init__z FileSystemArtifactStore.__init__0   s    i%YI#    c                    t         j                  j                  | j                  |      }	 t	        |d      }|S # t
        $ r}t        d      |d }~ww xY w)Nrb	not found)ospathjoinr   openFileNotFoundErrorr   )r   artifact_idfilepathfes        r   open_readerz#FileSystemArtifactStore.open_reader6   sQ    77<<=	7Xt$A  ! 	7";/Q6	7s   : 	AAAc                    t         j                  j                  | j                  |      }t	        |d      5 }t        j                  ||       d d d        y # 1 sw Y   y xY w)Nwb)r   r   r   r   r   shutilcopyfileobj)r   r   content_bodyr   r   s        r   writezFileSystemArtifactStore.write>   sK    77<<=(D! 	0Q|Q/	0 	0 	0s   AA c                    t         j                  j                  | j                  |      }	 t        j                  |       y # t
        $ r}t        d      |d }~ww xY w)Nr   )r   r   r   r   remover   r   )r   r   r   r   s       r   r'   zFileSystemArtifactStore.removeC   sH    77<<=	7IIh  	7";/Q6	7s   A 	AAAN)r   z
str | PathreturnNone)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	      s    @$0
7r   r	   )ArtifactStore r/   _)
__future__r   r   pathlibr   r"   typingr   optuna.artifacts.exceptionsr   r   r	   optuna.artifacts._protocolr/   r1   __annotations__r.   r   r   <module>r8      sH    " 	     8 97 97x  9.r2A}2 r   