Merge pull request #3560 from greyli/fix-env-chdir
Stop change CWD to .env/.flaskenv location
This commit is contained in:
commit
a40c381ffd
3 changed files with 4 additions and 8 deletions
|
|
@ -27,6 +27,9 @@ Unreleased
|
|||
instead of PyOpenSSL. :pr:`3492`
|
||||
- When specifying a factory function with ``FLASK_APP``, keyword
|
||||
argument can be passed. :issue:`3553`
|
||||
- When loading a ``.env`` or ``.flaskenv`` file on top level directory,
|
||||
Flask will not change current work directory to the location of dotenv
|
||||
files, in order to prevent potential confusion. :pr:`3560`
|
||||
|
||||
|
||||
Version 1.1.x
|
||||
|
|
|
|||
|
|
@ -610,10 +610,6 @@ def load_dotenv(path=None):
|
|||
If an env var is already set it is not overwritten, so earlier files in the
|
||||
list are preferred over later files.
|
||||
|
||||
Changes the current working directory to the location of the first file
|
||||
found, with the assumption that it is in the top level project directory
|
||||
and will be where the Python path should import local packages from.
|
||||
|
||||
This is a no-op if `python-dotenv`_ is not installed.
|
||||
|
||||
.. _python-dotenv: https://github.com/theskumar/python-dotenv#readme
|
||||
|
|
@ -659,9 +655,6 @@ def load_dotenv(path=None):
|
|||
|
||||
dotenv.load_dotenv(path)
|
||||
|
||||
if new_dir and os.getcwd() != new_dir:
|
||||
os.chdir(new_dir)
|
||||
|
||||
return new_dir is not None # at least one file was located and loaded
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -504,7 +504,7 @@ def test_load_dotenv(monkeypatch):
|
|||
monkeypatch._setitem.append((os.environ, item, notset))
|
||||
|
||||
monkeypatch.setenv("EGGS", "3")
|
||||
monkeypatch.chdir(os.path.join(test_path, "cliapp", "inner1"))
|
||||
monkeypatch.chdir(test_path)
|
||||
assert load_dotenv()
|
||||
assert os.getcwd() == test_path
|
||||
# .flaskenv doesn't overwrite .env
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue