Skip to content

Commit 4f6e7ec

Browse files
committed
merge
2 parents 070731d + ac28f82 commit 4f6e7ec

12 files changed

Lines changed: 192 additions & 172 deletions

File tree

openml/_config.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
openml_logger = logging.getLogger("openml")
2828

2929

30-
SERVERS_REGISTRY: dict[str, dict[APIVersion, dict[str, str | None]]] = {
30+
_SERVERS_REGISTRY: dict[str, dict[APIVersion, dict[str, str | None]]] = {
3131
"production": {
3232
APIVersion.V1: {
3333
"server": "https://www.openml.org/api/v1/xml/",
@@ -50,12 +50,12 @@
5050
},
5151
"local": {
5252
APIVersion.V1: {
53-
"server": "http://localhost:8000/api/v1/xml/",
53+
"server": "http://localhost:8080/api/v1/xml/",
5454
"apikey": "normaluser",
5555
},
5656
APIVersion.V2: {
57-
"server": "http://localhost:8002/api/v1/xml/",
58-
"apikey": "normaluser",
57+
"server": "http://localhost:8082/",
58+
"apikey": "AD000000000000000000000000000000",
5959
},
6060
},
6161
}
@@ -97,7 +97,7 @@ class OpenMLConfig:
9797
"""Dataclass storing the OpenML configuration."""
9898

9999
servers: dict[APIVersion, dict[str, str | None]] = field(
100-
default_factory=lambda: deepcopy(SERVERS_REGISTRY["production"])
100+
default_factory=lambda: deepcopy(_SERVERS_REGISTRY["production"])
101101
)
102102
api_version: APIVersion = APIVersion.V1
103103
fallback_api_version: APIVersion | None = None
@@ -137,15 +137,10 @@ def __init__(self) -> None:
137137
self.console_handler: logging.StreamHandler | None = None
138138
self.file_handler: logging.handlers.RotatingFileHandler | None = None
139139

140-
server_test_v1_apikey = self.get_servers("test")[APIVersion.V1]["apikey"]
141-
server_test_v1_server = self.get_servers("test")[APIVersion.V1]["server"]
142-
143140
self.OPENML_CACHE_DIR_ENV_VAR = "OPENML_CACHE_DIR"
144141
self.OPENML_SKIP_PARQUET_ENV_VAR = "OPENML_SKIP_PARQUET"
145-
self._TEST_SERVER_NORMAL_USER_KEY = server_test_v1_apikey
146-
self._HEADERS: dict[str, str] = {"user-agent": f"openml-python/{__version__}"}
147142
self.OPENML_TEST_SERVER_ADMIN_KEY_ENV_VAR = "OPENML_TEST_SERVER_ADMIN_KEY"
148-
self.TEST_SERVER_URL = cast("str", server_test_v1_server).split("/api/v1/xml")[0]
143+
self._HEADERS: dict[str, str] = {"user-agent": f"openml-python/{__version__}"}
149144

150145
self._config: OpenMLConfig = OpenMLConfig()
151146
# for legacy test `test_non_writable_home`
@@ -178,7 +173,6 @@ def __setattr__(self, name: str, value: Any) -> None:
178173
"_examples",
179174
"OPENML_CACHE_DIR_ENV_VAR",
180175
"OPENML_SKIP_PARQUET_ENV_VAR",
181-
"_TEST_SERVER_NORMAL_USER_KEY",
182176
"_HEADERS",
183177
}:
184178
return object.__setattr__(self, name, value)
@@ -258,11 +252,11 @@ def get_server_base_url(self) -> str:
258252
return domain.replace("api", "www")
259253

260254
def get_servers(self, mode: str) -> dict[APIVersion, dict[str, str | None]]:
261-
if mode not in SERVERS_REGISTRY:
255+
if mode not in _SERVERS_REGISTRY:
262256
raise ValueError(
263-
f'invalid mode="{mode}" allowed modes: {", ".join(list(SERVERS_REGISTRY.keys()))}'
257+
f'invalid mode="{mode}" allowed modes: {", ".join(list(_SERVERS_REGISTRY.keys()))}'
264258
)
265-
return deepcopy(SERVERS_REGISTRY[mode])
259+
return deepcopy(_SERVERS_REGISTRY[mode])
266260

267261
def set_servers(self, mode: str) -> None:
268262
servers = self.get_servers(mode)
@@ -525,8 +519,9 @@ def start_using_configuration_for_example(self) -> None:
525519
self._manager._config,
526520
servers=self._test_servers,
527521
)
522+
test_server = self._test_servers[self._manager._config.api_version]["server"]
528523
warnings.warn(
529-
f"Switching to the test servers {self._test_servers} to not upload results to "
524+
f"Switching to the test server {test_server} to not upload results to "
530525
"the live server. Using the test server may result in reduced performance of the "
531526
"API!",
532527
stacklevel=2,

openml/cli.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
from collections.abc import Callable
99
from dataclasses import fields
1010
from pathlib import Path
11+
from typing import cast
1112
from urllib.parse import urlparse
1213

1314
import openml
1415
from openml.__version__ import __version__
16+
from openml.enums import APIVersion
1517

1618

1719
def is_hex(string_: str) -> bool:
@@ -110,9 +112,9 @@ def check_server(server: str) -> str:
110112

111113
def replace_shorthand(server: str) -> str:
112114
if server == "test":
113-
return f"{openml.config.TEST_SERVER_URL}/api/v1/xml"
115+
return cast("str", openml.config.get_servers("test")[APIVersion.V1]["server"])
114116
if server == "production_server":
115-
return "https://www.openml.org/api/v1/xml"
117+
return cast("str", openml.config.get_servers("production")[APIVersion.V1]["server"])
116118
return server
117119

118120
configure_field(

openml/testing.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ class TestBase(unittest.TestCase):
4949
"user": [],
5050
}
5151
flow_name_tracker: ClassVar[list[str]] = []
52-
test_server = f"{openml.config.TEST_SERVER_URL}/api/v1/xml/"
5352
admin_key = os.environ.get(openml.config.OPENML_TEST_SERVER_ADMIN_KEY_ENV_VAR)
54-
user_key = openml.config._TEST_SERVER_NORMAL_USER_KEY
5553

5654
# creating logger for tracking files uploaded to test server
5755
logger = logging.getLogger("unit_tests_published_entities")
@@ -106,8 +104,6 @@ def setUp(self, n_levels: int = 1, tmpdir_suffix: str = "") -> None:
106104
os.chdir(self.workdir)
107105

108106
self.cached = True
109-
openml.config.apikey = TestBase.user_key
110-
self.production_server = "https://www.openml.org/api/v1/xml"
111107
openml.config.set_root_cache_directory(str(self.workdir))
112108

113109
# Increase the number of retries to avoid spurious server failures
@@ -128,8 +124,7 @@ def use_production_server(self) -> None:
128124
129125
Please use this sparingly - it is better to use the test server.
130126
"""
131-
openml.config.server = self.production_server
132-
openml.config.apikey = ""
127+
openml.config.set_servers("production")
133128

134129
def tearDown(self) -> None:
135130
"""Tear down the test"""

tests/conftest.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ def delete_remote_files(tracker, flow_names) -> None:
9999
:param tracker: Dict
100100
:return: None
101101
"""
102-
openml.config.server = TestBase.test_server
103-
openml.config.apikey = TestBase.user_key
102+
openml.config.set_servers("test")
104103

105104
# reordering to delete sub flows at the end of flows
106105
# sub-flows have shorter names, hence, sorting by descending order of flow name length
@@ -252,8 +251,23 @@ def test_files_directory() -> Path:
252251

253252

254253
@pytest.fixture(scope="session")
255-
def test_api_key() -> str:
256-
return TestBase.user_key
254+
def test_server_v1() -> str:
255+
return openml.config.get_servers("test")[APIVersion.V1]["server"]
256+
257+
258+
@pytest.fixture(scope="session")
259+
def test_apikey_v1() -> str:
260+
return openml.config.get_servers("test")[APIVersion.V1]["apikey"]
261+
262+
263+
@pytest.fixture(scope="session")
264+
def test_server_v2() -> str:
265+
return openml.config.get_servers("test")[APIVersion.V2]["server"]
266+
267+
268+
@pytest.fixture(scope="session")
269+
def test_apikey_v2() -> str:
270+
return openml.config.get_servers("test")[APIVersion.V2]["apikey"]
257271

258272

259273
@pytest.fixture(autouse=True, scope="function")
@@ -274,13 +288,12 @@ def as_robot() -> Iterator[None]:
274288

275289
@pytest.fixture(autouse=True)
276290
def with_server(request):
291+
openml.config.set_api_version(APIVersion.V1)
277292
if "production_server" in request.keywords:
278-
openml.config.server = "https://www.openml.org/api/v1/xml/"
279-
openml.config.apikey = None
293+
openml.config.set_servers("production")
280294
yield
281295
return
282-
openml.config.server = f"{openml.config.TEST_SERVER_URL}/api/v1/xml/"
283-
openml.config.apikey = TestBase.user_key
296+
openml.config.set_servers("test")
284297
yield
285298

286299

@@ -311,16 +324,6 @@ def workdir(tmp_path):
311324
os.chdir(original_cwd)
312325

313326

314-
@pytest.fixture
315-
def use_api_v1() -> None:
316-
openml.config.set_api_version(api_version=APIVersion.V1)
317-
318-
319-
@pytest.fixture
320-
def use_api_v2() -> None:
321-
openml.config.set_api_version(api_version=APIVersion.V2)
322-
323-
324327
@pytest.fixture
325328
def http_client_v1() -> HTTPClient:
326329
return HTTPClient(api_version=APIVersion.V1)

0 commit comments

Comments
 (0)