Bamboost
bamboost/_config

bamboost._config

This module manages configuration options for bamboost. It supports loading configuration from a global file (~/.config/bamboost/config.toml) and a project configuration in the standard (pyproject.toml).

The configuration is structured using dataclasses, allowing hierarchical and type-validated configuration handling.

Key Features:

  • Detects the root directory of the project based on common anchor files.
  • Reads configuration from global and project-specific TOML files.
  • Provides structured access to configuration values via dataclasses.
  • Supports nested dictionary updates for merging configuration sources.
  • Includes an index system for managing paths and database settings.

Attributes

  • __all__=['config']
  • CONFIG_DIR=Path('~/.config/bamboost').expanduser()
  • CONFIG_FILE=CONFIG_DIR.joinpath('config-next.toml')
  • LOCAL_DIR=Path('~/.local/share/bamboost').expanduser()
  • CACHE_DIR=Path('~/.cache/bamboost-next').expanduser()
  • DATABASE_FILE_NAME='bamboost-next.sqlite'
  • DEFAULT_EXCLUDE_DIRS:set[str]={'.git', '.hg', '.svn', '.bzr', '.cvs', '.venv', 'venv', 'env', '.tox', '.nox', 'node_modules', '.yarn', '.pnp', 'build', 'dist', '.eggs', '.idea', '.vscode', '.vs', '__pycache__', '.mypy_cache', '.pytest_cache', '.ruff_cache', '.cache', '.cargo', '.gocache', '.next', '.nuxt', '.terser-cache', '.parcel-cache', '.vercel', '.serverless', '.aws-sam', '.terraform', 'vendor'}
  • config:_Config=_Config()

    The main configuration instance containing paths, options, and index settings.

Functions

_find_root_dir() -> Optional[Path]

Find the root directory.

_get_global_config(filepath) -> dict[str, Any]

Reads the configuration file and fills the configuration options.

Arguments:
  • filepath:pathlib.Path
_get_project_config(project_dir) -> dict[str, Any]

Get the project configuration from bamboost.toml or pyproject.toml.

Arguments:
  • project_dir:pathlib.Path

Classes

_Base

_Base(self) -> None
Attributes:
  • _field_aliases={}
_Base.__getattr__(self, name) -> Any
Arguments:
  • name:str
_Base.__setitem__(self, key, value) -> None

Set the configuration options by key, separated by dots.

Arguments:
  • key:str
  • value:typing.Any
_Base.__getitem__(self, key) -> Any

Access the configuration options by key, separated by dots.

Arguments:
  • key:str
_Base.__repr__(self) -> str
_Base.from_dict(cls, config, **kwargs) -> Self

Create an instance of the dataclass from a dictionary of configuration values.

This method performs the following steps:

  1. Identifies valid field names and aliases.
  2. Logs any unknown configuration keys.
  3. Filters the input dictionary to include only valid keys and aliases.
  4. Validates the types of the configuration values.
  5. Creates an instance of the class with the filtered and validated configuration.
  6. Logs any missing fields that are using default values.
Arguments:
  • cls
  • config:dict

    A dictionary containing configuration key-value pairs.

  • kwargs={}
Returns
typing_extensions.SelfAn instance of the class initialized with the provided configuration.

Note

  • Invalid type values are removed from the configuration.
  • Aliases are resolved to their corresponding field names.
_Base._ipython_key_completions_(self) -> Generator[str, None, None]

_Paths

_Paths(self, localDir=LOCAL_DIR, cacheDir=CACHE_DIR) -> None

Paths used by bamboost.

This dataclass contains the paths used by bamboost.

Arguments:
  • localDir:StrPath=bamboost._config.LOCAL_DIR
  • cacheDir:StrPath=bamboost._config.CACHE_DIR
Attributes:
  • localDir:StrPath=field(default=LOCAL_DIR)

    The directory where the local data is stored.

  • cacheDir:StrPath=field(default=CACHE_DIR)

    The directory where the cache is stored.

