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'}
The main configuration instance containing paths, options, and index settings.
Functions
() -> Optional[Path]
Find the root directory.
(filepath) -> dict[str, Any]
Reads the configuration file and fills the configuration options.
Arguments:
- filepath:
pathlib.Path
(project_dir) -> dict[str, Any]
Get the project configuration from bamboost.toml or pyproject.toml.
Arguments:
- project_dir:
pathlib.Path
Classes
_Base
(self) -> None
Attributes:
- _field_aliases=
{}
(self, name) -> Any
Arguments:
- name:
str
(self, key, value) -> None
Set the configuration options by key, separated by dots.
Arguments:
- key:
str
- value:
typing.Any
(self, key) -> Any
Access the configuration options by key, separated by dots.
Arguments:
- key:
str
(self) -> str
(cls, config, **kwargs) -> Self
Create an instance of the dataclass from a dictionary of configuration values.
This method performs the following steps:
- Identifies valid field names and aliases.
- Logs any unknown configuration keys.
- Filters the input dictionary to include only valid keys and aliases.
- Validates the types of the configuration values.
- Creates an instance of the class with the filtered and validated configuration.
- Logs any missing fields that are using default values.
Arguments:
- cls
- config:
dict
A dictionary containing configuration key-value pairs.
- kwargs=
{}
Returns
typing_extensions.Self
An 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.
(self) -> Generator[str, None, None]
_Paths
(self, localDir=LOCAL_DIR, cacheDir=CACHE_DIR) -> None
Paths used by bamboost.
This dataclass contains the paths used by bamboost.
Attributes:
The directory where the local data is stored.
The directory where the cache is stored.
Bases
(self, name, value) -> None
Arguments:
- name:
str
- value:
typing.Any
_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
(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.
Bases
(self) -> None
_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:
Attributes:
Paths used by bamboost.
Configuration options for bamboost.
Index settings for bamboost.
Bases
(self) -> str