A common configuration-storage class with a .diag() method
Project description
A common configuration-storage class with a .diag() method
Description
This module provides four classes that may be used as base classes for
storing program runtime configuration with a verbose boolean field.
The classes provide a .diag(func) method that will check the object's
verbose field and, if it is set to a true value, invoke the specified
function and output the message that it returns. If the message is not
expensive to format (e.g. it does not include stringifying elaborate
data structures), the .diag_(msg) method may be used instead.
The ConfigUnfrozen and ConfigUnfrozenStdOut classes are
normal dataclasses, while the Config and ConfigStdOut ones
are frozen.
The Config and ConfigUnfrozen classes will output any
diagnostic messages to the standard error stream, while
the ConfigStdOut and ConfigUnfrozenStdOut ones will output
the diagnostic messages to the standard output stream.
For compatibility with cfg-diag versions 0.1.x and 0.2.x, there is
also a parallel ConfigDiag* class hierarchy; the classes there are
organized in exactly the same way as those in the Config* hierarchy,
but they only provide a single .diag(msg) method that accepts
a fixed, already-built, string instead of a callback function.
These classes are deprecated and will most probably be removed in
a future version of the cfg-diag library.
Example
Subclass the frozen Config class, add a program-specific field:
@dataclasses.dataclass(frozen=True)
class Config(cfg_diag.Config):
"""Runtime configuration for the fribble program."""
path: pathlib.Path
Initialize this class from an argument parser object:
return Config(path=args.path, verbose=args.verbose)
Output a diagnostic message if requested:
cfg.diag_("This will either appear or it will not")
cfg.diag(lambda: f"Here's the thing: {thing!r}")
Contact
This module is developed in a GitHub repository. Contact the StorPool support team for information.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cfg_diag-0.4.0.tar.gz.
File metadata
- Download URL: cfg_diag-0.4.0.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d6424e257fbae7ddfabb84abdac3495f08976dea551744fdb50c3a9e264a1b2
|
|
| MD5 |
0aef063f4a14285d96311bc8c60e1501
|
|
| BLAKE2b-256 |
a2147df32c10077c9d28eb0c49e03c9c8c1c0ab0b5c374d4a72a1c41c69e690b
|
File details
Details for the file cfg_diag-0.4.0-py3-none-any.whl.
File metadata
- Download URL: cfg_diag-0.4.0-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
660b96c9744c3c74a94c249d9c7855c4457516b805244818be00f0cf8fccecbc
|
|
| MD5 |
cbf82ea113b3d7114e1392f2051562b4
|
|
| BLAKE2b-256 |
91d5fb8727ccc40622744a2ba5bcbd05ff4c4d2b7bee0e5e47519728790ec02a
|