L i UddlmZddlZddlZddlmZddlmZddlm Z er ddlm Z ddl m Z e5Z ddlZddlmZdddGd d Zdd Zerdd lmZed Zded<yy#1swY.xYw)) annotationsN) TYPE_CHECKING) try_import)ArtifactNotFound)BinaryIO)S3Client) ClientErrorcHeZdZdZ d dd d dZd dZd dZd dZy)Boto3ArtifactStoreaAn artifact backend for Boto3. Args: bucket_name: The name of the bucket to store artifacts. client: A Boto3 client to use for storage operations. If not specified, a new client will be created. avoid_buf_copy: If True, skip procedure to copy the content of the source file object to a buffer before uploading it to S3 ins. This is default to False because using ``upload_fileobj()`` method of Boto3 client might close the source file object. Example: .. code-block:: python import optuna from optuna.artifacts import upload_artifact from optuna.artifacts import Boto3ArtifactStore artifact_store = Boto3ArtifactStore("my-bucket") 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 ... NF)avoid_buf_copyctj||_|xstjd|_||_y)Ns3)_importscheckbucketboto3client_avoid_buf_copy)self bucket_namerr s ]/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/optuna/artifacts/_boto3.py__init__zBoto3ArtifactStore.__init__;s4 ! 2 T 2  .c |jj|j|}|j d}|J|S#t$r.}t |rt d|jd|d|d}~wwxYw)NBucketKeyzArtifact storage with bucket: z, artifact_id: z was not foundBody)r get_objectrr _is_not_found_errorrget)r artifact_idobjebodys r open_readerzBoto3ArtifactStore.open_readerEs ++(( (MCwwv  "1%&4T[[MQ\P]^!!   s'A A7 )A22A7c|}|js=tj}tj|||j d|}|j j||j|y)Nr) rioBytesIOshutil copyfileobjseekrupload_fileobjr)rr" content_bodyfsrcbufs rwritezBoto3ArtifactStore.writeSsU%##**,C   |S 1 HHQKD ""4kBrcR|jj|j|y)Nr)r delete_objectr)rr"s rremovezBoto3ArtifactStore.remove\s !!+!Fr)N)rstrrzS3Client | Noner boolreturnNone)r"r5r7r)r"r5r.rr7r8)r"r5r7r8)__name__ __module__ __qualname____doc__rr&r1r4rrr r sK#L;?.Z_..(7.SW. . CGrr c|jjdijd}|jjdijd}|dk(xs|dk(S)NErrorCodeResponseMetadataHTTPStatusCode NoSuchKeyi)responser!)r$ error_codehttp_status_codes rr r `sY,008Jzz~~&8"=AABRS  $ ?(8C(??r) ArtifactStorerG_)r$r r7r6) __future__rr(r*typingroptuna._importsroptuna.artifacts.exceptionsrr mypy_boto3_s3rrrbotocore.exceptionsr r r optuna.artifacts._protocolrGrI__annotations__r=rrrRsx" &8&\0X/0 HGHGV@ 9)"-A}- m00s A//A8