Skip to content

Commit

Permalink
Merge pull request #13 from jokester/simplify-config
Browse files Browse the repository at this point in the history
Simplify config
  • Loading branch information
jokester authored Apr 22, 2024
2 parents 7158d81 + d397144 commit 33bc03c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 8 additions & 7 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
from app.utils.logging import configure_logger, logger

from .apis import register_apis
import app.config as _app_config

app_config = {
k: getattr(_app_config, k)
for k in dir(_app_config) if not k.startswith("_")
}

# 基本路径
APP_PATH = os.path.abspath(os.path.dirname(__file__))
Expand Down Expand Up @@ -77,13 +83,10 @@ def create_or_override_default_admin(app):

def create_app():
app = Flask(__name__)
app.config.from_envvar(
config_path_env
) # 获取配置文件,仅从环境变量读取,均需要配置环境变量
app.config.from_mapping(app_config)
configure_logger(app) # 配置日志记录(放在最前,会被下面调用)

logger.info("-" * 50)
logger.info("使用配置文件: {}".format(os.environ.get(config_path_env)))
# 连接数据库
from app.models import connect_db

Expand Down Expand Up @@ -119,9 +122,7 @@ def init_db(app: Flask):
def create_celery() -> Celery:
# 为celery创建app
app = Flask(__name__)
app.config.from_envvar(
config_path_env
) # 获取配置文件,仅从环境变量读取,均需要配置环境变量
app.config.from_mapping(app_config)
# 通过app配置创建celery实例
created = Celery(
app.name,
Expand Down
2 changes: 2 additions & 0 deletions config.py → app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,5 @@
"Content-Type",
"X-Requested-With",
]
# manga-image-translator worker
MIT_STORAGE_ROOT = env.get("MIT_STORAGE_ROOT", None)

0 comments on commit 33bc03c

Please sign in to comment.