def push_env(c, file='.env'): """Push .env key/value pairs to heroku""" from honcho.environ import parse with open(file, 'r') as f: env = parse(f.read()) cmd = 'heroku config:set ' + ' '.join(f'{key}={value}' for key, value in env.items()) c.run(cmd)
def _read_env(app_root, env): files = [e.strip() for e in env.split(',')] content = [] for envfile in files: try: with open(os.path.join(app_root, envfile)) as f: content.append(f.read()) except IOError: pass return environ.parse('\n'.join(content))
def _read_env(procfile_path, env): app_root = os.path.dirname(procfile_path) files = [e.strip() for e in env.split(",")] content = [] for envfile in files: try: with open(os.path.join(app_root, envfile)) as f: content.append(f.read()) except IOError: pass return environ.parse("\n".join(content))
def update_env(filename='.env'): """ Update os.environ with variables from an .env file. Parameters: filename (Optional[str]): the name of the .env file. Defaults to '.env'. """ with open(filename) as f: content = f.read() envvars = environ.parse(content) for k, v in envvars.items(): os.environ[k] = v
def test_environ_parse(content, commands): content = textwrap.dedent(content) result = environ.parse(content) assert result == commands
def test_environ_parse(self): for content, commands in ENVFILE_FIXTURES: content = textwrap.dedent(content) result = environ.parse(content) self.assertEqual(result, commands)
def test_environ_parse(): for content, commands in FIXTURES: content = textwrap.dedent(content) result = environ.parse(content) yield assert_equal, result, commands