squirrel.environment

Manage separate databases and caches for different user projects.

Squirrel based applications can either use the user’s global database which lives in Pyrocko’s global cache directory (by default under '$HOME/.pyrocko/cache/squirrel') or a project specific local database which can be conveniently created in the top level directory of a user’s project under '.squirrel' or 'squirrel'. The choice of database and associated cache directory locations is referred to here as the Squirrel environment. This module provides functions to create local environments and to look for a usable environment in the hierarchy of a user’s project directory.

get_environment(path=None)[source]

Get default Squirrel environment relevant for a given file system path.

Parameters:path – Directory path to use as starting point for detection of the Squirrel environment. By default, the current working directory is used as starting point. When searching for a usable environment the directory '.squirrel' or 'squirrel' in the current (or starting point) directory is used if it exists, otherwise the parent directories are search upwards for the existence of such a directory. If no such directory is found, the user’s global Squirrel environment, usually '$HOME/.pyrocko/cache/squirrel', is used.
Returns:Environment object containing the detected database and cache directory paths.
init_environment(path=None)[source]

Initialize empty Squirrel environment.

Parameters:path – Path to the directory where the new environment’s '.squirrel' directory should be created. If set to None, the current working directory is used.

If a '.squirrel' directory already exists at the given location, SquirrelError is raised.

class Environment(*args, **kwargs)[source]

Bases: pyrocko.has_paths.HasPaths

Configuration object providing paths to database and cache.

database_path

str (pyrocko.has_paths.Path), optional

cache_path

str (pyrocko.has_paths.Path), optional

persistent

str, optional