Skip to content

Commit

Permalink
Support multiple base configs (#3029)
Browse files Browse the repository at this point in the history
  • Loading branch information
lebauce authored Jan 7, 2021
1 parent 66449fc commit cac1063
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ jobs:
- tox_env: lint
- tox_env: docs
- tox_env: py36
PREFIX: PYTEST_REQPASS=426
PREFIX: PYTEST_REQPASS=427
- tox_env: py37
PREFIX: PYTEST_REQPASS=426
PREFIX: PYTEST_REQPASS=427
- tox_env: py38
PREFIX: PYTEST_REQPASS=426
PREFIX: PYTEST_REQPASS=427
- tox_env: py39
PREFIX: PYTEST_REQPASS=426
PREFIX: PYTEST_REQPASS=427
- tox_env: py36-devel
PREFIX: PYTEST_REQPASS=426
PREFIX: PYTEST_REQPASS=427
- tox_env: py39-devel
PREFIX: PYTEST_REQPASS=426
PREFIX: PYTEST_REQPASS=427
- tox_env: packaging
- tox_env: eco
- tox_env: dockerfile
Expand Down
4 changes: 2 additions & 2 deletions src/molecule/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ def _combine(self, env=os.environ, keep_string=None) -> MutableMapping:
:return: dict
"""
defaults = self._get_defaults()
base_config = self.args.get("base_config")
if base_config and os.path.exists(base_config):
base_configs = filter(os.path.exists, self.args.get("base_config", []))
for base_config in base_configs:
with util.open_file(base_config) as stream:
s = stream.read()
self._preflight(s)
Expand Down
11 changes: 7 additions & 4 deletions src/molecule/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,17 @@ def print_version(ctx, param, value):
@click.option(
"--base-config",
"-c",
default=LOCAL_CONFIG,
multiple=True,
default=[LOCAL_CONFIG],
help=(
"Path to a base config. If provided Molecule will load "
"this config first, and deep merge each scenario's "
"Path to a base config (can be specified multiple times)."
" If provided, Molecule will first load and deep merge the"
" configurations in the specified order,"
" and deep merge each scenario's "
"molecule.yml on top. By default Molecule is looking for "
"'{}' "
"in current VCS repository and if not found it will look "
"in user home. ({})"
"in user home. ({})."
).format(LOCAL_CONFIG_SEARCH, LOCAL_CONFIG),
)
@click.option(
Expand Down
16 changes: 14 additions & 2 deletions src/molecule/test/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,26 @@ def test_get_config(config_instance):


def test_get_config_with_base_config(config_instance):
config_instance.args = {"base_config": "./foo.yml"}
config_instance.args = {"base_config": ["./foo.yml"]}
contents = {"foo": "bar"}
util.write_file(config_instance.args["base_config"], util.safe_dump(contents))
util.write_file(config_instance.args["base_config"][0], util.safe_dump(contents))
result = config_instance._get_config()

assert result["foo"] == "bar"


def test_get_config_with_multiple_base_configs(config_instance):
config_instance.args = {"base_config": ["./foo.yml", "./foo2.yml"]}
contents = {"foo": "bar", "foo2": "bar"}
util.write_file(config_instance.args["base_config"][0], util.safe_dump(contents))
contents = {"foo2": "bar2"}
util.write_file(config_instance.args["base_config"][1], util.safe_dump(contents))
result = config_instance._get_config()

assert result["foo"] == "bar"
assert result["foo2"] == "bar2"


def test_reget_config(config_instance):
assert isinstance(config_instance._reget_config(), dict)

Expand Down

0 comments on commit cac1063

Please sign in to comment.