mirror of https://github.com/docker/compose.git
Show a warning when a variable is unset
Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
This commit is contained in:
parent
8b5bd945d0
commit
ee6ff294a2
|
@ -1,11 +1,13 @@
|
|||
import os
|
||||
from string import Template
|
||||
from collections import defaultdict
|
||||
|
||||
import six
|
||||
|
||||
from .errors import ConfigurationError
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def interpolate_environment_variables(config):
|
||||
return dict(
|
||||
|
@ -59,11 +61,26 @@ def recursive_interpolate(obj):
|
|||
|
||||
def interpolate(string, mapping):
|
||||
try:
|
||||
return Template(string).substitute(defaultdict(lambda: "", mapping))
|
||||
return Template(string).substitute(BlankDefaultDict(mapping))
|
||||
except ValueError:
|
||||
raise InvalidInterpolation(string)
|
||||
|
||||
|
||||
class BlankDefaultDict(dict):
|
||||
def __init__(self, mapping):
|
||||
super(BlankDefaultDict, self).__init__(mapping)
|
||||
|
||||
def __getitem__(self, key):
|
||||
try:
|
||||
return super(BlankDefaultDict, self).__getitem__(key)
|
||||
except KeyError:
|
||||
log.warn(
|
||||
"The {} variable is not set. Substituting a blank string."
|
||||
.format(key)
|
||||
)
|
||||
return ""
|
||||
|
||||
|
||||
class InvalidInterpolation(Exception):
|
||||
def __init__(self, string):
|
||||
self.string = string
|
||||
|
|
Loading…
Reference in New Issue