Giter VIP home page Giter VIP logo

confuse_jinja's Introduction

Confuse - Jinja Variables

Simple Ansible-style variable parsing for Confuse config files using Jinja2.

Install

pip install confuse-jinja

Usage

# config.yml
asdf:
  blah: asdf{{ C.other.thing }}
nested: '{{ C.asdf }}' # need to quote if you start with a '{'
other:
  thing: 456
import confuse
import confuse_jinja
confuse_jinja.enable() # now you can use jinja2 templates inside your config values

config = confuse.Configuration('asdf')
config.set(confuse.load_yaml('config.yml'))

assert config['asdf']['blah'].get() == 'asdf456'
assert config['nested'].get() == {'blah': 'asdf456'}

How it works

  • for any config values that are a string, render it as a jinja2 template
  • try to parse rendered string as python using ast functions graciously pulled from ansible's source code
    • if a valid python object (list, dict, etc.) can be parsed from the string the object will be returned, otherwise it will return as a string.

TODO:

  • test in a yaml file (possible syntax errors)
  • enable on a config-by-config object basis instead of globally.
    • would need to replace ConfigView.__getitem__ for a single Config
    • would require using self.Subview instead of global Subview

confuse_jinja's People

Contributors

beasteers avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.