logo

... gin.


Gin is a system for configuring python code that is still very much in early phases, but very powerful.


Notes

It does not make sense to create a function in order to configure something. You may need to make a reference first though. The files below reflect how you might be able to do that.

config.gin

simulate.random_func = @random.uniform

random.uniform.a = 0 
random.uniform.b = 2

simulate.py

import gin
import random

gin.external_configurable(random.uniform)
gin.external_configurable(random.triangular)

@gin.configurable(blacklist=["n_samples"])
def simulate(random_func, n_samples):
    return sum(random_func() for i in range(n_samples))

if __name__ == "__main__":
    gin.parse_config_file('config.gin')
    print(simulate())

Feedback? See an issue? Something unclear? Feel free to mention it here.

If you want to be kept up to date, consider getting the newsletter.