hed_cache

Infrastructure for caching HED schema from remote repositories.

Functions

cache_local_versions(cache_folder)

Cache all schemas included with the hed installation.

cache_xml_versions([hed_base_urls, ...])

Cache all schemas at the given URLs.

get_cache_directory()

Return the current value of HED_CACHE_DIRECTORY.

get_hed_version_path(xml_version[, ...])

Get HED XML file path in a directory.

get_hed_versions([local_hed_directory, ...])

Get the HED versions in the hed directory.

set_cache_directory(new_cache_dir)

Set default global hed cache directory.

cache_local_versions(cache_folder)[source]

Cache all schemas included with the hed installation.

Parameters:

cache_folder (str) – The folder holding the cache.

Returns:

Returns -1 on cache access failure. None otherwise

Return type:

int or None

cache_xml_versions(hed_base_urls=('https://api.github.com/repos/hed-standard/hed-schemas/contents/standard_schema',), hed_library_urls=('https://api.github.com/repos/hed-standard/hed-schemas/contents/library_schemas',), skip_folders=('deprecated',), cache_folder=None)[source]

Cache all schemas at the given URLs.

Parameters:
  • hed_base_urls (str or list) – Path or list of paths. These should point to a single folder.

  • hed_library_urls (str or list) – Path or list of paths. These should point to a folder containing library folders.

  • skip_folders (list) – A list of subfolders to skip over when downloading.

  • cache_folder (str) – The folder holding the cache.

Returns:

Returns -1 if cache failed, a positive number meaning time in seconds since last update

if it didn’t cache, 0 if it cached successfully this time.

Return type:

float

Notes

get_cache_directory()[source]

Return the current value of HED_CACHE_DIRECTORY.

get_hed_version_path(xml_version, library_name=None, local_hed_directory=None, check_prerelease=False)[source]

Get HED XML file path in a directory. Only returns filenames that exist.

Parameters:
  • library_name (str or None) – Optional the schema library name.

  • xml_version (str) – Returns this version if it exists

  • local_hed_directory (str) – Path to local hed directory. Defaults to HED_CACHE_DIRECTORY

  • check_prerelease (bool) – Also check for prerelease schemas

Returns:

The path to the latest HED version the hed directory.

Return type:

str

get_hed_versions(local_hed_directory=None, library_name=None, check_prerelease=False)[source]

Get the HED versions in the hed directory.

Parameters:
  • local_hed_directory (str) – Directory to check for versions which defaults to hed_cache.

  • library_name (str or None) – An optional schema library name. None retrieves the standard schema only. Pass “all” to retrieve all standard and library schemas as a dict.

  • check_prerelease (bool) – If True, results can include prerelease schemas

Returns:

List of version numbers or dictionary {library_name: [versions]}.

Return type:

list or dict

set_cache_directory(new_cache_dir)[source]

Set default global hed cache directory.

Parameters:

new_cache_dir (str) – Directory to check for versions.