__init__.py 1.87 KB
Newer Older
Weizhi Cui's avatar
Weizhi Cui committed
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
# @Version     : Python 3.11.4
# @Software    : Sublime Text 4
# @Author      : StudentCWZ
# @Email       : StudentCWZ@outlook.com
# @Date        : 2023/10/28 12:50
# @File        : __init__.py
# @Description :
"""


崔为之's avatar
崔为之 committed
14
from flask import Flask
崔为之's avatar
崔为之 committed
15

崔为之's avatar
崔为之 committed
16
# Import the initialization functions in alphabetical order
崔为之's avatar
崔为之 committed
17 18
from .init_apispec import init_apispec
from .init_apscheduler import init_tasks
Weizhi Cui's avatar
Weizhi Cui committed
19
from .init_config import init_config
崔为之's avatar
崔为之 committed
20
from .init_consul import init_consul
崔为之's avatar
崔为之 committed
21
from .init_cors import init_cors
崔为之's avatar
崔为之 committed
22
from .init_dotenv import init_dotenv
崔为之's avatar
崔为之 committed
23
from .init_elasticsearch import init_elasticsearch
Weizhi Cui's avatar
Weizhi Cui committed
24 25 26
from .init_logger import init_logger
from .init_sqlalchemy import init_database

崔为之's avatar
崔为之 committed
27

Weizhi Cui's avatar
Weizhi Cui committed
28
def init_plugs(app: Flask) -> None:
崔为之's avatar
崔为之 committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42
    """
    This function initializes various plugins for a Flask application.

    It accepts a Flask application instance as an argument, and calls a series of initialization
    functions on this instance, setting up several plugins.

    Each plugin is initialized by a function imported from a separate module. These initialization
    functions should take the Flask application instance as an argument, and set up the plugin for
    this instance.

    Note that the order in which these plugins are initialized can be important, as some plugins may
    depend on others being already initialized.
    """
    # Initialize the environment variables
崔为之's avatar
崔为之 committed
43
    init_dotenv()
崔为之's avatar
崔为之 committed
44 45

    # Initialize the application configuration
Weizhi Cui's avatar
Weizhi Cui committed
46
    init_config(app)
崔为之's avatar
崔为之 committed
47 48

    # Initialize the application logging
Weizhi Cui's avatar
Weizhi Cui committed
49
    init_logger(app)
崔为之's avatar
崔为之 committed
50 51

    # Initialize the database connection
Weizhi Cui's avatar
Weizhi Cui committed
52
    init_database(app)
崔为之's avatar
崔为之 committed
53 54

    # Initialize the API specification
Weizhi Cui's avatar
Weizhi Cui committed
55
    init_apispec(app)
崔为之's avatar
崔为之 committed
56 57

    # Initialize the Elasticsearch client
崔为之's avatar
崔为之 committed
58
    init_elasticsearch(app)
崔为之's avatar
崔为之 committed
59 60

    # Initialize the CORS policy
崔为之's avatar
崔为之 committed
61
    init_cors(app)
崔为之's avatar
崔为之 committed
62 63

    # Initialize the Consul client
崔为之's avatar
崔为之 committed
64
    init_consul(app)
崔为之's avatar
崔为之 committed
65 66

    # Initialize the scheduled tasks
崔为之's avatar
崔为之 committed
67
    init_tasks(app)