Skip to content
Myr

rename to FLASK_SKIP_DOTENV, add docs, test

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Lord · committed by David Lord · parent bac5d6b · Browse files · 4 files+50 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+50 added−7 removed

  • tests:+8 added−0 removed
  • other:+42 added−7 removed

4 files+50 added−7 removed

modified:docs/cli.rst+24 added
199 unmodified lines
200These can be added to the ``.flaskenv`` file just like ``FLASK_APP`` to201control default command options.202203204Disable dotenv205~~~~~~~~~~~~~~206207The ``flask`` command will show a message if it detects dotenv files but208python-dotenv is not installed.209210.. code-block:: none211212 flask run213 * Tip: There are .env files present. Do "pip install python-dotenv" to use them.214215You can tell Flask not to load dotenv files even when python-dotenv is216installed by setting the ``FLASK_SKIP_DOTENV`` environment variable.217This can be useful if you want to load them manually, or if you're using218a project runner that loads them already. Keep in mind that the219environment variables must be set before the app loads or it won't220configure as expected.221222.. code-block:: none223224 export FLASK_SKIP_DOTENV=1225 flask run226227228Environment Variables From virtualenv229-------------------------------------230231If you do not want to install dotenv support, you can still set environment
235 unmodified lines
modified:flask/cli.py+3 added-7 removed
26 unmodified lines
2728from . import __version__29from ._compat import getargspec, iteritems, reraise, text_type30from .globals import current_app31from .helpers import get_debug_flag, get_env31from .helpers import get_debug_flag, get_env, get_load_dotenv3233try:34 import dotenv35except ImportError:
507 unmodified lines
543 # call into a no-op. This is necessary to avoid ugly errors when the544 # script that is loaded here also attempts to start a server.545 os.environ['FLASK_RUN_FROM_CLI'] = 'true'546547 val = os.environ.get('FLASK_DONT_LOAD_ENV')548 load_dotenv = not val or val in ('0', 'false', 'no')549550 if self.load_dotenv and load_dotenv:547 if get_load_dotenv(self.load_dotenv):548 load_dotenv()549550 obj = kwargs.get('obj')551
30 unmodified lines
582 :return: ``True`` if a file was loaded.583584 .. versionadded:: 1.0585 """589586 if dotenv is None:587 if path or os.path.exists('.env') or os.path.exists('.flaskenv'):588 click.secho(589 ' * Tip: There are .env files present.'594 ' Do "pip install python-dotenv" to use them',590 ' Do "pip install python-dotenv" to use them.',591 fg='yellow')592 return593594 if path is not None:
300 unmodified lines
modified:flask/helpers.py+15 added
66 unmodified lines
6768 return val.lower() not in ('0', 'false', 'no')697071def get_load_dotenv(default=True):72 """Get whether the user has disabled loading dotenv files by setting73 :envvar:`FLASK_SKIP_DOTENV`. The default is ``True``, load the74 files.7576 :param default: What to return if the env var isn't set.77 """78 val = os.environ.get('FLASK_SKIP_DOTENV')7980 if not val:81 return default8283 return val.lower() in ('0', 'false', 'no')848586def _endpoint_from_view_func(view_func):87 """Internal helper that returns the default endpoint for a given88 function. This always is the function name.89 """
955 unmodified lines
modified:tests/test_cli.py+8 added
472 unmodified lines
473 load_dotenv()474 assert 'FOO' not in os.environ475476477@need_dotenv478def test_disable_dotenv_from_env(monkeypatch, runner):479 monkeypatch.chdir(test_path)480 monkeypatch.setitem(os.environ, 'FLASK_SKIP_DOTENV', '1')481 runner.invoke(FlaskGroup())482 assert 'FOO' not in os.environ483484485def test_run_cert_path():486 # no key487 with pytest.raises(click.BadParameter):488 run_command.make_context('run', ['--cert', __file__])
53 unmodified lines