commit
0f58526bd3
@ -0,0 +1,35 @@ |
||||
#!/usr/bin/env python |
||||
# -*- coding: utf-8 -*- |
||||
"""Post gen hook to ensure that the generated project |
||||
hase only one package managment, either pipenv or pip.""" |
||||
import os |
||||
import shutil |
||||
import sys |
||||
|
||||
|
||||
def clean_extra_package_managment_files(): |
||||
"""Removes either requirements files and folderor the Pipfile.""" |
||||
use_pipenv = '{{cookiecutter.use_pipenv}}' |
||||
to_delete = [] |
||||
|
||||
if use_pipenv == 'yes': |
||||
to_delete = to_delete + ['requirements.txt', 'requirements'] |
||||
else: |
||||
to_delete.append('Pipfile') |
||||
|
||||
try: |
||||
for file_or_dir in to_delete: |
||||
if os.path.isfile(file_or_dir): |
||||
os.remove(file_or_dir) |
||||
else: |
||||
shutil.rmtree(file_or_dir) |
||||
sys.exit(0) |
||||
except OSError as e: |
||||
sys.stdout.write( |
||||
'While attempting to remove file(s) an error occurred' |
||||
) |
||||
sys.stdout.write('Error: {}'.format(e)) |
||||
|
||||
|
||||
if __name__ == '__main__': |
||||
clean_extra_package_managment_files() |
@ -0,0 +1,5 @@ |
||||
# Environment variable overrides for local development |
||||
FLASK_APP=autoapp.py |
||||
FLASK_ENV=development |
||||
DATABASE_URL="sqlite:////tmp/dev.db" |
||||
SECRET_KEY="not-so-secret" |
@ -0,0 +1,60 @@ |
||||
[[source]] |
||||
url = "https://pypi.python.org/simple" |
||||
verify_ssl = true |
||||
name = "pypi" |
||||
|
||||
[packages] |
||||
# Flask |
||||
Flask = "==1.0.2" |
||||
MarkupSafe = "==1.0" |
||||
Werkzeug = "==0.14.1" |
||||
Jinja2 = "==2.10" |
||||
itsdangerous = "==0.24" |
||||
click = ">=5.0" |
||||
|
||||
# Database |
||||
Flask-SQLAlchemy = "==2.3.2" |
||||
psycopg2 = "==2.7.5" |
||||
SQLAlchemy = "==1.2.8" |
||||
|
||||
# Migrations |
||||
Flask-Migrate = "==2.2.0" |
||||
|
||||
# Forms |
||||
Flask-WTF = "==0.14.2" |
||||
WTForms = "==2.2.1" |
||||
|
||||
# Deployment |
||||
gunicorn = ">=19.1.1" |
||||
|
||||
# Webpack |
||||
flask-webpack = "==0.1.0" |
||||
|
||||
# Auth |
||||
Flask-Login = "==0.4.1" |
||||
Flask-Bcrypt = "==0.7.1" |
||||
|
||||
# Caching |
||||
Flask-Caching = ">=1.0.0" |
||||
|
||||
# Debug toolbar |
||||
Flask-DebugToolbar = "==0.10.1" |
||||
|
||||
# Environment variable parsing |
||||
environs = "==4.0.0" |
||||
|
||||
[dev-packages] |
||||
# Testing |
||||
pytest = "==3.6.1" |
||||
WebTest = "==2.0.30" |
||||
factory-boy = "==2.11.*" |
||||
|
||||
# Lint and code style |
||||
flake8 = "==3.5.0" |
||||
flake8-blind-except = "==0.1.1" |
||||
flake8-debugger = "==3.1.0" |
||||
flake8-docstrings = "==1.3.0" |
||||
flake8-isort = "==2.5" |
||||
flake8-quotes = "==1.0.0" |
||||
isort = "==4.3.4" |
||||
pep8-naming = "==0.7.0" |
@ -1,10 +1,5 @@ |
||||
# -*- coding: utf-8 -*- |
||||
"""Create an application instance.""" |
||||
from flask.helpers import get_debug_flag |
||||
|
||||
from {{cookiecutter.app_name}}.app import create_app |
||||
from {{cookiecutter.app_name}}.settings import DevConfig, ProdConfig |
||||
|
||||
CONFIG = DevConfig if get_debug_flag() else ProdConfig |
||||
|
||||
app = create_app(CONFIG) |
||||
app = create_app() |
||||
|
@ -0,0 +1,11 @@ |
||||
"""Settings module for test app.""" |
||||
ENV = 'development' |
||||
TESTING = True |
||||
SQLALCHEMY_DATABASE_URI = 'sqlite://' |
||||
SECRET_KEY = 'not-so-secret-in-tests' |
||||
BCRYPT_LOG_ROUNDS = 4 # For faster tests; needs at least 4 to avoid "ValueError: Invalid rounds" |
||||
DEBUG_TB_ENABLED = False |
||||
CACHE_TYPE = 'simple' # Can be "memcached", "redis", etc. |
||||
SQLALCHEMY_TRACK_MODIFICATIONS = False |
||||
WEBPACK_MANIFEST_PATH = 'webpack/manifest.json' |
||||
WTF_CSRF_ENABLED = False # Allows form testing |
@ -1,19 +0,0 @@ |
||||
# -*- coding: utf-8 -*- |
||||
"""Test configs.""" |
||||
from {{cookiecutter.app_name}}.app import create_app |
||||
from {{cookiecutter.app_name}}.settings import DevConfig, ProdConfig |
||||
|
||||
|
||||
def test_production_config(): |
||||
"""Production config.""" |
||||
app = create_app(ProdConfig) |
||||
assert app.config['ENV'] == 'prod' |
||||
assert app.config['DEBUG'] is False |
||||
assert app.config['DEBUG_TB_ENABLED'] is False |
||||
|
||||
|
||||
def test_dev_config(): |
||||
"""Development config.""" |
||||
app = create_app(DevConfig) |
||||
assert app.config['ENV'] == 'dev' |
||||
assert app.config['DEBUG'] is True |
@ -1,49 +1,23 @@ |
||||
# -*- coding: utf-8 -*- |
||||
"""Application configuration.""" |
||||
import os |
||||
|
||||
|
||||
class Config(object): |
||||
"""Base configuration.""" |
||||
|
||||
SECRET_KEY = os.environ.get('{{cookiecutter.app_name | upper}}_SECRET', 'secret-key') # TODO: Change me |
||||
APP_DIR = os.path.abspath(os.path.dirname(__file__)) # This directory |
||||
PROJECT_ROOT = os.path.abspath(os.path.join(APP_DIR, os.pardir)) |
||||
BCRYPT_LOG_ROUNDS = 13 |
||||
DEBUG_TB_ENABLED = False # Disable Debug toolbar |
||||
DEBUG_TB_INTERCEPT_REDIRECTS = False |
||||
CACHE_TYPE = 'simple' # Can be "memcached", "redis", etc. |
||||
SQLALCHEMY_TRACK_MODIFICATIONS = False |
||||
WEBPACK_MANIFEST_PATH = 'webpack/manifest.json' |
||||
|
||||
|
||||
class ProdConfig(Config): |
||||
"""Production configuration.""" |
||||
|
||||
ENV = 'prod' |
||||
DEBUG = False |
||||
SQLALCHEMY_DATABASE_URI = 'postgresql://localhost/example' # TODO: Change me |
||||
DEBUG_TB_ENABLED = False # Disable Debug toolbar |
||||
|
||||
|
||||
class DevConfig(Config): |
||||
"""Development configuration.""" |
||||
|
||||
ENV = 'dev' |
||||
DEBUG = True |
||||
DB_NAME = 'dev.db' |
||||
# Put the db file in project root |
||||
DB_PATH = os.path.join(Config.PROJECT_ROOT, DB_NAME) |
||||
SQLALCHEMY_DATABASE_URI = 'sqlite:///{0}'.format(DB_PATH) |
||||
DEBUG_TB_ENABLED = True |
||||
CACHE_TYPE = 'simple' # Can be "memcached", "redis", etc. |
||||
|
||||
|
||||
class TestConfig(Config): |
||||
"""Test configuration.""" |
||||
|
||||
TESTING = True |
||||
DEBUG = True |
||||
SQLALCHEMY_DATABASE_URI = 'sqlite://' |
||||
BCRYPT_LOG_ROUNDS = 4 # For faster tests; needs at least 4 to avoid "ValueError: Invalid rounds" |
||||
WTF_CSRF_ENABLED = False # Allows form testing |
||||
"""Application configuration. |
||||
|
||||
Most configuration is set via environment variables. |
||||
|
||||
For local development, use a .env file to set |
||||
environment variables. |
||||
""" |
||||
from environs import Env |
||||
|
||||
env = Env() |
||||
env.read_env() |
||||
|
||||
ENV = env.str('FLASK_ENV', default='production') |
||||
DEBUG = ENV == 'development' |
||||
SQLALCHEMY_DATABASE_URI = env.str('DATABASE_URL') |
||||
SECRET_KEY = env.str('SECRET_KEY') |
||||
BCRYPT_LOG_ROUNDS = env.int('BCRYPT_LOG_ROUNDS', default=13) |
||||
DEBUG_TB_ENABLED = DEBUG |
||||
DEBUG_TB_INTERCEPT_REDIRECTS = False |
||||
CACHE_TYPE = 'simple' # Can be "memcached", "redis", etc. |
||||
SQLALCHEMY_TRACK_MODIFICATIONS = False |
||||
WEBPACK_MANIFEST_PATH = 'webpack/manifest.json' |
||||
|
Loading…
Reference in new issue