Skip to content

Cannot override default path for venv #5

Description

@Prototyped

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]:.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions