def read_dotenv(dotenv=None, override=False):
    """
    Read a .env file into os.environ.

    If not given a path to a dotenv path, does filthy magic stack backtracking
    to find manage.py and then find the dotenv.

    If tests rely on .env files, setting the overwrite flag to True is a safe
    way to ensure tests run consistently across all environments.

    :param override: True if values in .env should override system variables.
    """
    if dotenv is None:
        frame_filename = sys._getframe().f_back.f_code.co_filename
        dotenv = os.path.join(os.path.dirname(frame_filename), '.env')

    if os.path.isdir(dotenv) and os.path.isfile(os.path.join(dotenv, '.env')):
        dotenv = os.path.join(dotenv, '.env')

    if os.path.exists(dotenv):
        with open(dotenv) as f:
            for k, v in parse_dotenv(f.read()).items():
                if override:
                    os.environ[k] = v
                else:
                    os.environ.setdefault(k, v)
    else:
        warnings.warn("Not reading {0} - it doesn't exist.".format(dotenv),
                      stacklevel=2)
def read_dotenv ( dotenv = None , override = False ) : if dotenv is None : frame_filename = sys . _getframe ( ) . f_back . f_code . co_filename dotenv = os . path . join ( os . path . dirname ( frame_filename ) , '.env' ) if os . path . isdir ( dotenv ) and os . path . isfile ( os . path . join ( dotenv , '.env' ) ) : dotenv = os . path . join ( dotenv , '.env' ) if os . path . exists ( dotenv ) : with open ( dotenv ) as f : for k , v in parse_dotenv ( f . read ( ) ) . items ( ) : if override : os . environ [ k ] = v else : os . environ . setdefault ( k , v ) else : warnings . warn ( "Not reading {0} - it doesn't exist." . format ( dotenv ) , stacklevel = 2 )
Read a .env file into os.environ.

    If not given a path to a dotenv path, does filthy magic stack backtracking
    to find manage.py and then find the dotenv.

    If tests rely on .env files, setting the overwrite flag to True is a safe
    way to ensure tests run consistently across all environments.

    :param override: True if values in .env should override system variables.