mafw.scripts.support
Shared runtime support for the MAFw Click executable.
This module contains root-group behavior, logging and exception display, banner rendering, and warning-capture setup used by the command modules.
- author:
Bulgheroni Antonio
Module Attributes
Modules omitted from rich traceback locals. |
|
Numeric logging levels accepted by the root CLI option. |
|
Click settings shared by the MAFw root group. |
|
Styled welcome banner rendered for rich command invocations. |
|
Root logger configured by the CLI options. |
Functions
|
Return the pure message of the warning. |
|
Display exception information with optional debug details. |
Check if the Python version has the warning capture bug in free-threading mode. |
|
|
Set up the logger. |
|
Print the welcome banner only once, only for rich UI, and only if not disabled. |
Classes
|
Click group with abbreviation and MAFw-specific exit handling. |
|
Enumerator to handle the script return value. |
- class mafw.scripts.support.MAFwGroup(name: str | None = None, commands: MutableMapping[str, Command] | Sequence[Command] | None = None, invoke_without_command: bool = False, no_args_is_help: bool | None = None, subcommand_metavar: str | None = None, chain: bool = False, result_callback: Callable[[...], Any] | None = None, **kwargs: Any)[source]
Bases:
AbbreviateGroupClick group with abbreviation and MAFw-specific exit handling.
- group_class
alias of
AbbreviateGroup
- _detect_command_name(args: list[str]) str | None[source]
Return the first subcommand token while skipping root option values.
- class mafw.scripts.support.ReturnValue(*values)[source]
Bases:
IntEnumEnumerator to handle the script return value.
- Error = 1
Generic error
- OK = 0
No error
- mafw.scripts.support.custom_formatwarning(message: Warning | str, category: type[Warning], filename: str, lineno: int, line: str | None = None) str[source]
Return the pure message of the warning.
- mafw.scripts.support.display_exception(exception: Exception, show_traceback: bool = False) None[source]
Display exception information with optional debug details.
This function logs exception information at the critical level. When show_traceback is enabled, it logs the full exception including traceback information. Otherwise, it logs a simplified message directing users to enable debug mode for more details.
- Parameters:
exception (Exception) – The exception to be displayed and logged.
show_traceback (bool) – Flag indicating whether to show detailed traceback information. Defaults to False
- mafw.scripts.support.is_bugged_warning_capture_version() bool[source]
Check if the Python version has the warning capture bug in free-threading mode.
Python 3.14.0 through 3.14.3 (free-threading builds only) have a bug where
logging.captureWarnings(True)can crash or misbehave. This function returns True when the current interpreter is affected.Note
See https://github.com/python/cpython/pull/146374 for details.
Todo
Remove this workaround when Python 3.14 is no longer a supported version (expected late 2030).
- Returns:
True if the interpreter is affected by the warning capture bug, False otherwise.
- Return type:
bool
- mafw.scripts.support.logger_setup(level: str, ui: str, tracebacks: bool) None[source]
Set up the logger.
This function is actually configuring the root logger level from the command line options and it attaches either a RichHandler or a StreamHandler depending on the user interface type.
The tracebacks flag is used only by the RichHandler. Printing the tracebacks is rather useful when debugging the code, but it could be detrimental for final users. In normal circumstances, tracebacks is set to False, and is turned on when the debug flag is activated.
- Parameters:
level (str) – Logging level as a string.
ui (str) – User interface as a string (‘rich’ or ‘console’).
tracebacks – Enable/disable the logging of exception tracebacks.
- mafw.scripts.support.print_banner(ctx: Context) None[source]
Print the welcome banner only once, only for rich UI, and only if not disabled.
Note
ctx.obj is not yet populated when Group.invoke() is called, but ctx.params contains parsed options for the current group. We therefore inspect the root context params.
- mafw.scripts.support.CONTEXT_SETTINGS = {'help_option_names': ['-h', '--help']}
Click settings shared by the MAFw root group.
- mafw.scripts.support.LEVELS = {'critical': 50, 'debug': 10, 'error': 40, 'info': 20, 'warning': 30}
Numeric logging levels accepted by the root CLI option.
- mafw.scripts.support._warnings_captured = False
Whether logging has installed the warning capture hook.
- mafw.scripts.support.log = <RootLogger root (WARNING)>[source]
Root logger configured by the CLI options.
- mafw.scripts.support.suppress = [<module 'click' from '/opt/hatch/env/virtual/mafw/pyqYxQxp/dev.py3.14/lib/python3.14/site-packages/click/__init__.py'>]
Modules omitted from rich traceback locals.
- mafw.scripts.support.welcome_message = <rich_pyfiglet.rich_figlet.RichFiglet object>
Styled welcome banner rendered for rich command invocations.