Skip to content

Commit 72d73a8

Browse files
committed
first commit
0 parents  commit 72d73a8

23 files changed

+389
-0
lines changed

.bumpversion.cfg

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[bumpversion]
2+
current_version = 0.0.0
3+
commit = True
4+
tag = True
5+
tag_name = {new_version}
6+
7+
[bumpversion:file:setup.py]

.coveragerc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[run]
2+
omit=
3+
*/tests/*
4+
*test*

.gitignore

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
5+
# C extensions
6+
*.so
7+
8+
# Distribution / packaging
9+
.Python
10+
env/
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
lib/
17+
lib64/
18+
parts/
19+
sdist/
20+
var/
21+
*.egg-info/
22+
.installed.cfg
23+
*.egg
24+
25+
# PyInstaller
26+
# Usually these files are written by a python script from a template
27+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
28+
*.manifest
29+
*.spec
30+
31+
# Installer logs
32+
pip-log.txt
33+
pip-delete-this-directory.txt
34+
35+
# Unit test / coverage reports
36+
htmlcov/
37+
.tox/
38+
.coverage
39+
.cache
40+
nosetests.xml
41+
coverage.xml
42+
43+
# Translations
44+
*.mo
45+
*.pot
46+
47+
# Django stuff:
48+
*.log
49+
50+
# Sphinx documentation
51+
docs/_build/
52+
53+
# PyBuilder
54+
target/
55+
56+
# sqlite
57+
*.db
58+
*.sqlite3
59+
60+
# virtualenv
61+
venv*

.travis.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
language: python
2+
3+
python:
4+
- "2.7"
5+
- "3.4"
6+
7+
install:
8+
- make requirements
9+
10+
before-script:
11+
- pip install python-coveralls
12+
13+
script: make test
14+
15+
after_sucess:
16+
- coveralls

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Diego Garcia
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
clean:
2+
@find . -name "*.pyc" | xargs rm -rf
3+
@find . -name "*.pyo" | xargs rm -rf
4+
@find . -name "__pycache__" -type d | xargs rm -rf
5+
6+
flake8:
7+
flake8 simple_settings/
8+
9+
test: clean flake8
10+
py.test --cov-config .coveragerc --cov-report term-missing --cov simple_settings/ tests/
11+
12+
test-debug: clean
13+
py.test -x --pdb simple_settings/ tests/
14+
15+
requirements: clean
16+
pip install -r requirements-dev.txt
17+
18+
release-patch:
19+
bumpversion patch
20+
21+
release-minor:
22+
bumpversion minor
23+
24+
release-major:
25+
bumpversion major
26+
27+
sdist: test
28+
@python setup.py sdist upload

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Python Simple Settings
2+
======================
3+
[![Code Issues](http://www.quantifiedcode.com/api/v1/project/1b5307f0f1584c3b9c736f976b57e973/badge.svg)](http://www.quantifiedcode.com/app/project/1b5307f0f1584c3b9c736f976b57e973)
4+
[![Build Status](https://travis-ci.org/drgarcia1986/simple-settings.svg)](https://travis-ci.org/drgarcia1986/simple-settings)
5+
[![Coverage Status](https://coveralls.io/repos/drgarcia1986/simple-settings/badge.svg)](https://coveralls.io/r/drgarcia1986/simple-settings)
6+
7+
A simple way to manage your project settings.
8+
9+
With `simple_settings` you just need specify your settings module in `--settings` arg (of command line or enviroment) and all will be available in `simple_settings.settings`.
10+
11+
For example:
12+
```
13+
$ python app.py --settings=project_settings
14+
```

examples/tornado/__init__.py

Whitespace-only changes.

examples/tornado/app.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# -*- coding: utf-8 -*-
2+
from tornado.web import Application, RequestHandler
3+
from tornado.httpserver import HTTPServer
4+
from tornado.ioloop import IOLoop
5+
6+
from simple_settings import settings
7+
8+
9+
class ConfigHandler(RequestHandler):
10+
def get(self):
11+
self.finish({
12+
'example_foo': settings.EXAMPLE_FOO,
13+
'example_bar': settings.EXAMPLE_BAR
14+
})
15+
16+
17+
if __name__ == '__main__':
18+
app = Application(
19+
handles=[(r'/', ConfigHandler)],
20+
debug=settings.DEBUG
21+
)
22+
server = HTTPServer(app)
23+
server.listen(settings.PORT)
24+
IOLoop.instance().start()

examples/tornado/settings/__init__.py

Whitespace-only changes.

examples/tornado/settings/base.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# -*- coding: utf-8 -*-
2+
3+
DEBUG = True
4+
PORT = 8080
5+
6+
EXAMPLE_FOO = 'foo'
7+
EXAMPLE_BAR = 'bar'
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# -*- coding: utf-8 -*-
2+
3+
PORT = 8000
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# -*- coding: utf-8 -*-
2+
3+
DEBUG = False
4+
PORT = 8000
5+
6+
EXAMPLE_FOO = 'foo production'
7+
EXAMPLE_BAR = 'bar production'

requirements-dev.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cov-core==1.15.0
2+
coverage==3.7.1
3+
mock==1.0.1
4+
py==1.4.27
5+
pytest==2.7.0
6+
pytest-cov==1.8.1
7+
bumpversion==0.5.1

setup.py

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# -*- coding: utf-8 -*-
2+
import os
3+
from setuptools import setup
4+
5+
6+
def read(fname):
7+
""" Return file content. """
8+
9+
return open(
10+
os.path.join(
11+
os.path.dirname(__file__), fname)
12+
).read()
13+
14+
15+
def get_packages(package):
16+
""" Return root package and all sub-packages. """
17+
18+
return [dirpath
19+
for dirpath, dirnames, filenames in os.walk(package)
20+
if os.path.exists(os.path.join(dirpath, '__init__.py'))]
21+
22+
23+
def get_package_data(package):
24+
"""
25+
Return all files under the root package,
26+
that are not in a package themselves.
27+
"""
28+
29+
walk = [(dirpath.replace(package + os.sep, '', 1), filenames)
30+
for dirpath, dirnames, filenames in os.walk(package)
31+
if not os.path.exists(os.path.join(dirpath, '__init__.py'))]
32+
33+
filepaths = []
34+
for base, filenames in walk:
35+
filepaths.extend([os.path.join(base, filename)
36+
for filename in filenames])
37+
return {package: filepaths}
38+
39+
setup(
40+
name='simple-settings',
41+
version='0.2.0',
42+
install_requires=[],
43+
url='https://github.com/drgarcia1986/simple-settings',
44+
author='Diego Garcia',
45+
author_email='drgarcia1986@gmail.com',
46+
keywords='django flask bottle tornado settings configuration conf',
47+
description='A simple way to manage your project settings',
48+
long_description=read('README.md'),
49+
packages=get_packages('simple_settings'),
50+
packages_data=get_package_data('simple_settings'),
51+
classifiers=[
52+
'Intended Audience :: Developers',
53+
'License :: OSI Approved :: MIT License',
54+
'Operating System :: OS Independent',
55+
'Programming Language :: Python :: 2',
56+
'Programming Language :: Python :: 3',
57+
]
58+
)

simple_settings/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# -*- coding: utf-8 -*-
2+
from .core import settings # noqa

simple_settings/core.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -*- coding: utf-8 -*-
2+
import argparse
3+
import importlib
4+
import os
5+
6+
7+
class _Settings(object):
8+
def __init__(self):
9+
self._dict = {}
10+
self._setup()
11+
12+
def _setup(self):
13+
self._settings_module = self._get_settings_from_cmd_line()
14+
if not self._settings_module:
15+
self._settings_module = os.environ.get('settings')
16+
if not self._settings_module:
17+
raise RuntimeError('Settings are not configured')
18+
self._load_settings_module(self._settings_module)
19+
20+
def _get_settings_from_cmd_line(self):
21+
parser = argparse.ArgumentParser()
22+
parser.add_argument('--settings', action='store', default='')
23+
return parser.parse_args().settings
24+
25+
def _load_settings_module(self, settings_module):
26+
module = importlib.import_module(settings_module)
27+
for setting in dir(module):
28+
value = os.environ.get(setting, getattr(module, setting))
29+
self._dict[setting] = value
30+
31+
def __getattr__(self, attr):
32+
return self._dict[attr]
33+
34+
def as_dict(self):
35+
return self._dict.copy()
36+
37+
38+
settings = _Settings()

tests/__init__.py

Whitespace-only changes.

tests/samples/__init__.py

Whitespace-only changes.

tests/samples/base.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# -*- coding: utf-8 -*-
2+
3+
APPLICATION_NAME = u'Simple Settings'

tests/samples/complex.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# -*- coding: utf-8 -*-
2+
from tests.samples.base import * # noqa
3+
4+
5+
COMPLEX_DICT = {
6+
'complex': 'settings',
7+
'foo': 'bar'
8+
}

tests/samples/simple.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# -*- coding: utf-8 -*-
2+
from tests.samples.base import * # noqa
3+
4+
5+
SIMPLE_STRING = u'simple'
6+
SIMPLE_INTEGER = 1

0 commit comments

Comments
 (0)