From 676036054885677cd040ac920d49e1aaa9b77c91 Mon Sep 17 00:00:00 2001 From: Ian Stapleton Cordasco Date: Thu, 27 Jan 2022 07:47:37 -0600 Subject: [PATCH] Rely on toml conditionally We only want to rely on toml when it's present and tell the user how to resolve things if in fact they want to use toml Closes #779 --- bandit/core/config.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bandit/core/config.py b/bandit/core/config.py index 7dbf0a8bb..cdbc8069d 100644 --- a/bandit/core/config.py +++ b/bandit/core/config.py @@ -6,6 +6,11 @@ import yaml +try: + import toml +except ImportError: + toml = None + from bandit.core import constants from bandit.core import extension_loader from bandit.core import utils @@ -36,7 +41,10 @@ def __init__(self, config_file=None): ) if config_file.endswith(".toml"): - import toml + if toml is None: + raise utils.ConfigError( + "toml parser not available, reinstall with toml extra" + ) try: with f: