pedrohdz/py-lambda-packer

Cannot override default path for venv

Opened this issue · 0 comments

Hi,

It looks like there is a bug in merging configuration values from CLI and config file into the defaults. The default configuration has a null path entry:

virtualenv:
  python: python2.7
  path: !!null

and the configuration merging algorithm takes care of several types, but does not take care of None values:

    def _merge_dicts(self, left, right, path=None):
        """
        Merges right into left.  Credit goes to:
            - https://stackoverflow.com/a/7205107/2721824
        """
        if path is None:
            path = []
        for key in right:
            if key in left:
                if (isinstance(left[key], dict)
                        and isinstance(right[key], dict)):
                    self._merge_dicts(left[key], right[key], path + [str(key)])
                elif left[key] == right[key]:
                    # same leaf value
                    pass
                elif (isinstance(left[key], (list, tuple))
                      and isinstance(right[key], (list, tuple))):
                    # TODO - Add unit tests
                    # Let us make a copy to be safe (shallow).
                    left[key] = [item for item in right[key]]
                elif (isinstance(left[key], (str, int, float))
                      and isinstance(right[key], (str, int, float))):
                    # TODO - Add unit tests
                    left[key] = right[key]
                else:
                    raise ValueError('Conflict at : {}'.format(
                        '.'.join(path + [str(key)])))
            else:
                left[key] = right[key]

So if we try to override the virtualenv.path configuration key, we end up with a ValueError being raised.

Please consider replacing the if key in left: conditional to something like if key in left and left[key]:.