Skip to content

Commit d7a3788

Browse files
committed
module level import for _backend
1 parent d156ad4 commit d7a3788

4 files changed

Lines changed: 54 additions & 1 deletion

File tree

openml/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
utils,
3434
)
3535
from .__version__ import __version__
36-
from ._api.setup._instance import _backend
36+
from ._api import _backend
3737
from .datasets import OpenMLDataFeature, OpenMLDataset
3838
from .evaluations import OpenMLEvaluation
3939
from .flows import OpenMLFlow

openml/_api/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
CacheConfig,
3434
Config,
3535
ConnectionConfig,
36+
_backend,
3637
)
3738

3839
__all__ = [
@@ -66,4 +67,5 @@
6667
"StudyV2API",
6768
"TaskV1API",
6869
"TaskV2API",
70+
"_backend",
6971
]

openml/_api/setup/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from ._instance import _backend
12
from .backend import APIBackend
23
from .builder import APIBackendBuilder
34
from .config import APIConfig, CacheConfig, Config, ConnectionConfig
@@ -9,4 +10,5 @@
910
"CacheConfig",
1011
"Config",
1112
"ConnectionConfig",
13+
"_backend",
1214
]

openml/_api/setup/_utils.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from __future__ import annotations
2+
3+
import logging
4+
import os
5+
import platform
6+
from pathlib import Path
7+
8+
openml_logger = logging.getLogger("openml")
9+
10+
# Default values (see also https://github.com/openml/OpenML/wiki/Client-API-Standards)
11+
_user_path = Path("~").expanduser().absolute()
12+
13+
14+
def _resolve_default_cache_dir() -> Path:
15+
user_defined_cache_dir = os.environ.get("OPENML_CACHE_DIR")
16+
if user_defined_cache_dir is not None:
17+
return Path(user_defined_cache_dir)
18+
19+
if platform.system().lower() != "linux":
20+
return _user_path / ".openml"
21+
22+
xdg_cache_home = os.environ.get("XDG_CACHE_HOME")
23+
if xdg_cache_home is None:
24+
return Path("~", ".cache", "openml")
25+
26+
# This is the proper XDG_CACHE_HOME directory, but
27+
# we unfortunately had a problem where we used XDG_CACHE_HOME/org,
28+
# we check heuristically if this old directory still exists and issue
29+
# a warning if it does. There's too much data to move to do this for the user.
30+
31+
# The new cache directory exists
32+
cache_dir = Path(xdg_cache_home) / "openml"
33+
if cache_dir.exists():
34+
return cache_dir
35+
36+
# The old cache directory *does not* exist
37+
heuristic_dir_for_backwards_compat = Path(xdg_cache_home) / "org" / "openml"
38+
if not heuristic_dir_for_backwards_compat.exists():
39+
return cache_dir
40+
41+
root_dir_to_delete = Path(xdg_cache_home) / "org"
42+
openml_logger.warning(
43+
"An old cache directory was found at '%s'. This directory is no longer used by "
44+
"OpenML-Python. To silence this warning you would need to delete the old cache "
45+
"directory. The cached files will then be located in '%s'.",
46+
root_dir_to_delete,
47+
cache_dir,
48+
)
49+
return Path(xdg_cache_home)

0 commit comments

Comments
 (0)