Coder Social home page Coder Social logo

varlet's Introduction

Varlet

Varlet lets you prompt for variables at runtime, and saves them to a variables module.

Install

pip install varlet

Usage

In your settings.py file add:

from varlet import variable

whenever you declare a variable that could change depending on the environment, use:

# It is OK to make this True if you are in dev
DEBUG = variable("DEBUG", default=False)

If this "DEBUG" variable is not defined in the variables module (somewhere in your python path), the user is prompted to enter a Python expression to set it.

When the prompt is displayed, the comments directly above the call to variable() are displayed, and the prompt has a default value as specified by the default argument.

Implementation Details

varlet assumes there is a variables module located somewhere in your Python path. If it is not found, it will attempt to create one based on the location of __main__.

When a variable is set to a value, varlet will eval the value (to make sure it is valid python), and then perform ast.literal_eval(repr(value)) to ensure that the value has a valid representation that can be written to a file. The repr(value) is then appended to the end of the variables module (along with any comments associated with the value).

If STDIN is not a tty-like interface, then a KeyError is raise if the variable is not set in the variables module.

varlet's People

Contributors

mdj2 avatar

Watchers

 avatar  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.