Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User Management backend - Base - Config file #37

Merged
merged 15 commits into from
May 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions edison/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import os

from flask import Flask
from edison.config import get_config_object


# Put app here so the entire app could import it.
app = Flask(__name__)
app.config.from_object(get_config_object(app.config["ENV"]))
basedir = os.path.abspath(os.path.dirname(__file__))
36 changes: 36 additions & 0 deletions edison/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import inspect
import sys


def get_config_object(env_keyword: str):
simzacks marked this conversation as resolved.
Show resolved Hide resolved
"""
Returns the the desired config class path.

The function iterates through a dictionary returned by inspect.
The dictionary contains details about all of the file members.
Its key is the name of the member and value is obj which contains all the details about the member.
The desired config path is being picked by the ENV_KEYWORD field defined in the config class.

Parameters:
env_keyword (str): Should be equals to one of the config classes ENV_KEYWORD field.

Returns:
str: module_name.class_name, which is the full path of the config class.
"""
for name, obj in inspect.getmembers(sys.modules[__name__]):
if issubclass(obj, Config) and obj.ENV_KEYWORD == env_keyword:
return ".".join([obj.__module__, name])
simzacks marked this conversation as resolved.
Show resolved Hide resolved


class Config:
ENV_KEYWORD = ""
DEBUG = False


class ProductionConfig(Config):
ENV_KEYWORD = "production"


class DevelopmentConfig(Config):
ENV_KEYWORD = "development"
DEBUG = True
2 changes: 2 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ sudo apt-get install -y postgresql postgresql-contrib
echo "install requirements"
pip3 install -r /vagrant/requirements.txt

export FLASK_ENV=development

echo "running app.py"
export FLASK_APP=/vagrant/edison/app.py
flask run -h 0.0.0.0 -p $FLASK_PORT >> /vagrant/edison/app.log 2>&1 &