#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ # @Version : Python 3.11.4 # @Software : Sublime Text 4 # @Author : StudentCWZ # @Email : StudentCWZ@outlook.com # @Date : 2023/11/21 10:51 # @File : init_dotenv.py # @Description : Initializes the dotenv extension for the application. """ # Import standard library modules import os # Import third-party library modules from dotenv import load_dotenv def init_dotenv() -> None: """ Initialize the dotenv extension. 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)