blext.utils
blext.utils.bl_init
Startup script for Blender, which (re)installs and runs an extension locally.
blext.utils.inline_script_metadata
Defines the BLExtSpec
model.
parse_inline_script_metadata
parse_inline_script_metadata(
*,
block_name: str = INLINE_METADATA_BLOCK_NAME,
py_source_code: str,
) -> dict[str, Any] | None
Parse inline script metadata from Python source code.
PARAMETER | DESCRIPTION |
---|---|
block_name
|
The name of the metadata block type to parse from the source code's header.
For instance, setting this to
TYPE:
|
py_source_code
|
The Python source code to parse for inline script metadata.
The script must start with a
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict[str, Any] | None
|
A dictionary of inline script metadata, in a format equivalent to that of |
dict[str, Any] | None
|
Otherwise the return value is |
References
PyPa on Inline Script Metadata: https://packaging.python.org/en/latest/specifications/inline-script-metadata
Source code in blext/utils/inline_script_metadata.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
parse_inline_script_metadata_str
parse_inline_script_metadata_str(
*,
block_name: str = INLINE_METADATA_BLOCK_NAME,
py_source_code: str,
) -> str | None
Parse inline script metadata from Python source code.
PARAMETER | DESCRIPTION |
---|---|
block_name
|
The name of the metadata block type to parse from the source code's header.
For instance, setting this to
TYPE:
|
py_source_code
|
The Python source code to parse for inline script metadata.
The script must start with a
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str | None
|
A string of inline script metadata, in a format equivalent to that of |
str | None
|
Otherwise the return value is |
References
PyPa on Inline Script Metadata: https://packaging.python.org/en/latest/specifications/inline-script-metadata
Source code in blext/utils/inline_script_metadata.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
replace_inline_script_metadata_str
replace_inline_script_metadata_str(
*,
block_name: str = INLINE_METADATA_BLOCK_NAME,
py_source_code: str,
metadata_str: str,
) -> str
Generate a string where the inline script metadata in the given source code has been replaced by an (also given) TOML string.
Source code in blext/utils/inline_script_metadata.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
|
blext.utils.lru_method
Implements the lru_method
decorator.
lru_method
lru_method(
maxsize: int = 128, typed: bool = False
) -> Callable[
[
Callable[
Concatenate[ClassType, ParamsType], ReturnType
]
],
Callable[
Concatenate[ClassType, ParamsType], ReturnType
],
]
Memoize a method of an immutable object, such that the cache is deleted with the object.
Source code in blext/utils/lru_method.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
blext.utils.pretty_exceptions
Exception handling for enhancing the end-user experience of dealing with errors.
exception_hook
exception_hook(
ex_type: type[BaseException],
ex: BaseException,
traceback: TracebackType | None,
) -> None
Prettifies exceptions incl. allowing the use of markdown in messages.
PARAMETER | DESCRIPTION |
---|---|
ex_type
|
Type of the exception that was raised.
TYPE:
|
ex
|
The exception that was raised.
TYPE:
|
traceback
|
The reported traceback.
TYPE:
|
Source code in blext/utils/pretty_exceptions.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
|
blext.utils.pydantic_frozendict
Implements a pydantic
wrapper for frozendict.frozendict
.
ATTRIBUTE | DESCRIPTION |
---|---|
FrozenDict |
|
blext.utils.search_in_parents
Tools for finding common information and files using platform-specific methods.
search_in_parents
search_in_parents(path: Path, filename: str) -> Path | None
Search all parents of a path for a file.
Notes
The input path
is itself searched for the filename, but only if it is a directory.
PARAMETER | DESCRIPTION |
---|---|
path
|
The path to search the parents of.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Path | None
|
Absolute path to the found file, else |
Source code in blext/utils/search_in_parents.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|