Skip to content

Commit

Permalink
Merge pull request #75 from greg-hellings/honor_existing_deps
Browse files Browse the repository at this point in the history
Allow environments to have existing deps
  • Loading branch information
greg-hellings authored Mar 7, 2021
2 parents 5567ffa + e62acde commit 8a54960
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 3 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
=============
Expand Down
5 changes: 4 additions & 1 deletion src/tox_ansible/tox_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/has_deps/galaxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace: example
name: foo
version: 0.0.1
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- name: test
hosts: all
roles:
- simple
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
driver:
name: podman
platforms:
- name: simple
image: fedora:latest
2 changes: 2 additions & 0 deletions tests/fixtures/has_deps/roles/simple/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- name: say hello
debug: msg='tox-ansible is the best'
13 changes: 13 additions & 0 deletions tests/fixtures/has_deps/tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[tox]
skipdist = true
envlist = lint_all

[testenv]
usedevelop = false
skip_install = true
deps =
otherdep

[testenv:lint_all]
deps =
notadep==1
10 changes: 10 additions & 0 deletions tests/test_everything.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")],
Expand Down

0 comments on commit 8a54960

Please sign in to comment.