Skip to main content

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(msg) method that decides whether to output the provided message based on the value of the object's verbose field.

The ConfigDiagUnfrozen and ConfigDiagUnfrozenStdOut classes are normal dataclasses, while the ConfigDiag and ConfigDiagStdOut ones are frozen.

The ConfigDiag and ConfigDiagUnfrozen classes will output any diagnostic messages to the standard error stream, while the ConfigDiagStdOut and ConfigDiagUnfrozenStdOut ones will output the diagnostic messages to the standard output stream.

Example

Subclass the frozen ConfigDiag class, add a program-specific field:

@dataclasses.dataclass(frozen=True)
class Config(cfg_diag.ConfigDiag):
    """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")

Contact

This module is developed in a GitHub repository. Contact the StorPool support team for information.

Version history

0.1.1

  • move some tool configuration options to setup.py and pyproject.toml
  • add Python 3.9 as a supported version
  • use unittest.mock instead of mock
  • fix a code comment
  • add a manifest to include more files in the source distribution

0.1.0

  • first public release

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

cfg_diag-0.1.1.tar.gz (5.4 kB view hashes)

Uploaded Source

Built Distribution

cfg_diag-0.1.1-py3-none-any.whl (5.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page