Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support line breaks and comments in .env file #339

Merged
merged 1 commit into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"