Skip to content

Commit

Permalink
adding capabilities for environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
toumorokoshi committed Feb 23, 2015
1 parent 0c7355f commit e6cc2fe
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 1 deletion.
15 changes: 15 additions & 0 deletions docs/envs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
====
Envs
====

The envs section can be used to set environment variables within the
Uranium sandbox.

envs should be a dictionary of <environment variable, value> pairs. These
Will be set as environment variables for the execution of both the Uranium run,
and also for any entry-points generated as well.

.. code-block:: yaml
envs:
AUTH_URL: 'http://example.com/auth'
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Contents:
tutorial
config
eggs
envs
indexes
inheritance
versions
Expand Down
3 changes: 2 additions & 1 deletion uranium/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from ..part import Part
from .develop_eggs import DevelopEggs
from .eggs import Eggs
from .envs import Envs
from .indexes import Indexes
from .parts import Parts
from .phases import Phases
Expand All @@ -14,7 +15,7 @@


class Config(ResolveDict,
DevelopEggs, Eggs, Indexes,
DevelopEggs, Eggs, Envs, Indexes,
Parts, Phases, Versions):
"""
The config object that store configuration.
Expand Down
19 changes: 19 additions & 0 deletions uranium/config/envs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from .utils import assert_condition, dict_types

KEY = "envs"


class Envs(object):

def _initialize(self):
self[KEY] = self.get(KEY, {})

def _validate(self, warnings, errors):
assert_condition(
errors, isinstance(self[KEY], dict_types),
"envs must be a dict! found {0} instead.".format(type(self[KEY]))
)

@property
def envs(self):
return self[KEY]
18 changes: 18 additions & 0 deletions uranium/tests/config/test_envs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from uranium.config import Config
from uranium.tests.utils import get_valid_config
from nose.tools import eq_


class TestEnvs(object):

def setUp(self):
config = get_valid_config()
self.config_dict = config
self.config = Config(config)

def test_non_dict(self):
self.config['envs'] = [
'ENV_VAR = "foo"'
]
warnings, errors = self.config.validate()
eq_(len(errors), 1)
8 changes: 8 additions & 0 deletions uranium/tests/test_uranium.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class TestUranium(object):
def setUp(self):
self.root = tempfile.mkdtemp()
self.config = Config({
'envs': {
'foo': 'bar'
},
'phases': {
'before-eggs': 'platform-versions'
},
Expand Down Expand Up @@ -38,3 +41,8 @@ def test_root_property(self):
def test_parts_directory_property(self):
eq_(self.uranium.parts_directory,
os.path.join(self.root, 'parts'))

def test_environment_inherits_from_config(self):
eq_(self.uranium.environment, {
'foo': 'bar'
})
1 change: 1 addition & 0 deletions uranium/uranium.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def __init__(self, config, root, state_file=None):
self._plugin_runner = PluginRunner(self, self._classloader)
self._state = State(state_file)
self._environment = {}
self._environment.update(config.envs)
self._validate_config()

@property
Expand Down

0 comments on commit e6cc2fe

Please sign in to comment.