Skip to content
Browse files

Make env.local to be automatically loaded

Closes #80
  • Loading branch information...
jaywink committed Jan 7, 2017
1 parent a32da6f commit 9c363d2b1a9c576f3f9bf1a6a5ee7695c83d10ac
Showing with 6 additions and 27 deletions.
  1. +1 −7
  2. +5 −0 config/settings/
  3. +0 −20
@@ -56,16 +56,12 @@ The file `requirements.apt` contains other various dependencies. You can use the

#### Configure

Configuration is done via environment variables. For the meaning of them, look them up under files in `config/settings`.
Configuration is done via environment variables. For the meaning of them, look them up under files in `config/settings`. Values in `env_local` will be used automatically.

cp env.example env.local

Edit any values necessary. By default the `SECRET_KEY` is empty. You MUST set something to it. We don't supply a default to force you to make it unique in your production app.

When running `` commands, these environment variables will be automatically loaded. For other usage (like `py.test`), load the environment in your shell with:

export `cat env.local`

#### Create a database

If you changed the `DATABASE_URL` in the settings file, make sure to change the values in these commands accordingly.
@@ -98,8 +94,6 @@ You should now be able to log in as the user `admin`.

### Running tests

Export your settings to the shell first.

#### Python tests

@@ -10,12 +10,17 @@
from __future__ import absolute_import, unicode_literals

import os

import environ

ROOT_DIR = environ.Path(__file__) - 3 # (/a/b/ - 3 = /)
APPS_DIR = ROOT_DIR.path('socialhome')

# Local environment
# -----------------
env = environ.Env()

# ------------------------------------------------------------------------------
@@ -1,29 +1,9 @@
#!/usr/bin/env python
import os
import sys
import warnings

if __name__ == "__main__":
# Load environment variables from env.local.
# Good for injecting environment into PyCharm run configurations for example and no need to
# manually load the env values for commands
with open("env.local") as envfile:
for line in envfile:
if line.strip():
setting = line.strip().split("=", maxsplit=1)
os.environ.setdefault(setting[0], setting[1])
# Backwards compatibility, since we used to require this and Django will freak out if here
# TODO: Remove in some future date
if "--load-env" in sys.argv:
warnings.warn("Argument '--load-env' has been deprecated and will be removed in the future.")
except FileNotFoundError:
warnings.warn("Config file 'env.local' is missing. It should be created from 'env.example' with "
"necessary values replaced.")

# Fail safe settings module
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local")

from import execute_from_command_line

0 comments on commit 9c363d2

Please sign in to comment.
You can’t perform that action at this time.