From e62acde3629dc247a919fa60ddef1d3875c5d9b9 Mon Sep 17 00:00:00 2001 From: Gregory Hellings Date: Sat, 6 Mar 2021 23:40:25 -0600 Subject: [PATCH] Allow environments to have existing deps Honor existing deps in configured environments by adding the auto-configured dependencies to existing ones rather than by replacing them Fixes #74 --- README.md | 6 ++++-- src/tox_ansible/tox_helper.py | 5 ++++- tests/fixtures/has_deps/galaxy.yml | 3 +++ tests/fixtures/has_deps/molecule/one/molecule.yml | 0 tests/fixtures/has_deps/molecule/two/molecule.yml | 0 .../roles/simple/molecule/default/converge.yml | 4 ++++ .../roles/simple/molecule/default/molecule.yml | 5 +++++ tests/fixtures/has_deps/roles/simple/tasks/main.yml | 2 ++ tests/fixtures/has_deps/tox.ini | 13 +++++++++++++ tests/test_everything.py | 10 ++++++++++ 10 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 tests/fixtures/has_deps/galaxy.yml create mode 100644 tests/fixtures/has_deps/molecule/one/molecule.yml create mode 100644 tests/fixtures/has_deps/molecule/two/molecule.yml create mode 100644 tests/fixtures/has_deps/roles/simple/molecule/default/converge.yml create mode 100644 tests/fixtures/has_deps/roles/simple/molecule/default/molecule.yml create mode 100644 tests/fixtures/has_deps/roles/simple/tasks/main.yml create mode 100644 tests/fixtures/has_deps/tox.ini diff --git a/README.md b/README.md index 26d84f1..45875fe 100644 --- a/README.md +++ b/README.md @@ -52,9 +52,11 @@ of the two options. Of course, tox can still be used to execute only one environ name directly via e.g. `tox -e roles-myrole-scenario`. If an environment already exists that matches the generated environment name, then this plugin -will not settings specified directly in the tox.ini for that environment. Thus, if you need to customize +will not override settings specified directly in the tox.ini for that environment. Thus, if you need to customize a particular run, then you can do so, but still take advantage of the filtering options and -auto-generation of the environments for other scenarios and options. +auto-generation of the environments for other scenarios and options. Dependencies defined in the standard +way in tox.ini for any name collision environments will be augmented with the ones needed for +running Molecule and lint. Configuration ============= diff --git a/src/tox_ansible/tox_helper.py b/src/tox_ansible/tox_helper.py index 729ffdc..47132f8 100644 --- a/src/tox_ansible/tox_helper.py +++ b/src/tox_ansible/tox_helper.py @@ -112,7 +112,10 @@ def customize_envconfig(self, config, options): config.commands = tox_case.get_commands(options) # Default deps to install molecule, etc do = DepOption() - config.deps = do.postprocess(config, tox_case.get_dependencies()) + processed_deps = do.postprocess(config, tox_case.get_dependencies()) + if config.deps: + processed_deps = config.deps + processed_deps + config.deps = processed_deps # Cannot run in {toxinidir}, which is default if not config.envdir or config.envdir == self.config.toxinidir: config.envdir = self.config.toxworkdir.join("ansible") diff --git a/tests/fixtures/has_deps/galaxy.yml b/tests/fixtures/has_deps/galaxy.yml new file mode 100644 index 0000000..613cfec --- /dev/null +++ b/tests/fixtures/has_deps/galaxy.yml @@ -0,0 +1,3 @@ +namespace: example +name: foo +version: 0.0.1 diff --git a/tests/fixtures/has_deps/molecule/one/molecule.yml b/tests/fixtures/has_deps/molecule/one/molecule.yml new file mode 100644 index 0000000..e69de29 diff --git a/tests/fixtures/has_deps/molecule/two/molecule.yml b/tests/fixtures/has_deps/molecule/two/molecule.yml new file mode 100644 index 0000000..e69de29 diff --git a/tests/fixtures/has_deps/roles/simple/molecule/default/converge.yml b/tests/fixtures/has_deps/roles/simple/molecule/default/converge.yml new file mode 100644 index 0000000..99fcfef --- /dev/null +++ b/tests/fixtures/has_deps/roles/simple/molecule/default/converge.yml @@ -0,0 +1,4 @@ +- name: test + hosts: all + roles: + - simple diff --git a/tests/fixtures/has_deps/roles/simple/molecule/default/molecule.yml b/tests/fixtures/has_deps/roles/simple/molecule/default/molecule.yml new file mode 100644 index 0000000..dffef1c --- /dev/null +++ b/tests/fixtures/has_deps/roles/simple/molecule/default/molecule.yml @@ -0,0 +1,5 @@ +driver: + name: podman +platforms: + - name: simple + image: fedora:latest diff --git a/tests/fixtures/has_deps/roles/simple/tasks/main.yml b/tests/fixtures/has_deps/roles/simple/tasks/main.yml new file mode 100644 index 0000000..133237d --- /dev/null +++ b/tests/fixtures/has_deps/roles/simple/tasks/main.yml @@ -0,0 +1,2 @@ +- name: say hello + debug: msg='tox-ansible is the best' diff --git a/tests/fixtures/has_deps/tox.ini b/tests/fixtures/has_deps/tox.ini new file mode 100644 index 0000000..e55ef3f --- /dev/null +++ b/tests/fixtures/has_deps/tox.ini @@ -0,0 +1,13 @@ +[tox] +skipdist = true +envlist = lint_all + +[testenv] +usedevelop = false +skip_install = true +deps = + otherdep + +[testenv:lint_all] +deps = + notadep==1 diff --git a/tests/test_everything.py b/tests/test_everything.py index 8732026..0f69f10 100644 --- a/tests/test_everything.py +++ b/tests/test_everything.py @@ -109,6 +109,16 @@ def test_run_tox(directory, capfd): assert out == EXPECTED[directory] +def test_tox_ini_deps_preserved(capfd): + with cd("tests/fixtures/has_deps"): + lint_out = run_tox(["--showconfig", "-e", "lint_all"], capfd) + simple_out = run_tox(["--showconfig", "-e", "roles-simple-default"], capfd) + deps = [m for m in lint_out.split("\n") if m.startswith("deps = ")][0] + assert "notadep==1" in deps + deps = [m for m in simple_out.split("\n") if m.startswith("deps = ")][0] + assert "otherdep" in deps + + @pytest.mark.parametrize( "target,value", [("scenario", "default"), ("driver", "openstack")],