Skip to content

Commit

Permalink
Rely on toml conditionally
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sigmavirus24 committed Jan 27, 2022
1 parent 25fde24 commit 18e9164
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions bandit/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,12 +36,13 @@ def __init__(self, config_file=None):
try:
f = open(config_file)
except OSError:
raise utils.ConfigError(
"Could not read config file.", config_file
)
raise utils.ConfigError("Could not read config file.", config_file)

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:
Expand Down

0 comments on commit 18e9164

Please sign in to comment.