unravel.core.config module#

This script defines classes for reading configuration settings from a file and accessing them using attribute-style access. It uses the ConfigParser module to parse configuration files and provides convenient access to configuration sections and values.

Classes:
  • AttrDict: A dictionary subclass that allows attribute access to its keys.

  • Config: A class to read configuration from a file and allow attribute access using RawConfigParser.

  • Configuration: A class to hold global configuration settings.

Usage:

Import the classes and use them to read and access configuration settings from a file.

Example

from path.to.this.script import Config, Configuration

config = Config(“path/to/config_file.ini”) database_config = config.database print(database_config.username) # Access a configuration value using attribute access

Classes:
AttrDict
  • A dictionary that allows attribute access to its keys.

  • Methods:
    • __getattr__: Returns the value associated with the given key.

Config
  • Reads configuration from a file and allows attribute access using RawConfigParser.

  • Methods:
    • __init__: Initializes the Config object and reads the configuration file.

    • __getattr__: Returns a dictionary-like object for the specified section, with comments stripped from values.

    • _strip_comments: Static method that strips inline comments from configuration values.

Configuration
  • Holds global configuration settings.

  • Attributes:
    • verbose: A boolean flag to control verbosity of the application.

Note

  • The Config class uses the RawConfigParser from the configparser module to parse the configuration file.

  • The AttrDict class allows for convenient attribute access to dictionary keys.

  • The Configuration class can be extended to hold additional global settings as needed.

class unravel.core.config.AttrDict[source]#

Bases: dict

A dictionary that allows attribute access.

class unravel.core.config.Config(config_file)[source]#

Bases: object

A class to read configuration from a file and allow attribute access using RawConfigParser.

class unravel.core.config.Configuration[source]#

Bases: object

A class to hold configuration settings.

verbose = False#