Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot override default path for venv #5

Open
Prototyped opened this issue Dec 23, 2019 · 0 comments
Open

Cannot override default path for venv #5

Prototyped opened this issue Dec 23, 2019 · 0 comments

Comments

@Prototyped
Copy link

Prototyped commented Dec 23, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant