Commits

jacobmason committed e0c2cb4

use environment variable for settings

Comments (0)

Files changed (6)

sphinxdemo/__init__.py

 from flask import Flask, g, session
 
-from sphinxdemo import conf
-from sphinxdemo.views.demo import demo
-from sphinxdemo.views.auth import auth
-from sphinxdemo.models import db_session, User
-
 app = Flask(__name__)
 
-app.config.update(
-    DATABASE_URI = conf.DATABASE_URI,
-    SECRET_KEY = conf.SECRET_KEY,
-)
+app.config.from_envvar('SPHINXDEMO_SETTINGS')
+
+from sphinxdemo.models import db_session, User
 
 @app.before_request
 def before_request():
     db_session.remove()
     return response
 
+from sphinxdemo.views.demo import demo
+from sphinxdemo.views.auth import auth
 app.register_module(demo)
 app.register_module(auth)
+from flask import Flask
+
+app = Flask(__name__)
+
+app.config.from_envvar('SPHINXDEMO_SETTINGS')
 
 from sphinx.websupport import WebSupport
 
-from sphinxdemo import conf
 from sphinxdemo.models import init_db
 
 init_db()
 
-support = WebSupport(srcdir=conf.SOURCE_DIR,
-                     builddir=conf.BUILD_DIR,
-                     search=conf.SEARCH,
-                     storage=conf.DATABASE_URI)
+support = WebSupport(srcdir=app.config['SOURCE_DIR'],
+                     builddir=app.config['BUILD_DIR'],
+                     search=app.config['SEARCH'],
+                     storage=app.config['DATABASE_URI'])
 support.build()

sphinxdemo/conf.py

-
-DEBUG = True
-
-SOURCE_DIR = ''
-BUILD_DIR = ''
-DATABASE_URI = ''
-SECRET_KEY = ''
-SEARCH = ''
 from sqlalchemy.orm import scoped_session, sessionmaker
 from sqlalchemy.ext.declarative import declarative_base
 
-from sphinxdemo import conf
+from sphinxdemo import app
 
 # setup sqlalchemy
-engine = create_engine(conf.DATABASE_URI)
+engine = create_engine(app.config['DATABASE_URI'])
 db_session = scoped_session(sessionmaker(autocommit=False,
                                          autoflush=False,
                                          bind=engine))

sphinxdemo/runserver.py

-from sphinxdemo import app, conf
-app.run(debug=conf.DEBUG)
+from sphinxdemo import app
+app.run()

sphinxdemo/views/demo.py

      redirect, url_for, abort, jsonify
 from sphinx.websupport import WebSupport
 from sphinx.websupport.errors import *
+from sphinxdemo import app
+demo = Module(__name__)
 
-from sphinxdemo import conf
-
-support = WebSupport(datadir=path.join(conf.BUILD_DIR, 'data'),
-                     search=conf.SEARCH,
+support = WebSupport(datadir=path.join(app.config['BUILD_DIR'], 'data'),
+                     search=app.config['SEARCH'],
                      docroot='docs',
-                     storage=conf.DATABASE_URI)
-
-demo = Module(__name__)
+                     storage=app.config['DATABASE_URI'])
 
 @demo.route('/docs/')
 def docs():