Skip to content

Commit

Permalink
Merge pull request optuna#5565 from nabenabe0928/enhance/add-import-c…
Browse files Browse the repository at this point in the history
…heck-to-artifact-store-objects

Add import check for artifact store objects
  • Loading branch information
HideakiImamura authored Jul 24, 2024
2 parents 83a4ccf + c799237 commit 8781df0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion optuna/artifacts/_boto3.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from mypy_boto3_s3 import S3Client

with try_import():
with try_import() as _imports:
import boto3
from botocore.exceptions import ClientError

Expand Down Expand Up @@ -59,6 +59,7 @@ def objective(trial: optuna.Trial) -> float:
def __init__(
self, bucket_name: str, client: S3Client | None = None, *, avoid_buf_copy: bool = False
) -> None:
_imports.check()
self.bucket = bucket_name
self.client = client or boto3.client("s3")
# This flag is added to avoid that upload_fileobj() method of Boto3 client may close the
Expand Down
3 changes: 2 additions & 1 deletion optuna/artifacts/_gcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
if TYPE_CHECKING:
from typing import BinaryIO

with try_import():
with try_import() as _imports:
import google.cloud.storage


Expand Down Expand Up @@ -61,6 +61,7 @@ def __init__(
bucket_name: str,
client: google.cloud.storage.Client | None = None,
) -> None:
_imports.check()
self.bucket_name = bucket_name
self.client = client or google.cloud.storage.Client()
self.bucket_obj = self.client.bucket(bucket_name)
Expand Down

0 comments on commit 8781df0

Please sign in to comment.