Standard Library¶
tinax.stdlib converts explicit argument sequences into caller-owned configuration and creates isolated stream loggers. It never reads sys.argv, calls logging.basicConfig, mutates root handlers, or registers named loggers globally.
parse_config passes a shallow read-only mapping to the factory; mutable values produced by custom argparse actions remain caller-owned. Its argv excludes the executable name, so an Abseil entry point passes argv[1:].
Tinax does not provide an Abseil domain. Grain executables still enter through absl.app.run because that upstream worker lifecycle requires parsed Abseil flags.
import logging
import sys
from tinax.stdlib import make_stream_logger
logger = make_stream_logger(
"trainer",
level=logging.INFO,
stream=sys.stderr,
format_string="%(levelname)s %(message)s",
)
parse_config
¶
parse_config(
parser: ArgumentParser,
argv: Sequence[str],
factory: Callable[[Mapping[str, object]], T],
) -> T
Parse explicit arguments and pass a shallow read-only value mapping to a configuration factory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parser
|
ArgumentParser
|
Configured |
required |
argv
|
Sequence[str]
|
Argument strings excluding the executable name (an Abseil entry point
passes |
required |
factory
|
Callable[[Mapping[str, object]], T]
|
Callable invoked with a shallow read-only mapping of parsed values; its return value is passed through unchanged. |
required |
Returns:
| Type | Description |
|---|---|
T
|
The object produced by |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
make_stream_logger
¶
Construct an unregistered non-propagating logger with one explicit stream handler.
The logger is not added to the global registry, does not propagate to the root
logger, and leaves logging.basicConfig and root handlers untouched.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Logger name. Must be non-empty. |
required |
level
|
int
|
Logging level as an integer (booleans are rejected). |
required |
stream
|
TextIO
|
Writable text stream providing callable |
required |
format_string
|
str
|
|
required |
Returns:
| Type | Description |
|---|---|
Logger
|
A configured |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |