@@ -37,7 +37,7 @@ def _create_log_handlers(create_file_handler=True):
3737
3838 if create_file_handler :
3939 one_mb = 2 ** 20
40- log_path = os .path .join (cache_directory , "openml_python.log" )
40+ log_path = os .path .join (_root_cache_directory , "openml_python.log" )
4141 file_handler = logging .handlers .RotatingFileHandler (
4242 log_path , maxBytes = one_mb , backupCount = 1 , delay = True
4343 )
@@ -125,7 +125,7 @@ def get_server_base_url() -> str:
125125
126126apikey = _defaults ["apikey" ]
127127# The current cache directory (without the server name)
128- cache_directory = str (_defaults ["cachedir" ]) # so mypy knows it is a string
128+ _root_cache_directory = str (_defaults ["cachedir" ]) # so mypy knows it is a string
129129avoid_duplicate_runs = True if _defaults ["avoid_duplicate_runs" ] == "True" else False
130130
131131retry_policy = _defaults ["retry_policy" ]
@@ -226,7 +226,7 @@ def _setup(config=None):
226226 """
227227 global apikey
228228 global server
229- global cache_directory
229+ global _root_cache_directory
230230 global avoid_duplicate_runs
231231
232232 config_file = determine_config_file_path ()
@@ -266,15 +266,15 @@ def _get(config, key):
266266
267267 set_retry_policy (_get (config , "retry_policy" ), n_retries )
268268
269- cache_directory = os .path .expanduser (short_cache_dir )
269+ _root_cache_directory = os .path .expanduser (short_cache_dir )
270270 # create the cache subdirectory
271- if not os .path .exists (cache_directory ):
271+ if not os .path .exists (_root_cache_directory ):
272272 try :
273- os .makedirs (cache_directory , exist_ok = True )
273+ os .makedirs (_root_cache_directory , exist_ok = True )
274274 except PermissionError :
275275 openml_logger .warning (
276276 "No permission to create openml cache directory at %s! This can result in "
277- "OpenML-Python not working properly." % cache_directory
277+ "OpenML-Python not working properly." % _root_cache_directory
278278 )
279279
280280 if cache_exists :
@@ -333,7 +333,7 @@ def get_config_as_dict():
333333 config = dict ()
334334 config ["apikey" ] = apikey
335335 config ["server" ] = server
336- config ["cachedir" ] = cache_directory
336+ config ["cachedir" ] = _root_cache_directory
337337 config ["avoid_duplicate_runs" ] = avoid_duplicate_runs
338338 config ["connection_n_retries" ] = connection_n_retries
339339 config ["retry_policy" ] = retry_policy
@@ -343,6 +343,17 @@ def get_config_as_dict():
343343def get_cache_directory ():
344344 """Get the current cache directory.
345345
346+ This gets the cache directory for the current server relative
347+ to the root cache directory that can be set via
348+ ``set_root_cache_directory()``. The cache directory is the
349+ ``root_cache_directory`` with additional information on which
350+ subdirectory to use based on the server name. By default it is
351+ ``root_cache_directory / org / openml / www`` for the standard
352+ OpenML.org server and is defined as
353+ ``root_cache_directory / top-level domain / second-level domain /
354+ hostname``
355+ ```
356+
346357 Returns
347358 -------
348359 cachedir : string
@@ -351,27 +362,32 @@ def get_cache_directory():
351362 """
352363 url_suffix = urlparse (server ).netloc
353364 reversed_url_suffix = os .sep .join (url_suffix .split ("." )[::- 1 ])
354- _cachedir = os .path .join (cache_directory , reversed_url_suffix )
365+ _cachedir = os .path .join (_root_cache_directory , reversed_url_suffix )
355366 return _cachedir
356367
357368
358- def set_cache_directory ( cachedir ):
359- """Set module-wide cache directory.
369+ def set_root_cache_directory ( root_cache_directory ):
370+ """Set module-wide base cache directory.
360371
361- Sets the cache directory into which to download datasets, tasks etc.
372+ Sets the root cache directory, wherin the cache directories are
373+ created to store content from different OpenML servers. For example,
374+ by default, cached data for the standard OpenML.org server is stored
375+ at ``root_cache_directory / org / openml / www``, and the general
376+ pattern is ``root_cache_directory / top-level domain / second-level
377+ domain / hostname``.
362378
363379 Parameters
364380 ----------
365- cachedir : string
381+ root_cache_directory : string
366382 Path to use as cache directory.
367383
368384 See also
369385 --------
370386 get_cache_directory
371387 """
372388
373- global cache_directory
374- cache_directory = cachedir
389+ global _root_cache_directory
390+ _root_cache_directory = root_cache_directory
375391
376392
377393start_using_configuration_for_example = (
@@ -382,7 +398,7 @@ def set_cache_directory(cachedir):
382398
383399__all__ = [
384400 "get_cache_directory" ,
385- "set_cache_directory " ,
401+ "set_root_cache_directory " ,
386402 "start_using_configuration_for_example" ,
387403 "stop_using_configuration_for_example" ,
388404 "get_config_as_dict" ,
0 commit comments