Skip to content

Commit 36184e5

Browse files
committed
remove chaching part
Signed-off-by: Omswastik-11 <omswastikpanda11@gmail.com>
1 parent 36c22aa commit 36184e5

4 files changed

Lines changed: 20 additions & 67 deletions

File tree

openml/_api/resources/base.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,13 @@ class FlowsAPI(ResourceAPI, ABC):
3838
def get(
3939
self,
4040
flow_id: int,
41-
*,
42-
return_response: bool = False,
43-
) -> OpenMLFlow | tuple[OpenMLFlow, Response]: ...
41+
) -> OpenMLFlow: ...
4442

4543
@abstractmethod
4644
def exists(self, name: str, external_version: str) -> int | bool: ...
4745

4846
@abstractmethod
49-
def list_page(
47+
def list(
5048
self,
5149
*,
5250
limit: int | None = None,

openml/_api/resources/flows.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import TYPE_CHECKING, Any
3+
from typing import Any
44

55
import pandas as pd
66
import requests
@@ -9,17 +9,12 @@
99
from openml._api.resources.base import FlowsAPI
1010
from openml.flows.flow import OpenMLFlow
1111

12-
if TYPE_CHECKING:
13-
from requests import Response
14-
1512

1613
class FlowsV1(FlowsAPI):
1714
def get(
1815
self,
1916
flow_id: int,
20-
*,
21-
return_response: bool = False,
22-
) -> OpenMLFlow | tuple[OpenMLFlow, Response]:
17+
) -> OpenMLFlow:
2318
"""Get a flow from the OpenML server.
2419
2520
Parameters
@@ -36,10 +31,7 @@ def get(
3631
"""
3732
response = self._http.get(f"flow/{flow_id}")
3833
flow_xml = response.text
39-
flow = OpenMLFlow._from_dict(xmltodict.parse(flow_xml))
40-
if return_response:
41-
return flow, response
42-
return flow
34+
return OpenMLFlow._from_dict(xmltodict.parse(flow_xml))
4335

4436
def exists(self, name: str, external_version: str) -> int | bool:
4537
"""Check if a flow exists on the OpenML server.
@@ -68,7 +60,7 @@ def exists(self, name: str, external_version: str) -> int | bool:
6860
flow_id = int(result_dict["oml:flow_exists"]["oml:id"])
6961
return flow_id if flow_id > 0 else False
7062

71-
def list_page(
63+
def list(
7264
self,
7365
*,
7466
limit: int | None = None,
@@ -181,9 +173,7 @@ class FlowsV2(FlowsAPI):
181173
def get(
182174
self,
183175
flow_id: int,
184-
*,
185-
return_response: bool = False,
186-
) -> OpenMLFlow | tuple[OpenMLFlow, Response]:
176+
) -> OpenMLFlow:
187177
"""Get a flow from the OpenML v2 server.
188178
189179
Parameters
@@ -203,11 +193,7 @@ def get(
203193

204194
# Convert v2 JSON to v1-compatible dict for OpenMLFlow._from_dict()
205195
flow_dict = self._convert_v2_to_v1_format(flow_json)
206-
flow = OpenMLFlow._from_dict(flow_dict)
207-
208-
if return_response:
209-
return flow, response
210-
return flow
196+
return OpenMLFlow._from_dict(flow_dict)
211197

212198
def exists(self, name: str, external_version: str) -> int | bool:
213199
"""Check if a flow exists on the OpenML v2 server.
@@ -238,15 +224,15 @@ def exists(self, name: str, external_version: str) -> int | bool:
238224
# v2 returns 404 when flow doesn't exist
239225
return False
240226

241-
def list_page(
227+
def list(
242228
self,
243229
*,
244230
limit: int | None = None,
245231
offset: int | None = None,
246232
tag: str | None = None,
247233
uploader: str | None = None,
248234
) -> pd.DataFrame:
249-
raise NotImplementedError("GET /flows (list) not yet implemented in v2 server")
235+
raise NotImplementedError("flows (list) not yet implemented in v2 server")
250236

251237
def create(self, flow: OpenMLFlow) -> OpenMLFlow:
252238
raise NotImplementedError("POST /flows (create) not yet implemented in v2 server")

openml/flows/functions.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,7 @@ def _get_flow_description(flow_id: int) -> OpenMLFlow:
121121
except OpenMLCacheException:
122122
from openml._api import api_context
123123

124-
xml_file = (
125-
openml.utils._create_cache_directory_for_id(FLOWS_CACHE_DIR_NAME, flow_id) / "flow.xml"
126-
)
127-
result = api_context.backend.flows.get(flow_id, return_response=True)
128-
129-
if isinstance(result, tuple):
130-
flow, response = result
131-
with xml_file.open("w", encoding="utf8") as fh:
132-
fh.write(response.text)
133-
else:
134-
flow = result
135-
136-
return flow
124+
return api_context.backend.flows.get(flow_id)
137125

138126

139127
def list_flows(
@@ -169,7 +157,9 @@ def list_flows(
169157
- external version
170158
- uploader
171159
"""
172-
listing_call = partial(_list_flows, tag=tag, uploader=uploader)
160+
from openml._api import api_context
161+
162+
listing_call = partial(api_context.backend.flows.list, tag=tag, uploader=uploader)
173163
batches = openml.utils._list_all(listing_call, offset=offset, limit=size)
174164
if len(batches) == 0:
175165
return pd.DataFrame()
@@ -196,7 +186,7 @@ def _list_flows(limit: int, offset: int, **kwargs: Any) -> pd.DataFrame:
196186
"""
197187
from openml._api import api_context
198188

199-
return api_context.backend.flows.list_page(
189+
return api_context.backend.flows.list(
200190
limit=limit,
201191
offset=offset,
202192
tag=kwargs.get("tag"),
@@ -323,9 +313,7 @@ def __list_flows(api_call: str) -> pd.DataFrame:
323313
# Silently continue if parsing fails; all params default to None
324314
pass
325315

326-
return api_context.backend.flows.list_page(
327-
limit=limit, offset=offset, tag=tag, uploader=uploader
328-
)
316+
return api_context.backend.flows.list(limit=limit, offset=offset, tag=tag, uploader=uploader)
329317

330318

331319
def _check_flow_for_server_id(flow: OpenMLFlow) -> None:

tests/test_flows/test_flow_migration.py

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,19 @@ def test_list_flows_delegates_to_backend(monkeypatch):
6161
"uploader": ["u", "u"],
6262
}).set_index("id")
6363

64-
def fake_list_page(limit: int | None, offset: int | None, tag: str | None, uploader: str | None):
64+
def fake_list(limit: int | None, offset: int | None, tag: str | None, uploader: str | None):
6565
calls.append((limit or 0, offset or 0, tag, uploader))
6666
return df
6767

68-
monkeypatch.setattr(api_context.backend.flows, "list_page", fake_list_page)
69-
68+
monkeypatch.setattr(api_context.backend.flows, "list", fake_list)
7069
result = openml.flows.list_flows(offset=0, size=5, tag="t", uploader="u")
7170

7271
assert result.equals(df)
7372
# _list_all passes batch_size as limit; expect one call
7473
assert calls == [(5, 0, "t", "u")]
7574

7675

77-
def test_get_flow_description_fetches_and_caches(monkeypatch, tmp_path, dummy_flow):
76+
def test_get_flow_description_fetches_on_cache_miss(monkeypatch, tmp_path, dummy_flow):
7877
from openml._api import api_context
7978

8079
# Force cache miss
@@ -83,32 +82,14 @@ def raise_cache(_fid: int) -> None:
8382

8483
monkeypatch.setattr(flow_functions, "_get_cached_flow", raise_cache)
8584

86-
def fake_cache_dir(_key: str, id_: int):
87-
path = tmp_path / str(id_)
88-
path.mkdir(parents=True, exist_ok=True)
89-
return path
90-
91-
monkeypatch.setattr(openml.utils, "_create_cache_directory_for_id", fake_cache_dir)
92-
93-
xml_text = "<oml:flow>test</oml:flow>"
94-
response = requests.Response()
95-
response.status_code = 200
96-
response._content = xml_text.encode()
97-
98-
def fake_get(flow_id: int, *, return_response: bool = False):
99-
if return_response:
100-
return dummy_flow, response
85+
def fake_get(flow_id: int):
10186
return dummy_flow
10287

10388
monkeypatch.setattr(api_context.backend.flows, "get", fake_get)
10489

10590
flow = flow_functions._get_flow_description(123)
10691

10792
assert flow is dummy_flow
108-
cached = (tmp_path / "123" / "flow.xml").read_text()
109-
assert cached == xml_text
110-
cached = (tmp_path / "123" / "flow.xml").read_text()
111-
assert cached == xml_text
11293

11394

11495
def test_delete_flow_delegates_to_backend(monkeypatch):

0 commit comments

Comments
 (0)