Injecting os.environ in Environment instance happens outside of init method

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2016-03-22 15:42:30 -07:00
commit 12ad3ff301
5 changed files with 29 additions and 19 deletions

View file

@ -449,12 +449,12 @@ def process_config_file(config_file, environment, service_name=None):
class ServiceExtendsResolver(object):
def __init__(self, service_config, config_file, environment=None, already_seen=None):
def __init__(self, service_config, config_file, environment, already_seen=None):
self.service_config = service_config
self.working_dir = service_config.working_dir
self.already_seen = already_seen or []
self.config_file = config_file
self.environment = environment or Environment()
self.environment = environment
@property
def signature(self):

View file

@ -41,19 +41,22 @@ class Environment(dict):
def __init__(self, *args, **kwargs):
super(Environment, self).__init__(*args, **kwargs)
self.missing_keys = []
self.update(os.environ)
@classmethod
def from_env_file(cls, base_dir):
result = cls()
if base_dir is None:
def _initialize():
result = cls()
if base_dir is None:
return result
env_file_path = os.path.join(base_dir, '.env')
try:
return cls(env_vars_from_file(env_file_path))
except ConfigurationError:
pass
return result
env_file_path = os.path.join(base_dir, '.env')
try:
return cls(env_vars_from_file(env_file_path))
except ConfigurationError:
pass
return result
instance = _initialize()
instance.update(os.environ)
return instance
def __getitem__(self, key):
try: