Skip to content

Commit

Permalink
Merge pull request #339 from pratyushmittal/main
Browse files Browse the repository at this point in the history
Support line breaks and comments in .env file
  • Loading branch information
sergeyklay committed Oct 19, 2021
2 parents d3f4b01 + 96b5804 commit 8a2adfa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions environ/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,9 @@ def _keep_escaped_format_characters(match):
val = re.sub(r'\\(.)', _keep_escaped_format_characters,
m3.group(1))
overrides[key] = str(val)
elif not line or line.startswith('#'):
# ignore warnings for empty line-breaks or comments
pass
else:
logger.warning('Invalid line: %s', line)

Expand Down
10 changes: 10 additions & 0 deletions tests/test_env.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
DICT_VAR=foo=bar,test=on

# Database variables
DATABASE_MYSQL_URL=mysql://bea6eb0:69772142@us-cdbr-east.cleardb.com/heroku_97681?reconnect=true
DATABASE_MYSQL_CLOUDSQL_URL=mysql://djuser:hidden-password@//cloudsql/arvore-codelab:us-central1:mysqlinstance/mydatabase
DATABASE_MYSQL_GIS_URL=mysqlgis://user:password@127.0.0.1/some_database

# Cache variables
CACHE_URL=memcache://127.0.0.1:11211
CACHE_REDIS=rediscache://127.0.0.1:6379/1?client_class=django_redis.client.DefaultClient&password=secret

# Email variables
EMAIL_URL=smtps://user@domain.com:password@smtp.example.com:587

# Others
URL_VAR=http://www.google.com/
PATH_VAR=/home/dev
BOOL_TRUE_STRING_LIKE_INT='1'
Expand Down Expand Up @@ -45,4 +53,6 @@ DATABASE_ORACLE_TNS_URL=oracle://user:password@sid
DATABASE_ORACLE_URL=oracle://user:password@host:1521/sid
DATABASE_REDSHIFT_URL=redshift://user:password@examplecluster.abc123xyz789.us-west-2.redshift.amazonaws.com:5439/dev
DATABASE_CUSTOM_BACKEND_URL=custom.backend://user:password@example.com:5430/database

# Exports
export EXPORTED_VAR="exported var"

0 comments on commit 8a2adfa

Please sign in to comment.