diff --git a/.gitignore b/.gitignore index 9f11b755a1..868324859a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ .idea/ +.ycm_extra_conf.py +__pycache__ + +.env diff --git a/README.md b/README.md index 4daea481f0..8f6e729023 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,15 @@ ### Geting started +- Create .env base on .env.example + - Install Miniconda first - `conda create --name vec_engine python=3.6` - `conda activate vec_engine` - `conda install faiss-gpu cuda90 -c pytorch # For CUDA9.0` - `conda install flask` - - `pip install flask-restful flask_sqlalchemy` + - `pip install flask-restful flask_sqlalchemy flask_script` + - `pip install pymysql environs` ### Create Database diff --git a/pyengine/engine/.env.example b/pyengine/engine/.env.example new file mode 100644 index 0000000000..045f6903be --- /dev/null +++ b/pyengine/engine/.env.example @@ -0,0 +1,7 @@ +DEBUG=True +SQLALCHEMY_TRACK_MODIFICATIONS=False +SECRET_KEY=test +SQLALCHEMY_DATABASE_URI=mysql+pymysql://vecwise@127.0.0.1:3306/vecdata + +ROW_LIMIT=10000000 +DATABASE_DIRECTORY=/tmp diff --git a/pyengine/engine/__init__.py b/pyengine/engine/__init__.py index 0be56e1c60..bb9718e89b 100644 --- a/pyengine/engine/__init__.py +++ b/pyengine/engine/__init__.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- +from engine import settings from flask import Flask from flask_sqlalchemy import SQLAlchemy -print ("Load paramters") app = Flask(__name__) -app.config.from_object('engine.settings') +app.config.from_object(settings) #创建数据库对象 print ("Create database instance") diff --git a/pyengine/engine/settings.py b/pyengine/engine/settings.py index 428deffc19..8b9e1e06a8 100644 --- a/pyengine/engine/settings.py +++ b/pyengine/engine/settings.py @@ -1,9 +1,12 @@ -# _*_ coding: utf-8 _*_ +from environs import Env -DEBUG = True -SQLALCHEMY_TRACK_MODIFICATIONS = False -# SECRET_KEY='A0Zr98j/3yX R~XHH!jmN]LWX/,?RT' -SQLALCHEMY_DATABASE_URI = "mysql+pymysql://vecwise@127.0.0.1:3306/vecdata" +env = Env() +env.read_env() -ROW_LIMIT = 1000000 -DATABASE_DIRECTORY = '/tmp' \ No newline at end of file +DEBUG = env.bool('DEBUG', default=False) +SQLALCHEMY_TRACK_MODIFICATIONS = env.bool('DEBUG', default=False) +SECRET_KEY = env.str('SECRET_KEY', 'test') +SQLALCHEMY_DATABASE_URI = env.str('SQLALCHEMY_DATABASE_URI') + +ROW_LIMIT = env.int('ROW_LIMIT') +DATABASE_DIRECTORY = env.str('DATABASE_DIRECTORY') diff --git a/pyengine/manager.py b/pyengine/manager.py new file mode 100644 index 0000000000..da1b0a248c --- /dev/null +++ b/pyengine/manager.py @@ -0,0 +1,21 @@ +from flask_script import Manager + +from engine import db, app + +manager = Manager(app) + +@manager.command +def create_all(): + db.create_all() + +@manager.command +def drop_all(): + db.drop_all() + +@manager.command +def recreate_all(): + db.drop_all() + db.create_all() + +if __name__ == '__main__': + manager.run()