Skip to content
Myr

Merge pull request #3560 from greyli/fix-env-chdir

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

Stop change CWD to .env/.flaskenv location

authored by Joshua Bronson · committed by GitHub · parents 65a0a4b, e403e9e · Browse files · 3 files+4 added−8 removed
This commit

State

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

Diff stats

3 files+4 added−8 removed

  • tests:+1 added−1 removed
  • other:+3 added−7 removed

3 files+4 added−8 removed

modified:src/flask/cli.py-7 removed
608 unmodified lines
609610 If an env var is already set it is not overwritten, so earlier files in the611 list are preferred over later files.612613 Changes the current working directory to the location of the first file614 found, with the assumption that it is in the top level project directory615 and will be where the Python path should import local packages from.616613 This is a no-op if `python-dotenv`_ is not installed.614615 .. _python-dotenv: https://github.com/theskumar/python-dotenv#readme616
37 unmodified lines
654 new_dir = os.path.dirname(path)655656 dotenv.load_dotenv(path)657662 if new_dir and os.getcwd() != new_dir:663 os.chdir(new_dir)664658 return new_dir is not None # at least one file was located and loaded659660661def show_server_banner(env, debug, app_import_path, eager_loading):
303 unmodified lines
modified:tests/test_cli.py+1 added-1 removed
502 unmodified lines
503 for item in ("FOO", "BAR", "SPAM"):504 monkeypatch._setitem.append((os.environ, item, notset))505506 monkeypatch.setenv("EGGS", "3")507 monkeypatch.chdir(os.path.join(test_path, "cliapp", "inner1"))507 monkeypatch.chdir(test_path)508 assert load_dotenv()509 assert os.getcwd() == test_path510 # .flaskenv doesn't overwrite .env511 assert os.environ["FOO"] == "env"
145 unmodified lines
modified:CHANGES.rst+3 added
25 unmodified lines
26- When using ad-hoc certificates, check for the cryptography library27 instead of PyOpenSSL. :pr:`3492`28- When specifying a factory function with ``FLASK_APP``, keyword29 argument can be passed. :issue:`3553`30- When loading a ``.env`` or ``.flaskenv`` file on top level directory,31 Flask will not change current work directory to the location of dotenv32 files, in order to prevent potential confusion. :pr:`3560`333435Version 1.1.x36-------------
1020 unmodified lines