Modules
This package provides public modules.
FastConfig
dataclass
this class provides the way to build and update instance from toml
or json
format file.
Source code in fastconfig/config.py
build(path, config=None)
classmethod
Read file from path and create/update instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Union[str, Path]
|
Union[str, Path] a file path to read a config |
required |
config |
Optional[_Self]
|
Optional[_Self] an instance inheriting from FastConfig (if updating) |
None
|
Returns: _Self: an instance inheriting from FastConfig
Source code in fastconfig/config.py
to_dict(use_key=False)
Convert from an instance to dict.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
use_key |
bool
|
bool Whether to convert to dictionary by class instance name |
False
|
Returns: dict[str, Any]
Source code in fastconfig/config.py
FastConfigError
InvalidConfigError
Bases: FastConfigError
exception when providing files or classes in unsupported formats.
MissingRequiredElementError
Bases: FastConfigError
exception when providing field
has no default value and the corresponding value could not be read from the file.
UnexpectedValueError
Bases: FastConfigError
exception whe providing failed type-checking.
fc_field(key=None, separator='.', default=MISSING, default_factory=MISSING, init=True, repr=True, hash=None, compare=True, metadata=None)
Return dataclass::field
.
wrapper of dataclass::field
for FastConfig definition.
same as field
except for passing key
and separator
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
Optional[Union[str, int]]
|
Optional[str | int]
the name of the key you want to read, divided by |
None
|
separator |
str
|
str
Separator for splitting key values, default is |
'.'
|
Returns:
Type | Description |
---|---|
_T
|
_T |
Source code in fastconfig/config.py
find_project_root(path=None)
Return if the project root is found, or None if not.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Optional[Union[str, Path]]
|
A path string or Path object to start searching, If nothing is passed, start in the current directory |
None
|
Returns:
Type | Description |
---|---|
Optional[Path]
|
Optional[Path]: the project root path, or None if the project root is not found |
Source code in fastconfig/searcher.py
is_project_root(path)
Check the given path is the project root directory or not.
This method determines the project root by whether the version control tool directory exists.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Union[str, Path]
|
The path to check whether it is the project root or not |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
The result of the project root or not |
Source code in fastconfig/searcher.py
search(target, path=None, end_up_the_project_root=True)
Recursively searches for files with the name of the target and returns the result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
Union[str, Path]
|
Search target filename, and directory names are ignored. |
required |
path |
Optional[Union[str, Path]]
|
A path string or Path object to start searching, If nothing is passed, start in the current directory. |
None
|
end_up_the_project_root |
bool
|
Whether or not to search the directory where the version control tool exists |
True
|
Returns:
Type | Description |
---|---|
Optional[Path]
|
Optional[Path]: a path of the target file, or None if the target file is not found |