pax_global_header00006660000000000000000000000064134212250230014504gustar00rootroot0000000000000052 comment=55b7a04aa656771ed71cd83fa10719453ef5162f derpconf-0.8.3/000077500000000000000000000000001342122502300133145ustar00rootroot00000000000000derpconf-0.8.3/.gitignore000066400000000000000000000005631342122502300153100ustar00rootroot00000000000000*.py[co] # Packages *.egg *.egg-info dist build eggs parts bin var sdist develop-eggs .installed.cfg # Installer logs pip-log.txt # Unit test / coverage reports .coverage .tox #Translations *.mo #Mr Developer .mr.developer.cfg # Debian packaging /debian/debhelper.log /debian/files /debian/python-derpconf.* /debian/python-derpconf /debian/tmp .venv .ropeproject/ derpconf-0.8.3/.travis.yml000066400000000000000000000002101342122502300154160ustar00rootroot00000000000000language: python python: - 2.7 install: - sudo apt-get install -y librtmp-dev libevent-dev - make setup script: - make test derpconf-0.8.3/LICENSE000066400000000000000000000021061342122502300143200ustar00rootroot00000000000000The MIT License Copyright (c) 2012 globo.com timehome@corp.globo.com 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. derpconf-0.8.3/MANIFEST.in000066400000000000000000000000221342122502300150440ustar00rootroot00000000000000include README.md derpconf-0.8.3/Makefile000066400000000000000000000006001342122502300147500ustar00rootroot00000000000000test pyvows: @PYTHONPATH=.:$$PYTHONPATH pyvows -v --profile --cover --cover-package=derpconf --cover-threshold=90 vows/ tox: @PATH=$$PATH:~/.pythonbrew/pythons/Python-2.7.*/bin/:~/.pythonbrew/pythons/Python-3.0.*/bin/:~/.pythonbrew/pythons/Python-3.1.*/bin/:~/.pythonbrew/pythons/Python-3.2.3/bin/:~/.pythonbrew/pythons/Python-3.3.0/bin/ tox setup: @pip install -Ue .\[tests\] derpconf-0.8.3/README.md000066400000000000000000000134131342122502300145750ustar00rootroot00000000000000derpconf ======== [![Build Status](https://secure.travis-ci.org/globocom/derpconf.png?branch=master)](http://travis-ci.org/globocom/derpconf) derpconf abstracts loading configuration files for your app. derpconf was extracted from [thumbor](http://github.com/globocom/thumbor/). Intalling --------- Installing derpconf is as easy as: pip install derpconf Usage ----- Using it is as simple as: from derpconf.config import Config conf = Config.load('/path/to/my/cfg.conf') assert conf.MY_KEY == 'MY_VALUE' # assuming there's a key called MY_KEY in # the configuration file. Settings Defaults ----------------- If you want to set default values for your configurations, just call: Config.define('MY-KEY', 'DEFAULT VALUE', 'Description for my key', 'Section') The values that define gets are: * the configuration key; * the default value for that key if it's not found in the configuration file; * the description for this key. This is very useful for generating configuration file examples. * the section that this key belongs to. Again very useful for generating configuration file examples. Using Environment Variables --------------------------- If you wish to allow environment variables to be used as the value of configuration keys, just call the `allow_environment_variables` method in your `config.py` file: from derpconf.config import Config Config.allow_environment_variables() If there's an environment variable with the same name as the given configuration, derpconf will give precedence to it, instead of using the default value or the value in the configuration file. # called program with SOMETHING=value myprogram.py assert config.SOMETHING == "value" # even if the default for 'SOMETHING' or the value in the config file is different from 'value' Reloading Configurations ------------------------ After you've loaded configurations from a file, sometimes it's needed to have them reloaded. This is the case when a new module needs to define some new default values. In order to reload values from a config object, just call `reload` on it: from derpconf.config import Config conf = Config.load('/path/to/my/cfg.conf') # then later on... Config.define('SOMENEWFOO', 'bar', 'baz', 'foo') conf.reload() assert conf.SOMENEWFOO == 'bar' Generating Configuration Examples --------------------------------- To generate a configuration example, you just need to call the `get_config_text` method. Let's see an example: from derpconf.config import Config Config.define('foo', 'fooval', 'Foo is always a foo', 'FooValues') Config.define('bar', 'barval', 'Bar is not always a bar', 'BarValues') Config.define('baz', 'bazval', 'Baz is never a bar', 'BarValues') config_sample = Config.get_config_text() print config_sample # or instead of both, just call generate_config() The following text will be print into the standard output: ################################## FooValues ################################### ## Foo is always a foo ## Defaults to: fooval #foo = 'fooval' ################################################################################ ################################## BarValues ################################### ## Bar is not always a bar ## Defaults to: barval #bar = 'barval' ## Baz is never a bar ## Defaults to: bazval #baz = 'bazval' ################################################################################ A good sample of using derpconf can be seen at [thumbor's configuration file](https://github.com/globocom/thumbor/blob/master/thumbor/config.py). Verifying a Configuration File ------------------------------ derpconf includes a configuration file verifier. The purpose of this verifier is to help you quickly understand what configuration files are missing what keys and what values will be used for them instead. Running it is as simple as including a call to `verify_config` in your `config.py` file: verify_config(file_path) Or you can leave it blank and derpconf will get the file path from `sys.argv`: verify_config() The output of the verifier is something like this: Configuration "baz" not found in file /Users/bernardo/dev/derpconf/vows/fixtures/missing.conf. Using "bazval" instead. Configuration "foo" not found in file /Users/bernardo/dev/derpconf/vows/fixtures/missing.conf. Using "fooval" instead. Configuration "bar" not found in file /Users/bernardo/dev/derpconf/vows/fixtures/missing.conf. Using "barval" instead. You can see it in use at [derpconf's code](https://github.com/globocom/derpconf/blob/master/derpconf/config.py). License ------- derpconf is licensed under the MIT License: The MIT License Copyright (c) 2012 globo.com timehome@corp.globo.com 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. derpconf-0.8.3/debian/000077500000000000000000000000001342122502300145365ustar00rootroot00000000000000derpconf-0.8.3/debian/changelog000066400000000000000000000046621342122502300164200ustar00rootroot00000000000000derpconf (0.8.2-1) unstable; urgency=medium * New upstream release -- Marcelo Jorge Vieira Thu, 11 Jan 2018 22:13:34 -0200 derpconf (0.8.1-1) unstable; urgency=medium * New upstream release * Fixed package-uses-deprecated-debhelper-compat-version * Bumped standards version to 4.0.0 (no changes) -- Marcelo Jorge Vieira Sun, 27 Aug 2017 16:01:40 -0300 derpconf (0.8.0-1~bpo8+1) jessie-backports; urgency=medium * Rebuild for jessie-backports. -- Gilles Dubuc Fri, 17 Jun 2016 11:55:15 +0000 derpconf (0.8.0-1) unstable; urgency=medium * New upstream release -- Gilles Dubuc Thu, 16 Jun 2016 16:26:41 +0000 derpconf (0.7.3-1) unstable; urgency=low * New upstream release (Closes: #774656) * Updated Standards-Version to 3.9.6 (no changes) * Added watch file * Rules: + build with buildsystem=python_distutils + Added override_dh_auto_test target + Added get-orig-source target + Added override_dh_clean target * Control: + Fixed build-depends + Added me as Maintainer + Updating long description * Updating debian copyright -- Marcelo Jorge Vieira Mon, 06 Apr 2015 23:37:14 -0300 derpconf (0.4.9-2) UNRELEASED; urgency=low * Added docs file -- Marcelo Jorge Vieira (metal) Wed, 20 Nov 2013 21:18:47 -0200 derpconf (0.4.9-1) UNRELEASED; urgency=low * New release 0.4.9; * Fixed python-six dependency; * Fixed python support; * Minimizing rules file; * Improving package description; * Refactoring Maintainer field; Now globo.com is the Maintainer and I and Wichert as uploaders; * Switch to dpkg-source 3.0 (quilt) format; * Convert copyright file to machine readable specification; * Fixed debhelper compatibility level; * Updated Standards-Version to 3.9.4 (no changes). -- Marcelo Jorge Vieira (metal) Wed, 20 Nov 2013 19:23:15 -0200 derpconf (0.3.3ubuntu1) UNRELEASED; urgency=low * Fixes on rules file - missing python libs after install package -- Paulo Sousa Wed, 16 Jan 2013 18:24:36 -0200 derpconf (0.3.3) UNRELEASED; urgency=low * New release 0.3.3 -- Paulo Sousa Wed, 16 Jan 2013 14:29:45 -0200 derpconf (0.3.0-1) UNRELEASED; urgency=low * First packaging -- Wichert Akkerman Tue, 25 Sep 2012 10:04:40 +0200 derpconf-0.8.3/debian/compat000066400000000000000000000000021342122502300157340ustar00rootroot000000000000009 derpconf-0.8.3/debian/control000066400000000000000000000016411342122502300161430ustar00rootroot00000000000000Source: derpconf Maintainer: Marcelo Jorge Vieira Uploaders: Gilles Dubuc Section: python Priority: optional Standards-Version: 4.0.0 Build-Depends: debhelper (>= 9), python-setuptools (>= 0.6b3), python-all (>= 2.6.6-3), dh-python, python-pyvows, python-gevent, python-coverage, python-colorama, python-tox, python-six X-Python-Version: >= 2.6 Homepage: https://github.com/globocom/derpconf Vcs-Git: git://github.com/globocom/derpconf.git Vcs-Browser: https://github.com/globocom/derpconf Package: python-derpconf Architecture: all Depends: ${misc:Depends}, ${python:Depends}, python-six Provides: ${python:Provides} Description: Python module to abstract loading configuration files for your app Abstracts loading configuration files for your app. derpconf-0.8.3/debian/copyright000066400000000000000000000027471342122502300165030ustar00rootroot00000000000000Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: derpconf Source: https://github.com/globocom/derpconf Files: * Copyright: 2011-2015 globo.com License: MIT Files: debian/* Copyright: 2011-2015 globo.com , 2014-2015 Marcelo Jorge Vieira License: MIT License: MIT Copyright (c) 2011-2015 globo.com . 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. derpconf-0.8.3/debian/docs000066400000000000000000000000121342122502300154020ustar00rootroot00000000000000README.md derpconf-0.8.3/debian/rules000077500000000000000000000015431342122502300156210ustar00rootroot00000000000000#!/usr/bin/make -f %: dh $@ --with python2 --buildsystem=python_distutils override_dh_auto_test: $(MAKE) test override_dh_clean: rm -rf derpconf.egg-info dh_clean get-orig-source: OUTDIR=$$PWD ; \ MAKEFILE=`echo $(MAKEFILE_LIST) | awk '{ print $$1 }'` ; \ FILE=`readlink -f $$MAKEFILE` ; \ DIR=`dirname $$FILE` ; \ cd $$DIR/.. ; \ TMP=`mktemp -d` ; \ if ! USCAN=`uscan --no-symlink --destdir $$TMP` ; then exit 1 ; fi ; \ VERSION=`echo $$USCAN | sed -n 's/.*Newer version (\(.*\)) available.*/\1/p'` ; \ cd $$TMP ; \ tar xzf derpconf-$$VERSION.tar.gz ; \ cd derpconf-$$VERSION ; \ rm -rf debian ; \ cd .. ; \ tar c derpconf-$$VERSION | gzip -9 > derpconf_$$VERSION.orig.tar.gz ; \ rm -rf derpconf-$$VERSION ; \ mv derpconf_$$VERSION.orig.tar.gz $$OUTDIR ; \ cd $$OUTDIR ; \ rm -rf $$TMP ; \ echo Saved file at derpconf_$$VERSION.orig.tar.gz derpconf-0.8.3/debian/source/000077500000000000000000000000001342122502300160365ustar00rootroot00000000000000derpconf-0.8.3/debian/source/format000066400000000000000000000000141342122502300172440ustar00rootroot000000000000003.0 (quilt) derpconf-0.8.3/debian/watch000066400000000000000000000002261342122502300155670ustar00rootroot00000000000000version=3 opts="filenamemangle=s/.+\/v?(.*)\.tar\.gz/derpconf-$1.tar.gz/" \ https://github.com/globocom/derpconf/tags (?:.*/)?v?(\d[\d\.]*)\.tar\.gz derpconf-0.8.3/derpconf/000077500000000000000000000000001342122502300151145ustar00rootroot00000000000000derpconf-0.8.3/derpconf/__init__.py000066400000000000000000000000001342122502300172130ustar00rootroot00000000000000derpconf-0.8.3/derpconf/config.py000066400000000000000000000233651342122502300167440ustar00rootroot00000000000000#!/usr/bin/python # -*- coding: utf-8 -*- # derpconf # https://github.com/globocom/derpconf # Licensed under the MIT license: # http://www.opensource.org/licenses/mit-license # Copyright (c) 2012 globo.com timehome@corp.globo.com import sys import os import logging from collections import defaultdict from os.path import join, exists, abspath, dirname, isdir import imp import six from textwrap import fill class ConfigurationError(RuntimeError): pass class Config(object): class_defaults = {} class_group_items = defaultdict(list) class_groups = [] class_descriptions = {} class_aliases = defaultdict(list) class_aliased_items = {} _allow_environment_variables = False @classmethod def define(cls, key, value, description, group='General'): cls.class_defaults[key] = value cls.class_descriptions[key] = description cls.class_group_items[group].append(key) if group not in cls.class_groups: cls.class_groups.append(group) @classmethod def alias(cls, new_key, aliased_key): if aliased_key in cls.class_aliased_items: aliased_key = cls.class_aliased_items[aliased_key] cls.class_aliases[aliased_key].append(new_key) cls.class_aliased_items[new_key] = aliased_key @classmethod def get_conf_file(cls, conf_name, lookup_paths): for conf_path in lookup_paths: conf_path_file = abspath(join(conf_path, conf_name)) if exists(conf_path_file): return conf_path_file return None @classmethod def allow_environment_variables(cls): cls._allow_environment_variables = True @classmethod def load(cls, path, conf_name=None, lookup_paths=[], defaults={}): if path is None and conf_name is not None and lookup_paths: path = cls.get_conf_file(conf_name, lookup_paths) if path is None: return cls(defaults=defaults) if not exists(path): raise ConfigurationError('Configuration file not found at path %s' % path) conf = cls(defaults=defaults) return cls.__load_from_path(conf, path) @classmethod def __load_from_path(cls, conf, path): if isdir(path): conf.config_folder = path files = sorted(os.listdir(path)) for file in files: if file.endswith('.conf'): filepath = path + os.sep + file conf = Config.__load_from_path(conf, filepath) return conf with open(path) as config_file: name = 'configuration' code = config_file.read() module = imp.new_module(name) six.exec_(code, module.__dict__) conf.config_file = path for name, value in module.__dict__.items(): if name.upper() == name: conf._items[name] = value setattr(conf, name, value) return conf @classmethod def verify(cls, path): if path is None: return [] if not exists(path): raise ConfigurationError('Configuration file not found at path %s' % path) with open(path) as config_file: name = 'configuration' code = config_file.read() module = imp.new_module(name) six.exec_(code, module.__dict__) conf = cls(defaults=[]) for name, value in module.__dict__.items(): if name.upper() == name: setattr(conf, name, value) not_found = [] for key, value in cls.class_defaults.items(): if key not in conf.__dict__: not_found.append((key, value)) return not_found def __init__(self, **kw): if 'defaults' in kw: self.defaults = kw['defaults'] self._items = kw for key, value in kw.items(): setattr(self, key, value) @property def items(self): values = {} for key, value in self.class_defaults.items(): values[key] = value for key, value in self.defaults.items(): values[key] = value for key, value in self._items.items(): values[key] = value return values def reload(self): cfg = getattr(self, 'config_file', None) if cfg is None: return self.__load_from_path(self, cfg) def validates_presence_of(self, *args): for arg in args: if not hasattr(self, arg): raise ConfigurationError('Configuration %s was not found and does not have a default value. Please verify your thumbor.conf file' % arg) def get(self, name, default=None): if hasattr(self, name): return getattr(self, name) return default def get_description(self, name): if hasattr(self, name): return self.class_descriptions.get(name, None) raise KeyError('No config called \'%s\'' % name) def __setattr__(self, name, value): if name in self.__class__.class_aliased_items: logging.warn('Option %s is marked as deprecated please use %s instead.' % (name, self.__class__.class_aliased_items[name])) self.__setattr__(self.__class__.class_aliased_items[name], value) else: super(Config, self).__setattr__(name, value) def __getattribute__(self, name): if name in ['_allow_environment_variables']: return super(Config, self).__getattribute__(name) if self._allow_environment_variables: value = os.environ.get(name, None) if value is not None: return value return super(Config, self).__getattribute__(name) def __getattr__(self, name): if name in self.__dict__: return self.__dict__[name] if name in self.__class__.class_aliased_items: logging.warn('Option %s is marked as deprecated please use %s instead.' % (name, self.__class__.class_aliased_items[name])) return self.__getattr__(self.__class__.class_aliased_items[name]) if 'defaults' in self.__dict__ and name in self.__dict__['defaults']: return self.__dict__['defaults'][name] if name in self.__class__.class_defaults: return self.__class__.class_defaults[name] raise AttributeError(name) def __getitem__(self, name): if hasattr(self, name): return getattr(self, name) raise KeyError('No config called \'%s\'' % name) def __setitem__(self, name, value): setattr(self, name, value) @classmethod def get_config_text(cls): result = [] MAX_LEN = 80 SEPARATOR = '#' for group in cls.class_groups: keys = cls.class_group_items[group] sep_size = int(round((MAX_LEN - len(group)) / 2, 0)) - 1 group_name = SEPARATOR * sep_size + ' ' + group + ' ' + SEPARATOR * sep_size if len(group_name) < MAX_LEN: group_name += SEPARATOR result.append(group_name) for key in keys: result.append('') value = cls.class_defaults[key] description = cls.class_descriptions[key] wrapped = fill(description, width=78, subsequent_indent='## ') result.append('## %s' % wrapped) if key in cls.class_aliases: result.append('## Aliases: %s' % ', '.join(cls.class_aliases[key])) result.append('## Defaults to: %s' % format_value(value)) result.append('#%s = %s' % (key, format_value(value))) result.append('') result.append(SEPARATOR * MAX_LEN) result.append('') result.append('') return '\n'.join(result) def verify_config(path=None): OKBLUE = '\033[94m' ENDC = '\033[0m' OKGREEN = '\033[92m' if path is None: if len(sys.argv) < 2: raise ValueError('You need to specify a path to verify.') path = sys.argv[1] validation = Config.verify(path) for error in validation: sys.stdout.write('Configuration "{0}{1}{2}" not found in file {3}. Using "{4}{5}{2}" instead.\n'.format(OKBLUE, error[0], ENDC, path, OKGREEN, error[1])) def generate_config(): sys.stdout.write("%s\n" % Config.get_config_text()) spaces = ' ' * 4 def format_tuple(value, tabs=0): separator = spaces * (tabs + 0) item_separator = spaces * (tabs + 1) start_delimiter = isinstance(value, tuple) and '(' or '[' end_delimiter = isinstance(value, tuple) and ')' or ']' representation = '' if tabs != 0: representation += '#' representation += "%s%s\n" % (separator, start_delimiter) for item in value: if isinstance(item, (tuple, list, set)): representation += format_tuple(item, tabs + 1) else: representation += '#%s' % item_separator + format_value(item) + ",\n" representation += "#%s%s%s\n" % (separator, end_delimiter, (tabs > 0 and ',' or '')) return representation def format_value(value): if isinstance(value, six.string_types): return "'%s'" % value if isinstance(value, (tuple, list, set)): return format_tuple(value) return str(value) if __name__ == '__main__': Config.define('foo', 'fooval', 'Foo is always a foo', 'FooValues') Config.define('bar', 'barval', 'Bar is not always a bar', 'BarValues') Config.define('baz', 'bazval', 'Baz is never a bar', 'BarValues') config_sample = Config.get_config_text() sys.stdout.write("%s\n" % config_sample) # or instead of both, just call generate_config() verify_config(abspath(join(dirname(__file__), '../vows/fixtures/missing.conf'))) derpconf-0.8.3/derpconf/version.py000066400000000000000000000003771342122502300171620ustar00rootroot00000000000000#!/usr/bin/python # -*- coding: utf-8 -*- # derpconf # https://github.com/globocom/derpconf # Licensed under the MIT license: # http://www.opensource.org/licenses/mit-license # Copyright (c) 2012 globo.com timehome@corp.globo.com __version__ = "0.8.3" derpconf-0.8.3/requirements.txt000066400000000000000000000000501342122502300165730ustar00rootroot00000000000000gevent pyVows coverage colorama tox six derpconf-0.8.3/setup.py000066400000000000000000000030061342122502300150250ustar00rootroot00000000000000#!/usr/bin/python # -*- coding: utf-8 -*- # thumbor imaging service # https://github.com/globocom/thumbor/wiki # Licensed under the MIT license: # http://www.opensource.org/licenses/mit-license # Copyright (c) 2011 globo.com timehome@corp.globo.com from setuptools import setup from derpconf.version import __version__ tests_require = [ 'gevent', 'pyVows', 'coverage', 'colorama', 'tox', 'six', ] def run_setup(extension_modules=[]): setup( name='derpconf', version=__version__, description="derpconf abstracts loading configuration files for your app", long_description=""" derpconf abstracts loading configuration files for your app. """, keywords='configuration', author='globo.com', author_email='timehome@corp.globo.com', url='https://github.com/globocom/derpconf', license='MIT', classifiers=[ 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', 'Natural Language :: English', 'Operating System :: MacOS', 'Operating System :: POSIX :: Linux', 'Programming Language :: Python :: 2.7', ], packages=['derpconf'], package_dir={"derpconf": "derpconf"}, install_requires=[ 'six', ], extras_require={ 'tests': tests_require, }, include_package_data=False ) run_setup() derpconf-0.8.3/tox.ini000066400000000000000000000005711342122502300146320ustar00rootroot00000000000000# Tox (http://tox.testrun.org/) is a tool for running tests # in multiple virtualenvs. This configuration file will run the # test suite on all supported python versions. To use it, "pip install tox" # and then run "tox" from this directory. [tox] envlist = py27, py32, py33, pypy [testenv] commands = make test deps = gevent pyVows coverage colorama six derpconf-0.8.3/vows/000077500000000000000000000000001342122502300143125ustar00rootroot00000000000000derpconf-0.8.3/vows/__init__.py000066400000000000000000000000001342122502300164110ustar00rootroot00000000000000derpconf-0.8.3/vows/config_vows.py000066400000000000000000000226171342122502300172170ustar00rootroot00000000000000#!/usr/bin/python # -*- coding: utf-8 -*- # derpconf # https://github.com/globocom/derpconf # Licensed under the MIT license: # http://www.opensource.org/licenses/mit-license # Copyright (c) 2012 globo.com timehome@corp.globo.com import os from os.path import abspath, join, dirname from collections import defaultdict from pyvows import Vows, expect from derpconf.config import Config, ConfigurationError fix = lambda name: abspath(join(dirname(__file__), 'fixtures', name)) @Vows.batch class Configuration(Vows.Context): class WhenLoading(Vows.Context): class WhenFileDoesNotExist(Vows.Context): def topic(self): err = expect.error_to_happen(ConfigurationError) with err: Config.load(fix('not-existent.conf')) return err def should_be_an_error(self, topic): expect(topic).to_be_an_error() expect(topic).to_be_an_error_like(ConfigurationError) class WhenFileExists(Vows.Context): def topic(self): return Config.load(fix('sample.conf'), defaults={ 'PROPER': 'PROPERVALUE' }) def should_have_default_value(self, topic): expect(topic.PROPER).to_equal('PROPERVALUE') def should_have_set_value(self, topic): expect(topic.FOO).to_equal('bar') def should_not_have_lower_case_value(self, topic): expect(hasattr(topic, 'baz')).to_be_false() class WhenPathIsNone(Vows.Context): class AndConfNameExists(Vows.Context): def topic(self): return Config.load(None, conf_name='sample.conf', lookup_paths=['vows/fixtures/']) def should_have_set_value(self, topic): expect(topic.FOO).to_equal('bar') class AndConfNameDoesNotExist(Vows.Context): def topic(self): return Config.load( None, conf_name='not-existent.conf', lookup_paths=['vows/fixtures/'], defaults={'DEFAULT': 'DEFAULTVALUE'} ) def should_have_default_values(self, topic): expect(topic.DEFAULT).to_equal('DEFAULTVALUE') class AndConfNameIsNone(Vows.Context): def topic(self): return Config.load(None, defaults={'DEFAULT': 'DEFAULTVALUE'}) def should_have_default_values(self, topic): expect(topic.DEFAULT).to_equal('DEFAULTVALUE') class WhenPathIsDirectory(Vows.Context): def topic(self): return Config.load(fix('conf.d'), defaults={ 'PROPER': 'PROPERVALUE' }) def should_have_default_value(self, topic): expect(topic.PROPER).to_equal('PROPERVALUE') def should_have_overridden_value(self, topic): expect(topic.FOO).to_equal('override') def should_have_new_value(self, topic): expect(topic.NEW).to_equal('thing') def should_not_have_lower_case_value(self, topic): expect(hasattr(topic, 'baz')).to_be_false() class WhenSettingAnAlias(Vows.Context): def topic(self): Config.alias('OTHER_ENGINE', 'ENGINE') return Config(OTHER_ENGINE='x') def should_set_engine_attribute(self, config): expect(config.ENGINE).to_equal('x') def should_set_other_engine_attribute(self, config): expect(config.OTHER_ENGINE).to_equal('x') class WhenSettingAnAliasedKey(Vows.Context): def topic(self): Config.alias('LOADER_ALIAS', 'LOADER') return Config(LOADER='y') def should_set_loader_attribute(self, config): expect(config.LOADER).to_equal('y') def should_set_loader_alias_attribute(self, config): expect(config.LOADER_ALIAS).to_equal('y') class WithAliasedAliases(Vows.Context): def topic(self): Config.alias('STORAGE_ALIAS', 'STORAGE') Config.alias('STORAGE_ALIAS_ALIAS', 'STORAGE_ALIAS') return Config(STORAGE_ALIAS_ALIAS='z') def should_set_storage_attribute(self, config): expect(config.STORAGE).to_equal('z') def should_set_storage_alias_attribute(self, config): expect(config.STORAGE_ALIAS).to_equal('z') def should_set_storage_alias_alias_attribute(self, config): expect(config.STORAGE_ALIAS_ALIAS).to_equal('z') class WithDefaultValues(Vows.Context): def topic(self): return Config() class WhenVerifying(Vows.Context): def topic(self): class SpecialConfig(Config): class_defaults = {} class_group_items = defaultdict(list) class_groups = [] class_descriptions = {} SpecialConfig.define('some_key', 'default', 'test key') return SpecialConfig.verify(fix('missing.conf')) def should_be_lengthy(self, topic): expect(topic).to_length(1) class WhenUsedAsDict(Vows.Context): def topic(self): return Config.load(fix('sample.conf')) def should_have_get_value_as_dict(self, topic): expect(topic['FOO']).to_equal('bar') def should_have_set_value_as_dict(self, topic): topic['X'] = 'something' expect(topic['X']).to_equal('something') class WithError(Vows.Context): def topic(self, parent_topic): err = expect.error_to_happen(KeyError) with err: parent_topic['INVALID_KEY'] return err def should_raise_key_error(self, topic): expect(topic).to_be_an_error_like(KeyError) class WhenGetDescription(Vows.Context): def topic(self): Config.define('some_key', 'default', 'test key') return Config.load(fix('missing.conf')) def should_have_description(self, topic): expect(topic.get_description('some_key')).to_equal('test key') class WhenEnvironmentVariablesIsDisabled(Vows.Context): def topic(self): Config._allow_environment_variables = False config = Config.load(fix('sample.conf')) try: os.environ['FOO'] = "baz" return config.FOO finally: del os.environ['FOO'] def should_be_equal_to_env(self, topic): expect(topic).to_equal("bar") class WhenGettingFromEnvironment(Vows.Context): class WhenKeyDoesNotExistInConfiguration(Vows.Context): def topic(self): os.environ['SOME_CONFIGURATION'] = "test value" config = Config() Config.allow_environment_variables() return config.SOME_CONFIGURATION def should_be_equal_to_env(self, topic): expect(topic).to_equal("test value") class WhenKeyExistsInConfigurationFile(Vows.Context): def topic(self): config = Config.load(fix('sample.conf')) Config.allow_environment_variables() try: os.environ['FOO'] = "baz" return config.FOO finally: del os.environ['FOO'] def should_be_equal_to_env(self, topic): expect(topic).to_equal("baz") class WhenReloading(Vows.Context): def topic(self): class SpecialConfig(Config): class_defaults = {} class_group_items = defaultdict(list) class_groups = [] class_descriptions = {} config = SpecialConfig.load(fix('sample.conf'), defaults={ 'PROPER': 'PROPERVALUE' }) SpecialConfig.define('UBERFOO', 'baz', 'something', 'else') config.reload() return config def should_have_uberfoo(self, topic): expect(hasattr(topic, 'UBERFOO')).to_be_true() expect(topic.UBERFOO).to_equal('baz') class WhenGeneratingConfig(Vows.Context): def topic(self): class SpecialConfig(Config): class_defaults = {} class_group_items = defaultdict(list) class_groups = [] class_descriptions = {} SpecialConfig.define( 'SOME_TUPLE_VAR', ('foo', 'bar'), 'Tuple var from config', 'some config' ) text = SpecialConfig.get_config_text() return text.split('\n') def should_have_uberfoo(self, topic): expect(topic).to_equal([ '################################# some config ##################################', '', '## Tuple var from config', '## Defaults to: (', "# 'foo',", "# 'bar',", '#)', '', '#SOME_TUPLE_VAR = (', "# 'foo',", "# 'bar',", '#)', '', '', '################################################################################', '', '' ]) derpconf-0.8.3/vows/fixtures/000077500000000000000000000000001342122502300161635ustar00rootroot00000000000000derpconf-0.8.3/vows/fixtures/conf.d/000077500000000000000000000000001342122502300173325ustar00rootroot00000000000000derpconf-0.8.3/vows/fixtures/conf.d/01-sample.conf000066400000000000000000000000241342122502300216740ustar00rootroot00000000000000FOO="bar" baz="baj" derpconf-0.8.3/vows/fixtures/conf.d/02-sample.conf000066400000000000000000000000321342122502300216740ustar00rootroot00000000000000FOO="override" NEW="thing"derpconf-0.8.3/vows/fixtures/conf.d/03-sample.conf.bak000066400000000000000000000000401342122502300224300ustar00rootroot00000000000000FOO="shouldn't" NEW="be a thing"derpconf-0.8.3/vows/fixtures/missing.conf000066400000000000000000000000001342122502300204710ustar00rootroot00000000000000derpconf-0.8.3/vows/fixtures/sample.conf000066400000000000000000000000241342122502300203070ustar00rootroot00000000000000FOO="bar" baz="baj"