Gin config - ValueError raised even in examples

Viewed 188

I want to use gin config for a project, but even the most basic example raises a ValueError: No configurable matching {}.

I copied this example straight from here

config.gin

make_drink.drink_name = "G&T"
make_drink.ingredients = ["Gin", "Tonic", "Lemon"]
make_drink.ice = False

main.py

import gin
gin.parse_config_file("./config.gin")

@gin.configurable
def make_drink(drink_name:str, ingredients:list, ice:bool=False):
    print(f"New drink called: {drink_name}")
    print(f"Drink contains: " + ", ".join(ingredients))
    if ice is True:
        print("With ice")
    else:
        print("Without ice")

make_drink()

The result is always the same:

ValueError: No configurable matching 'make_drink'.
  In file "./config.gin", line 1
    make_drink.drink_name = "G&T"

Thank you in advance!

1 Answers

Alright, i got it. Apparently one must put the gin.parse_config_file("./config.gin") command in the main.

import gin

@gin.configurable
def make_drink(drink_name:str, ingredients:list, ice:bool=False):
    print(f"New drink called: {drink_name}")
    print(f"Drink contains: " + ", ".join(ingredients))
    if ice is True:
        print("With ice")
    else:
        print("Without ice")

if __name__=='__main__':
    gin.parse_config_file("./config.gin")
    make_drink()

If anyone could explain to me, why it does not work when i put at after the import, i would appreciate that.

Related