Skip to content

Commit

Permalink
Resolve #45 - configure project name from the config file.
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Nephin <dnephin@gmail.com>
  • Loading branch information
dnephin committed Sep 2, 2014
1 parent 6dab8c1 commit 6067ff4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
14 changes: 10 additions & 4 deletions fig/project.py
Expand Up @@ -64,13 +64,19 @@ def from_dicts(cls, name, service_dicts, client):

@classmethod
def from_config(cls, name, config, client):
dicts = []
services = []
project_config = config.pop('.project', {})
name = project_config.get('name', name)

for service_name, service in list(config.items()):
if not isinstance(service, dict):
raise ConfigurationError('Service "%s" doesn\'t have any configuration options. All top level keys in your fig.yml must map to a dictionary of configuration options.')
raise ConfigurationError(
'Service "%s" doesn\'t have any configuration options. '
'All top level keys in your fig.yml must map to a '
'dictionary of configuration options.')
service['name'] = service_name
dicts.append(service)
return cls.from_dicts(name, dicts, client)
services.append(service)
return cls.from_dicts(name, services, client)

def get_service(self, name):
"""
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/project_test.py
Expand Up @@ -65,6 +65,15 @@ def test_from_config_throws_error_when_not_dict(self):
'web': 'busybox:latest',
}, None)

def test_from_config_with_project_config(self):
project_name = 'theprojectnamefromconfig'
project = Project.from_config('default_name_not_used', {
'.project': {'name': project_name},
'web': {'image': 'busybox:latest'}
}, None)

self.assertEqual(project.name, project_name)

def test_get_service(self):
web = Service(
project='figtest',
Expand Down

0 comments on commit 6067ff4

Please sign in to comment.