Skip to content

Commit

Permalink
Raise error when invalid requirements are parsed
Browse files Browse the repository at this point in the history
Fixes: ansible#364

Signed-off-by: Abhijeet Kasurde <[email protected]>
  • Loading branch information
Akasurde committed Aug 15, 2023
1 parent eb7d8f1 commit d991218
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ansible_builder/_target_scripts/introspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@ def sanitize_requirements(collection_py_reqs):
consolidated.append(req)
seen_pkgs.add(req.name)
except Exception as e:
logger.warning('Warning: failed to parse requirements from %s, error: %s', collection, e)
logger.error('Failed to parse requirements from %s, error: %s', collection, e)
sys.exit(1)

# removal of unwanted packages
sanitized = []
Expand Down
6 changes: 6 additions & 0 deletions test/unit/test_introspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,9 @@ def test_parse_args_default_action():
assert parser.user_bindep == user_bindep
assert parser.write_pip == write_pip
assert parser.write_bindep == write_bindep


def test_corrupt_python_requirements():
with pytest.raises(SystemExit) as excinfo:
sanitize_requirements({'test.metadata': ['invalid_package=1']})
assert excinfo.value.code == 1

0 comments on commit d991218

Please sign in to comment.