Skip to content

Commit

Permalink
playing with ReST
Browse files Browse the repository at this point in the history
  • Loading branch information
3kwa committed Oct 10, 2012
1 parent c95771c commit f784a93
Showing 1 changed file with 36 additions and 11 deletions.
47 changes: 36 additions & 11 deletions README.rst
@@ -1,6 +1,9 @@
===================
constants.Constants
===================
=========
constants
=========


The simple way to deal with environment constants!


The problem?
Expand All @@ -12,18 +15,21 @@ on the environment the application is executed in.
Think database credentials over development, testing, staging, production or
stock market execution over development, testing, paper, production ...


A solution
==========

Shamelessly inspired by the app_constants_ gem, constants aims to solve that
Shamelessly inspired by the app_constants_ gem, ``constants`` aims to solve that
problem (and that problem only).

.ini file
---------

Constants use the .ini file format to specify the application constants values
in each environment. DEFAULT values are available in every environment unless
specifically overridden in a section.
``constants`` uses the .ini file format to specify the application constants
values in each environment. DEFAULT values are available in every environment
unless specifically overridden in a section.

::

[DEFAULT]
something = a_default_value
Expand All @@ -36,17 +42,24 @@ specifically overridden in a section.
To find out more about ini files and sections, check the Python standard
library configparser_ documention.

The default file is ``constants.ini`` in the current working directory. but
you can use any filename you want cf. Instantiation_.

Environment
-----------

Define the environment the application will run in. The default environment
variable to store that value is __CONSTANTS__, but you can use any variable
name you want.
name you want cf. Instantiation_.

Most platform have a way to do that, in bash:

::

export __CONSTANTS__=a_section

.. _Instantiations:

Instantiations
--------------

Expand All @@ -57,9 +70,9 @@ On instantiation, constants looks for an environement variable named
__CONSTANTS__ whose value is used to find out which section of the
constants.ini file should be used.

Constants' constructor takes two (2) optional parameters. variable let's you
specify the name of the environment variable and filename the absolute path
to the .ini file containing the constants definitions.
Constants' constructor takes two (2) optional parameters. ``variable``
let's you specify the name of the environment variable and ``filename``
the absolute path to the .ini file containing the constants definitions.

>>> consts = Constants(variable='AN_ENVIRONMENT_VARIABLE',
... filename='constants.cfg') # doctest: +SKIP
Expand All @@ -82,5 +95,17 @@ Values can also be accessed using the . operator (getattr)
>>> consts.all
1


Installation
============

constants is available on PyPI_ ...

pip install constants

... and can be forked on GitHub_.

.. _app_constants: https://github.com/leonardoborges/app_constants
.. _configparser: http://docs.python.org/library/configparser.html
.. _PyPI: http://pypi.python.org/pypi/constants
.. _GitHub: https://github.com/3kwa/constants

0 comments on commit f784a93

Please sign in to comment.