Skip to content

Commit c9b204c

Browse files
committed
simplified config take 2
1 parent 020fa23 commit c9b204c

6 files changed

Lines changed: 66 additions & 29 deletions

File tree

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
.idea/workspace.xml
22
venv
3-
test_users.db
4-
users.db
5-
users/config.py
3+
*.db
64
*.py[cod]
75

86
# C extensions

README.md

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,40 @@ User Map
66

77
A simple flask application for creating user community maps.
88

9-
First create a valid ``config.py`` e.g.
9+
By default, this app reads configuration from `users/config.py`.
10+
To override values set in default config, simply copy the contents
11+
of `users/config.py` and save it elsewhere.
1012

11-
```
12-
cp users/config.py.prod users/config.py
13-
```
13+
cp users/config.py /path/to/custom/config.py
14+
15+
Then edit the custom config file, setting appropriate values as needed.
16+
17+
To run in debug mode (which will also serve up static content),
18+
use the `-d` flag:
19+
20+
USERS_CONFIG=/path/to/custom/config.py python runserver.py -d
21+
22+
Each config item is overridable through environment variable.
23+
For instance, if you want to suppress email delivery,
24+
simply set appropriate value:
1425

15-
Then edit the config file, setting appropriate values as needed.
26+
USERS_MAIL_SUPPRESS_SEND=True python runserver
1627

17-
To run in debug mode (which will also serve up static content), use the -d
18-
flag.
28+
To run testcases:
1929

20-
``python runserver.py -d``
30+
USERS_CONFIG=/path/to/custom/config.py MAIL_SUPPRESS_SEND=True ./runtests.sh
2131

32+
Collaboration
33+
-------------
2234

23-
If running under pycharm, remember to edit the run configuration and add the
24-
``-d`` to the parameters.
35+
1. Fork this repo.
36+
2. Create a topic branch in your forked repo and start hacking.
37+
3. Run `runtests.sh`. Ensure all tests passed.
38+
4. Once it done, submit your pull request (PR) against upstream `develop` branch.
39+
5. Our maintainers will review your PR. If it's good — all tests passed and proposed feature is in our roadmap — your PR will be merged.
2540

2641
Deployment using Docker
27-
=======================
42+
-----------------------
2843

2944
If you are using docker, you can create a Docker image for this app easily as
3045
follows:
@@ -46,6 +61,6 @@ wget -O sources.list https://raw.github.com/timlinux/user_map/master/docker/hetz
4661
```
4762

4863
Authors
49-
=======
64+
-------
5065

5166
Tim Sutton and Akbar Gumbira

requirements.txt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
Flask==0.10.1
2-
Jinja2==2.7.1
3-
MarkupSafe==0.18
4-
Werkzeug==0.9.4
5-
itsdangerous==0.23
6-
nose==1.3.0
2+
Flask-Mail==0.9.0
3+
Jinja2==2.7.3
4+
MarkupSafe==0.23
5+
Werkzeug==0.9.6
6+
blinker==1.3
7+
flask-appconfig==0.9.1
8+
itsdangerous==0.24
9+
nose==1.3.3
710
pydns==2.3.6
11+
six==1.7.3
812
validate-email==1.1
913
wsgiref==0.1.2
10-
Flask-mail==0.9.0

runtests.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
#!/bin/bash
2-
source venv/bin/activate
1+
#!/usr/bin/env bash
2+
if [ -f venv/bin/activate ]; then
3+
source venv/bin/activate
4+
fi
5+
36
nosetests -v --with-id users
4-
deactivate
7+
8+
if [ ! -z $(command -v deactivate) ]; then
9+
deactivate
10+
fi

users/__init__.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from flask import Flask
1111
from flask_mail import Mail
12+
from flask.ext.appconfig import AppConfig
1213

1314

1415
def add_handler_once(logger, handler):
@@ -67,11 +68,25 @@ def setup_logger():
6768

6869
APP = Flask(__name__)
6970

70-
# Load configuration from ``users.config``.
71-
# This will raise ``ImportError`` if such module isn't exist.
72-
# Simply copy the contents of ``config.py.example`` file,
73-
# and save it into a file named ``config.py``.
74-
APP.config.from_object("users.config")
71+
#: Load configuration from any possible means.
72+
#: To override default configuration defined in ``users.config``,
73+
#: simply copy the contents of ``config.py`` file,
74+
#: and save it into a file.
75+
#:
76+
#: .. sourcecode:: sh
77+
#:
78+
#: USERS_CONFIG=/path/to/config.py python runserver
79+
#:
80+
#: Another way of doing it is by setting environment variable for each
81+
#: config item.
82+
#:
83+
#: .. sourcecode:: sh
84+
#:
85+
#: USERS_CONFIG=/path/to/config.py USERS_MAIL_SUPPRESS_SEND=True \
86+
#: python runserver
87+
#:
88+
AppConfig(APP, default_settings="users.config")
89+
7590
mail = Mail(APP)
7691

7792
# backward-compat
File renamed without changes.

0 commit comments

Comments
 (0)