diff --git a/application/__init__.py b/application/__init__.py index 5086922a4fe769d5112235512c3e69a6e3cc3877..4b51ca50798999b4319e2b2f52ac49dcabfeafc6 100644 --- a/application/__init__.py +++ b/application/__init__.py @@ -44,7 +44,5 @@ def create_app() -> Flask: # This could include data migration scripts, administrative tasks, etc. init_script(app) - print(app.config) - # Return the fully initialized Flask application return app diff --git a/application/extensions/__init__.py b/application/extensions/__init__.py index 29e667b8002c650b6a359a65c773df75fbacee0e..0130c7dc8a91b88256d9ec01e2f2d0402b687d3f 100644 --- a/application/extensions/__init__.py +++ b/application/extensions/__init__.py @@ -13,6 +13,7 @@ from flask import Flask +# Import the initialization functions in alphabetical order from .init_apispec import init_apispec from .init_apscheduler import init_tasks from .init_config import init_config @@ -23,14 +24,43 @@ from .init_elasticsearch import init_elasticsearch from .init_logger import init_logger from .init_sqlalchemy import init_database - def init_plugs(app: Flask) -> None: + """ + 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 init_dotenv() + + # Initialize the application configuration init_config(app) + + # Initialize the application logging init_logger(app) + + # Initialize the database connection init_database(app) + + # Initialize the API specification init_apispec(app) + + # Initialize the Elasticsearch client init_elasticsearch(app) + + # Initialize the CORS policy init_cors(app) + + # Initialize the Consul client init_consul(app) + + # Initialize the scheduled tasks init_tasks(app) diff --git a/application/extensions/init_apscheduler.py b/application/extensions/init_apscheduler.py index 9445c2e554d6a1f9c20d98233a25ace6d9a933b3..f8d2e38414dafee0ef98f8e09a8a425192d3caad 100644 --- a/application/extensions/init_apscheduler.py +++ b/application/extensions/init_apscheduler.py @@ -13,8 +13,8 @@ from apscheduler.triggers.interval import IntervalTrigger from flask import Flask -from application.libs.tasks import task from application.libs.flask_apscheduler import APScheduler +from application.libs.tasks import task scheduler = APScheduler() diff --git a/application/extensions/init_consul.py b/application/extensions/init_consul.py index 0c0dde6e0fd8800a25c2a7cd3c5c504520205984..c12d1b6029b0d4c6f86619922f5e4af679d27980 100644 --- a/application/extensions/init_consul.py +++ b/application/extensions/init_consul.py @@ -10,10 +10,31 @@ # @Description : """ +# Import built-in modules from flask import Flask +# Import custom modules from application.libs import FlaskConsulService def init_consul(app: Flask) -> None: + """ + Initialize the Consul service. + + This function creates an instance of the FlaskConsulService class, passing + the Flask application instance as an argument. This sets up the Consul + service for the Flask application. + + Consul is a service networking solution to automate network configurations, + discover services, and enable secure connectivity across any cloud or runtime. + + Args: + app (Flask): The Flask application instance. + + Returns: + None + """ + # Initialize the FlaskConsulService with the Flask application instance. + # The FlaskConsulService constructor is responsible for setting up + # the Consul service for the Flask application. FlaskConsulService(app) diff --git a/application/extensions/init_dotenv.py b/application/extensions/init_dotenv.py index 9a7b19fc4d919bfcdb4df1bfef052bfb1c8291fc..bef1f585eac1191e77c2c8658ec249b582d9fccc 100644 --- a/application/extensions/init_dotenv.py +++ b/application/extensions/init_dotenv.py @@ -10,18 +10,34 @@ # @Description : """ +# Import standard library modules import os +# Import third-party library modules from dotenv import load_dotenv def init_dotenv() -> None: """ - Initialize the dotenv extension + Initialize the dotenv extension. - :return: None + This function locates the `.flaskenv` file at the root of the project + and loads it into environment variables using the dotenv package. + + The `.flaskenv` file is a convenient place to put configuration variables + that should be set early in the application's life cycle, such as + settings for the Flask command-line interface. + + Returns: + None """ + # Get the root path to the project by removing the 'extensions' + # part from the current file's absolute path root_path = os.path.abspath(os.path.dirname(__file__)).split('extensions')[0] + + # Construct the path to the .flaskenv file flask_env_path = os.path.join(root_path, '.flaskenv') + + # If the .flaskenv file exists, load it into environment variables if os.path.exists(flask_env_path): load_dotenv(flask_env_path)