Skip to content

Commit

Permalink
Fixed incorrect exception chaining for conflicting dependencies excep…
Browse files Browse the repository at this point in the history
…tion (PR #4577)

# Description

See https://docs.python.org/3/tutorial/errors.html#exception-chaining

closes #4573

# Self Check:

Strike through any lines that are not applicable (`~~line~~`) then check the box

- [ ] Attached issue to pull request
- [ ] Changelog entry
- [ ] Type annotations are present
- [ ] Code is clear and sufficiently documented
- [ ] No (preventable) type errors (check using make mypy or make mypy-diff)
- [ ] Sufficient test cases (reproduces the bug/tests the requested feature)
- [ ] Correct, in line with design
- [ ] End user documentation is included or an issue is created for end-user documentation (add ref to issue here: )

# Reviewer Checklist:

- [ ] Sufficient test cases (reproduces the bug/tests the requested feature)
- [ ] Code is clear and sufficiently documented
- [ ] Correct, in line with design
  • Loading branch information
sanderr authored and inmantaci committed Jul 20, 2022
1 parent 517cb93 commit 7e74376
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
5 changes: 5 additions & 0 deletions changelogs/unreleased/4573-dependency-conflict-type-error.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
description: Fixed incorrect exception chaining for conflicting dependencies exception
change-type: patch
destination-branches:
- iso5
- master
2 changes: 1 addition & 1 deletion src/inmanta/moduletool.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ def install(install_path: str) -> None:
try:
env.process_env.install_from_source([env.LocalPackagePath(path=install_path, editable=editable)])
except env.ConflictingRequirements as e:
raise InvalidModuleException(e)
raise InvalidModuleException("Module installation failed due to conflicting dependencies") from e

module_path: str = os.path.abspath(path) if path is not None else os.getcwd()
module: Module = self.construct_module(None, module_path)
Expand Down
37 changes: 37 additions & 0 deletions tests/moduletool/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,43 @@ def is_installed(name: str, only_editable: bool = False) -> bool:
assert is_installed(python_module_name, False)


@pytest.mark.slowtest
def test_module_install_conflicting_requirements(tmpdir: py.path.local, snippetcompiler_clean, modules_v2_dir: str) -> None:
"""
Verify that the module tool's install command raises an appropriate exception when a module has conflicting dependencies.
"""
# activate snippetcompiler's venv
snippetcompiler_clean.setup_for_snippet("")

module_from_template(
os.path.join(modules_v2_dir, "minimalv2module"),
os.path.join(str(tmpdir), "modone"),
new_name="modone",
new_requirements=[Requirement.parse("lorem~=0.0.1")],
install=True,
)
module_from_template(
os.path.join(modules_v2_dir, "minimalv2module"),
os.path.join(str(tmpdir), "modtwo"),
new_name="modtwo",
new_requirements=[Requirement.parse("lorem~=0.1.0")],
install=True,
)

module_path: str = os.path.join(str(tmpdir), "conflictingdeps")
module_from_template(
os.path.join(modules_v2_dir, "minimalv2module"),
module_path,
new_name="conflictingdeps",
new_requirements=[InmantaModuleRequirement.parse(name) for name in ("modone", "modtwo")],
)

with pytest.raises(module.InvalidModuleException) as exc_info:
run_module_install(module_path, False, True)
assert isinstance(exc_info.value.__cause__, ConflictingRequirements)
assert "caused by:" in exc_info.value.format_trace()


@pytest.mark.parametrize_any("dev", [True, False])
def test_module_install_version(
tmpdir: py.path.local,
Expand Down

0 comments on commit 7e74376

Please sign in to comment.