From 17093cbd8cf0f2eda2271c7066fe4455e0d388b8 Mon Sep 17 00:00:00 2001 From: Gyanu Mayank Date: Wed, 2 Sep 2026 08:12:16 +0530 Subject: [PATCH] Accept export KEY=value lines in .env files. docker-compose and python-dotenv both treat a leading export as optional syntax. We were storing the key as "export KEY". --- decouple.py | 4 ++++ tests/test_env.py | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/decouple.py b/decouple.py index 9873fc9..8331330 100644 --- a/decouple.py +++ b/decouple.py @@ -152,6 +152,10 @@ def __init__(self, source, encoding=DEFAULT_ENCODING): line = line.strip() if not line or line.startswith('#') or '=' not in line: continue + if line.startswith('export ') or line.startswith('export\t'): + line = line[7:].lstrip() + if not line or '=' not in line: + continue k, v = line.split('=', 1) k = k.strip() v = v.strip() diff --git a/tests/test_env.py b/tests/test_env.py index a91c95c..1b4ffe5 100644 --- a/tests/test_env.py +++ b/tests/test_env.py @@ -49,6 +49,8 @@ KeyHasTwoDoubleQuote='"Y"' KeyHasMixedQuotesAsData1="Y' KeyHasMixedQuotesAsData2='Y" +export ExportedKey=fromexport +export ExportedTab=tabs ''' @pytest.fixture(scope='module') @@ -140,3 +142,8 @@ def test_env_with_quote(config): def test_env_repo_keyerror(config): with pytest.raises(KeyError): config.repository['UndefinedKey'] + + +def test_env_export_prefix(config): + assert 'fromexport' == config('ExportedKey') + assert 'tabs' == config('ExportedTab')