Skip to content

Commit 17093cb

Browse files
committed
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".
1 parent 0573e6f commit 17093cb

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

‎decouple.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ def __init__(self, source, encoding=DEFAULT_ENCODING):
152152
line = line.strip()
153153
if not line or line.startswith('#') or '=' not in line:
154154
continue
155+
if line.startswith('export ') or line.startswith('export\t'):
156+
line = line[7:].lstrip()
157+
if not line or '=' not in line:
158+
continue
155159
k, v = line.split('=', 1)
156160
k = k.strip()
157161
v = v.strip()

‎tests/test_env.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
KeyHasTwoDoubleQuote='"Y"'
5050
KeyHasMixedQuotesAsData1="Y'
5151
KeyHasMixedQuotesAsData2='Y"
52+
export ExportedKey=fromexport
53+
export ExportedTab=tabs
5254
'''
5355

5456
@pytest.fixture(scope='module')
@@ -140,3 +142,8 @@ def test_env_with_quote(config):
140142
def test_env_repo_keyerror(config):
141143
with pytest.raises(KeyError):
142144
config.repository['UndefinedKey']
145+
146+
147+
def test_env_export_prefix(config):
148+
assert 'fromexport' == config('ExportedKey')
149+
assert 'tabs' == config('ExportedTab')

0 commit comments

Comments
 (0)