Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
chomechome committed Feb 11, 2018
1 parent 7d7641d commit bfcbff3
Show file tree
Hide file tree
Showing 71 changed files with 2,417 additions and 2 deletions.
59 changes: 59 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.pyc
*.pyo
*.pyd
*.local

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache/
.hypothesis/
coverage.xml

# IPython Notebook
.ipynb_checkpoints

# pyenv
.python-version

# dotenv
.env

# virtualenv
venv/
ENV/
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
language: python

python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"

install:
- "pipenv install --dev"
- "pip install -U -e ."

script:
- "pipenv run pytest tests"
- "pipenv run flake8"
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright 2018 Vladislav Blinov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
13 changes: 13 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true

[dev-packages]

pytest = "*"
hypothesis = "*"
"flake8" = "*"

[packages]

"e1839a8" = {path = ".", editable = true}
185 changes: 185 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions README.md

This file was deleted.

65 changes: 65 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
Granula: Multi-file Configurations for Python Applications
==============================================

.. image:: https://travis-ci.org/chomechome/granula.svg?branch=master
:target: https://travis-ci.org/chomechome/granula
:alt: TravisCI status

---------------

**Granula** is a tool that aims to help maintain multi-file configurations for
Python applications (with environments and more).

Installation
------------

::

$ pipenv install granula

or, in a more familiar way to some (though you should take a look at `pipenv http://pipenv.readthedocs.io/en/latest/`)

$ pip install granula

🌈🌈🌈

☤ Features
----------

- Gathers configurations from multiple files or directories.
- Supports widely used file formats (YAML, JSON).
- Offers a small DSL that allows to load environment variables into config
files.
- Manages different configuration environments (e.g. testing, production).

☤ Usage
-------

.. code-block:: python
>> config = granula.Config.from_directory('examples/multi-file/settings')
>> config
Config({'name': 'Darth Vader', ...})
>> config.name
'Darth Vader'
>> config.occupation
'sith lord'
>> config.family
Config({'fiancee': 'Padme Amidala', 'children': ['Luke', 'Leia']})
where ``examples/multi-file/settings`` is a directory that contains multiple
configuration files.

``granula.Config.from_directory`` parses files in the lexicographic order.
Every file is expected to contain a mapping. The values specified in the
preceding files can be overwritten in the succeeding files
(``config.name`` in the example above).

``granula.Config.from_directory`` takes a ``pattern`` parameter which is used
to match filenames. If a string is passed, it is considered to be a shell-style
wildcard pattern. An object that implements ``granula.pattern.IFilenamePattern``
can also be passed. See ``examples/environments/`` on how to manage
configuration environments using ``pattern`` parameter.

Also see ``examples/dsl/`` for examples on how to load environment variables in
config files using ``granula`` DSL.
15 changes: 15 additions & 0 deletions examples/dsl/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os

import granula


if __name__ == '__main__':
# use default value here, specified using 'val' operator
default = granula.Config.from_directory('settings')

# add SECRET variable to the environment and parse again
os.environ['SECRET'] = 'secret'
secret = granula.Config.from_directory('settings')

print(default)
print(secret)
2 changes: 2 additions & 0 deletions examples/dsl/settings/01-base.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
config:
variable: ${env SECRET|val 'variable'}
2 changes: 2 additions & 0 deletions examples/dsl/settings/02-extension.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
config:
reference: ${ref config variable}
Loading

0 comments on commit bfcbff3

Please sign in to comment.