MCPcopy Create free account
hub / github.com/pallets/quart / load_dotenv

Function load_dotenv

src/quart/cli.py:576–617  ·  view source on GitHub ↗

Load "dotenv" files in order of precedence to set environment variables. If an env var is already set it is not overwritten, so earlier files in the list are preferred over later files. This is a no-op if `python-dotenv`_ is not installed. .. _python-dotenv: https://github.com/thesku

(path: str | os.PathLike | None = None)

Source from the content-addressed store, hash-verified

574
575
576def load_dotenv(path: str | os.PathLike | None = None) -> bool:
577 """Load "dotenv" files in order of precedence to set environment variables.
578 If an env var is already set it is not overwritten, so earlier files in the
579 list are preferred over later files.
580 This is a no-op if `python-dotenv`_ is not installed.
581 .. _python-dotenv: https://github.com/theskumar/python-dotenv#readme
582 :param path: Load the file at this location instead of searching.
583 :return: ``True`` if a file was loaded.
584 """
585 try:
586 import dotenv
587 except ImportError:
588 if path or os.path.isfile(".env") or os.path.isfile(".quartenv"):
589 click.secho(
590 " * Tip: There are .env or .quartenv files present."
591 ' Do "pip install python-dotenv" to use them.',
592 fg="yellow",
593 err=True,
594 )
595
596 return False
597
598 # Always return after attempting to load a given path, don't load
599 # the default files.
600 if path is not None:
601 if os.path.isfile(path):
602 return dotenv.load_dotenv(path, encoding="utf-8")
603
604 return False
605
606 loaded = False
607
608 for name in (".env", ".quartenv"):
609 path = dotenv.find_dotenv(name, usecwd=True)
610
611 if not path:
612 continue
613
614 dotenv.load_dotenv(path, encoding="utf-8")
615 loaded = True
616
617 return loaded # True if at least one file was located and loaded.
618
619
620@click.command("run", short_help="Run a development server.")

Callers 5

test_load_dotenvFunction · 0.90
test_load_dotquartenvFunction · 0.90
_env_file_callbackFunction · 0.85
make_contextMethod · 0.85

Calls

no outgoing calls

Tested by 3

test_load_dotenvFunction · 0.72
test_load_dotquartenvFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…