_Paths.__setattr__(self, name, value) -> None
Arguments:
  • name:str
  • value:typing.Any

_Options

_Options(self, mpi=importlib.util.find_spec('mpi4py') is not None, sortTableKey='time_stamp', sortTableOrder='desc', log_file_lock_severity='WARNING', log_root_only=False) -> None

Core options for bamboost.

This dataclass contains the core options for bamboost.

Arguments:
  • mpi:bool=importlib.importlib.util.importlib.util.find_spec('mpi4py') is not None
  • sortTableKey:str='time_stamp'
  • sortTableOrder:str='desc'
  • log_file_lock_severity:typing.Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']='WARNING'
  • log_root_only:bool=False
Attributes:
  • mpi:bool=field(default=importlib.util.find_spec('mpi4py') is not None)

    If True, the mpi4py package is available and used.

  • sortTableKey:str=field(default='time_stamp')

    The default key to sort the table by.

  • sortTableOrder:str=field(default='desc')

    The default order to sort the table by.

  • log_file_lock_severity:typing.Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']=field(default='WARNING')

    The severity level for the log file lock.

  • log_root_only:bool=False

    If True, only the root logger is used.

_IndexOptions

_IndexOptions(self, searchPaths=lambda: PathSet([Path('~').expanduser()])(), excludeDirs=lambda: DEFAULT_EXCLUDE_DIRS(), extendDefaultExcludeDirs=None, syncTables=True, convertArrays=True, databaseFileName=DATABASE_FILE_NAME, isolated=False, projectDir=None) -> None

Index options for bamboost.

This dataclass contains the index options for bamboost.

Arguments:
  • searchPaths:typing.Iterable[typing.Union[str, pathlib.Path]]=lambda: PathSet([Path('~').expanduser()])()
  • excludeDirs:typing.Iterable[str]=lambda: DEFAULT_EXCLUDE_DIRS()
  • extendDefaultExcludeDirs:typing.Iterable[str] | None=None
  • syncTables:bool=True
  • convertArrays:bool=True
  • databaseFileName:str=bamboost._config.DATABASE_FILE_NAME
  • isolated:bool=False
  • projectDir:typing.Optional[pathlib.Path]=None
Attributes:
  • _field_aliases={'paths': 'searchPaths'}
  • searchPaths:typing.Iterable[typing.Union[str, pathlib.Path]]=field(default_factory=lambda: PathSet([Path('~').expanduser()]))

    A list of paths to index.

  • excludeDirs:typing.Iterable[str]=field(default_factory=lambda: DEFAULT_EXCLUDE_DIRS)

    The list of directory names to exclude from the search.

  • extendDefaultExcludeDirs:typing.Iterable[str] | None=None

    Use this to extend the default exclude directories.

  • syncTables:bool=field(default=True)

    If True, the sqlite tables are synchronized immediatly after some queries.

  • convertArrays:bool=True

    If True, arrays are converted to np.arrays.

  • databaseFileName:str=field(default=DATABASE_FILE_NAME)

    The name of the database file.

  • databaseFile:pathlib.Path=field(init=False)

    The path to the database file.

  • isolated:bool=False

    If true, this project manages it's own database. The searchPaths are reduced to the project root only.

  • projectDir:typing.Optional[pathlib.Path]=None

    The project directory, if found.

_Config

_Config(self, project_dir=None) -> None

Configuration class for bamboost.

This class manages the configuration options and index settings for bamboost. It loads the configuration from a file and provides access to the options and index attributes.

Arguments:
  • project_dir:typing.Optional[StrPath]=None
Attributes:
  • paths:_Paths=_Paths.from_dict(config.pop('paths', {}))

    Paths used by bamboost.

  • options:_Options=_Options.from_dict(config.pop('options', {}))

    Configuration options for bamboost.

  • index:_IndexOptions=_IndexOptions.from_dict(config.pop('index', {}), projectDir=project_dir)

    Index settings for bamboost.

_Config.__repr__(self) -> str