From 2b7cb4a417bf778149c1e86172218f8c2018f80a Mon Sep 17 00:00:00 2001 From: RektPunk Date: Thu, 11 Jul 2024 17:02:14 +0900 Subject: [PATCH 1/6] replace relative import to absolute path --- optuna/artifacts/_backoff.py | 4 ++-- optuna/artifacts/_boto3.py | 2 +- optuna/artifacts/_filesystem.py | 2 +- optuna/artifacts/_gcs.py | 2 +- optuna/samplers/_gp/__init__.py | 2 +- tests/artifacts_tests/test_backoff.py | 5 +++-- tests/storages_tests/rdb_tests/test_storage.py | 6 +++--- 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/optuna/artifacts/_backoff.py b/optuna/artifacts/_backoff.py index f8b6ce5f70..5633f74e0b 100644 --- a/optuna/artifacts/_backoff.py +++ b/optuna/artifacts/_backoff.py @@ -13,7 +13,7 @@ if TYPE_CHECKING: from typing import BinaryIO - from ._protocol import ArtifactStore + from optuna.artifacts._protocol import ArtifactStore class Backoff: @@ -112,6 +112,6 @@ def remove(self, artifact_id: str) -> None: if TYPE_CHECKING: # A mypy-runtime assertion to ensure that the Backoff middleware implements # all abstract methods in ArtifactStore. - from . import FileSystemArtifactStore + from optuna.artifacts._filesystem import FileSystemArtifactStore _: ArtifactStore = Backoff(FileSystemArtifactStore(".")) diff --git a/optuna/artifacts/_boto3.py b/optuna/artifacts/_boto3.py index 62366131a4..ed9cd7f4ee 100644 --- a/optuna/artifacts/_boto3.py +++ b/optuna/artifacts/_boto3.py @@ -101,6 +101,6 @@ def _is_not_found_error(e: ClientError) -> bool: if TYPE_CHECKING: # A mypy-runtime assertion to ensure that Boto3ArtifactStore implements all abstract methods # in ArtifactStore. - from ._protocol import ArtifactStore + from optuna.artifacts._protocol import ArtifactStore _: ArtifactStore = Boto3ArtifactStore("") diff --git a/optuna/artifacts/_filesystem.py b/optuna/artifacts/_filesystem.py index dcdfcbb740..32318996bd 100644 --- a/optuna/artifacts/_filesystem.py +++ b/optuna/artifacts/_filesystem.py @@ -75,6 +75,6 @@ def remove(self, artifact_id: str) -> None: if TYPE_CHECKING: # A mypy-runtime assertion to ensure that LocalArtifactBackend # implements all abstract methods in ArtifactBackendProtocol. - from ._protocol import ArtifactStore + from optuna.artifacts._protocol import ArtifactStore _: ArtifactStore = FileSystemArtifactStore("") diff --git a/optuna/artifacts/_gcs.py b/optuna/artifacts/_gcs.py index ec3826d623..65aa97a951 100644 --- a/optuna/artifacts/_gcs.py +++ b/optuna/artifacts/_gcs.py @@ -89,6 +89,6 @@ def remove(self, artifact_id: str) -> None: if TYPE_CHECKING: # A mypy-runtime assertion to ensure that GCS3ArtifactStore implements all abstract methods # in ArtifactStore. - from ._protocol import ArtifactStore + from optuna.artifacts._protocol import ArtifactStore _: ArtifactStore = GCSArtifactStore("") diff --git a/optuna/samplers/_gp/__init__.py b/optuna/samplers/_gp/__init__.py index 9f55ab1f62..ff09f1235a 100644 --- a/optuna/samplers/_gp/__init__.py +++ b/optuna/samplers/_gp/__init__.py @@ -1,4 +1,4 @@ -from .sampler import GPSampler +from optuna.samplers._gp.sampler import GPSampler __all__ = ["GPSampler"] diff --git a/tests/artifacts_tests/test_backoff.py b/tests/artifacts_tests/test_backoff.py index 0229d31d3c..456b8fd578 100644 --- a/tests/artifacts_tests/test_backoff.py +++ b/tests/artifacts_tests/test_backoff.py @@ -3,8 +3,9 @@ from optuna.artifacts import Backoff -from .stubs import FailArtifactStore -from .stubs import InMemoryArtifactStore +from tests.artifacts_tests.stubs import FailArtifactStore +from tests.artifacts_tests.stubs import InMemoryArtifactStore + def test_backoff_time() -> None: diff --git a/tests/storages_tests/rdb_tests/test_storage.py b/tests/storages_tests/rdb_tests/test_storage.py index 95183e68fb..7bf4341a3b 100644 --- a/tests/storages_tests/rdb_tests/test_storage.py +++ b/tests/storages_tests/rdb_tests/test_storage.py @@ -32,9 +32,9 @@ from optuna.trial import FrozenTrial from optuna.trial import TrialState -from .create_db import mo_objective_test_upgrade -from .create_db import objective_test_upgrade -from .create_db import objective_test_upgrade_distributions +from tests.storages_tests.rdb_tests.create_db import mo_objective_test_upgrade +from tests.storages_tests.rdb_tests.create_db import objective_test_upgrade +from tests.storages_tests.rdb_tests.create_db import objective_test_upgrade_distributions def test_init() -> None: From ce67adcea327c2c26404ccf25db45ab1cdaaca01 Mon Sep 17 00:00:00 2001 From: RektPunk Date: Thu, 11 Jul 2024 17:26:31 +0900 Subject: [PATCH 2/6] black test_backoff --- tests/artifacts_tests/test_backoff.py | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/tests/artifacts_tests/test_backoff.py b/tests/artifacts_tests/test_backoff.py index 456b8fd578..5ed1a2f6bf 100644 --- a/tests/artifacts_tests/test_backoff.py +++ b/tests/artifacts_tests/test_backoff.py @@ -7,14 +7,8 @@ from tests.artifacts_tests.stubs import InMemoryArtifactStore - def test_backoff_time() -> None: - backend = Backoff( - backend=FailArtifactStore(), - min_delay=0.1, - multiplier=10, - max_delay=10, - ) + backend = Backoff(backend=FailArtifactStore(), min_delay=0.1, multiplier=10, max_delay=10,) assert backend._get_sleep_secs(0) == 0.1 assert backend._get_sleep_secs(1) == 1 assert backend._get_sleep_secs(2) == 10 @@ -24,12 +18,7 @@ def test_read_and_write() -> None: artifact_id = f"test-{uuid.uuid4()}" dummy_content = b"Hello World" - backend = Backoff( - backend=InMemoryArtifactStore(), - min_delay=0.1, - multiplier=10, - max_delay=10, - ) + backend = Backoff(backend=InMemoryArtifactStore(), min_delay=0.1, multiplier=10, max_delay=10,) backend.write(artifact_id, io.BytesIO(dummy_content)) with backend.open_reader(artifact_id) as f: actual = f.read() From 344d4131ec618aa1d5026228fd4e3a85141dde48 Mon Sep 17 00:00:00 2001 From: RektPunk Date: Thu, 11 Jul 2024 17:32:53 +0900 Subject: [PATCH 3/6] black test_backoff --- tests/artifacts_tests/test_backoff.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/artifacts_tests/test_backoff.py b/tests/artifacts_tests/test_backoff.py index 5ed1a2f6bf..8ff94141d8 100644 --- a/tests/artifacts_tests/test_backoff.py +++ b/tests/artifacts_tests/test_backoff.py @@ -8,7 +8,12 @@ def test_backoff_time() -> None: - backend = Backoff(backend=FailArtifactStore(), min_delay=0.1, multiplier=10, max_delay=10,) + backend = Backoff( + backend=FailArtifactStore(), + min_delay=0.1, + multiplier=10, + max_delay=10, + ) assert backend._get_sleep_secs(0) == 0.1 assert backend._get_sleep_secs(1) == 1 assert backend._get_sleep_secs(2) == 10 @@ -18,7 +23,12 @@ def test_read_and_write() -> None: artifact_id = f"test-{uuid.uuid4()}" dummy_content = b"Hello World" - backend = Backoff(backend=InMemoryArtifactStore(), min_delay=0.1, multiplier=10, max_delay=10,) + backend = Backoff( + backend=InMemoryArtifactStore(), + min_delay=0.1, + multiplier=10, + max_delay=10, + ) backend.write(artifact_id, io.BytesIO(dummy_content)) with backend.open_reader(artifact_id) as f: actual = f.read() From 12d9006d3ae633b783e57ee3d2811550717bc3a9 Mon Sep 17 00:00:00 2001 From: RektPunk Date: Thu, 11 Jul 2024 17:39:32 +0900 Subject: [PATCH 4/6] isort test_backoff and test_storages --- tests/artifacts_tests/test_backoff.py | 1 - tests/storages_tests/rdb_tests/test_storage.py | 1 - 2 files changed, 2 deletions(-) diff --git a/tests/artifacts_tests/test_backoff.py b/tests/artifacts_tests/test_backoff.py index 8ff94141d8..226befcd11 100644 --- a/tests/artifacts_tests/test_backoff.py +++ b/tests/artifacts_tests/test_backoff.py @@ -2,7 +2,6 @@ import uuid from optuna.artifacts import Backoff - from tests.artifacts_tests.stubs import FailArtifactStore from tests.artifacts_tests.stubs import InMemoryArtifactStore diff --git a/tests/storages_tests/rdb_tests/test_storage.py b/tests/storages_tests/rdb_tests/test_storage.py index 7bf4341a3b..06c43ff254 100644 --- a/tests/storages_tests/rdb_tests/test_storage.py +++ b/tests/storages_tests/rdb_tests/test_storage.py @@ -31,7 +31,6 @@ from optuna.testing.tempfile_pool import NamedTemporaryFilePool from optuna.trial import FrozenTrial from optuna.trial import TrialState - from tests.storages_tests.rdb_tests.create_db import mo_objective_test_upgrade from tests.storages_tests.rdb_tests.create_db import objective_test_upgrade from tests.storages_tests.rdb_tests.create_db import objective_test_upgrade_distributions From 12a023afcb5a792c149d2189d1537b3c4a1d89cf Mon Sep 17 00:00:00 2001 From: RektPunk Date: Thu, 11 Jul 2024 18:02:05 +0900 Subject: [PATCH 5/6] revert test import --- tests/artifacts_tests/test_backoff.py | 5 +++-- tests/storages_tests/rdb_tests/test_storage.py | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/artifacts_tests/test_backoff.py b/tests/artifacts_tests/test_backoff.py index 226befcd11..0229d31d3c 100644 --- a/tests/artifacts_tests/test_backoff.py +++ b/tests/artifacts_tests/test_backoff.py @@ -2,8 +2,9 @@ import uuid from optuna.artifacts import Backoff -from tests.artifacts_tests.stubs import FailArtifactStore -from tests.artifacts_tests.stubs import InMemoryArtifactStore + +from .stubs import FailArtifactStore +from .stubs import InMemoryArtifactStore def test_backoff_time() -> None: diff --git a/tests/storages_tests/rdb_tests/test_storage.py b/tests/storages_tests/rdb_tests/test_storage.py index 06c43ff254..95183e68fb 100644 --- a/tests/storages_tests/rdb_tests/test_storage.py +++ b/tests/storages_tests/rdb_tests/test_storage.py @@ -31,9 +31,10 @@ from optuna.testing.tempfile_pool import NamedTemporaryFilePool from optuna.trial import FrozenTrial from optuna.trial import TrialState -from tests.storages_tests.rdb_tests.create_db import mo_objective_test_upgrade -from tests.storages_tests.rdb_tests.create_db import objective_test_upgrade -from tests.storages_tests.rdb_tests.create_db import objective_test_upgrade_distributions + +from .create_db import mo_objective_test_upgrade +from .create_db import objective_test_upgrade +from .create_db import objective_test_upgrade_distributions def test_init() -> None: From ec36e9e07d6b10fc3b49c0f18bc98088b7e3a44a Mon Sep 17 00:00:00 2001 From: RektPunk Date: Fri, 12 Jul 2024 16:12:54 +0900 Subject: [PATCH 6/6] fix import private module --- optuna/artifacts/_backoff.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/optuna/artifacts/_backoff.py b/optuna/artifacts/_backoff.py index 5633f74e0b..823a9c62b2 100644 --- a/optuna/artifacts/_backoff.py +++ b/optuna/artifacts/_backoff.py @@ -112,6 +112,6 @@ def remove(self, artifact_id: str) -> None: if TYPE_CHECKING: # A mypy-runtime assertion to ensure that the Backoff middleware implements # all abstract methods in ArtifactStore. - from optuna.artifacts._filesystem import FileSystemArtifactStore + from optuna.artifacts import FileSystemArtifactStore _: ArtifactStore = Backoff(FileSystemArtifactStore("."))