Debugging the Parsed Values

  • Setting debug=True

    When parsing this parameter, it will print at the terminal all the values parsed and from where it was set.

Example:

TODO !!!
  • Using the Environmental Variables

    Here is how you can add your configuration file to the package:
from fejao_config_parser import my_config

config = [
    {
        "name": "example_string",
        "type": "string",
        "default": "default_string_value",
        "env_name": "EXAMPLE_STRING",
        "terminal_help": "Example of a string terminal variable.",
        "terminal_name": "example-str",
        "terminal_name_short": "es",
    },
    {
        "name": "example_bool",
        "type": "bool",
        "default": False,
        "env_name": "EXAMPLE_BOOL",
        "terminal_help": "Example of a boolean terminal variable.",
        "terminal_name": "example-bool",
        "terminal_name_short": "eb",
    },
    {
        "name": "example_int",
        "type": "int",
        "default": 42,
        "env_name": "EXAMPLE_INT",
        "terminal_help": "Example of a integer terminal variable.",
        "terminal_name": "example-int",
        "terminal_name_short": "ei",
    },
    {
        "name": "example_float",
        "type": "float",
        "default": 4.2,
        "env_name": "EXAMPLE_FLOAT",
        "terminal_help": "Example of a float terminal variable.",
        "terminal_name": "example-float",
        "terminal_name_short": "ef",
    },
    {
        "name": "example_list",
        "type": "list",
        "default": [1, 2, 3],
        "env_name": "EXAMPLE_LIST",
        "terminal_help": "Example of a float list variable.",
        "terminal_name": "example-list",
        "terminal_name_short": "el",
    },
    {
        "name": "example_dict",
        "type": "dict",
        "default": {
            "key_1": "dict_deafult_1",
            "key_2": "dict_deafult_2",
        },
        "env_name": "EXAMPLE_DICT",
        "terminal_help": "Example of a float dictionary variable.",
        "terminal_name": "example-dict",
        "terminal_name_short": "ed",
    },
]

# Calling the package setting the debug=True
config = my_config(
    config=config,
    debug=True
)

Here is an example of starting your project from the terminal using the environmental variables:

EXAMPLE_STRING="from_env_value" \
EXAMPLE_BOOL=false \
EXAMPLE_INT=12 \
EXAMPLE_LIST=[a,b,c] \
python main.py \
--example-str from_terminal_value \
-ei 24 \
--example-float 2.4 \
--example-list "[7,8,9]"

The printed info on the terminal should be:

CONFIGURATION VALUES DEBUG INFO:

Value name: 'example_string'
Value set: 'from_env_value'
Value source: 'environment'

Value name: 'example_bool'
Value set: 'False'
Value source: 'environment'

Value name: 'example_int'
Value set: '24'
Value source: 'terminal'

Value name: 'example_float'
Value set: '2.4'
Value source: 'terminal'

Value name: 'example_list'
Value set: '['7', '8', '9']'
Value source: 'terminal'

Value name: 'example_dict'
Value set: '{'key_1': 'dict_deafult_1', 'key_2': 'dict_deafult_2'}'
Value source: 'default'

You can access the values as:

print(f"example_string: {config.example_string}")
print(f"example_bool: {config.example_bool}")
print(f"example_int: {config.example_int}")
print(f"example_float: {config.example_float}")
print(f"example_list: {config.example_list}")
print(f"example_dict: {config.example_dict}")

The ouput will be:

example_string: "from_env_value"
example_bool: False
example_int: 24
example_float: 2.4
example_list: [7, 8, 9]
example_dict: {"key_1": "dict_default_1", "key_2": "dict_default_2"}