Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: refactor from ConfigFileFinder to load_config #35

Merged
merged 4 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions flake8_bandit.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
"""Implementation of bandit security testing in Flake8."""
import ast
import configparser
import sys
from functools import lru_cache
from pathlib import Path
from typing import Dict, NamedTuple, Set

import pycodestyle
from flake8.options.config import ConfigFileFinder
from flake8 import utils as stdin_utils

from bandit.core.config import BanditConfig
from bandit.core.meta_ast import BanditMetaAst
from bandit.core.metrics import Metrics
from bandit.core.node_visitor import BanditNodeVisitor
from bandit.core.test_set import BanditTestSet
from flake8 import utils as stdin_utils
from flake8.exceptions import ExecutionError
from flake8.options.config import load_config


__version__ = "3.0.0"
__version__ = "4.0.0"


class Flake8BanditConfig(NamedTuple):
Expand All @@ -34,11 +32,9 @@ def from_config_file(cls) -> "Flake8BanditConfig":
excluded_paths = set()

# populate config from `.bandit` configuration file
ini_file = ConfigFileFinder("bandit", None, None).local_config_files()
config = configparser.ConfigParser()
try:
config.read(ini_file)
bandit_config = {k: v for k, v in config.items("bandit")}
cfg, _ = load_config(".bandit", [])
bandit_config = {k: v for k, v in cfg["bandit"].items()}

# test-set profile
if bandit_config.get("skips"):
Expand Down Expand Up @@ -67,10 +63,8 @@ def from_config_file(cls) -> "Flake8BanditConfig":
path = "." + path
excluded_paths.add(Path(path))

except (configparser.Error, KeyError, TypeError) as e:
except (ExecutionError, KeyError, TypeError) as e:
profile = {}
if str(e) != "No section: 'bandit'":
sys.stderr.write(f"Unable to parse config file: {e}")

return cls(profile, target_paths, excluded_paths)

Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def get_version(fname="flake8_bandit.py"):
VERSION = get_version()

# What packages are required for this module to be executed?
REQUIRED = ["flake8<5", "bandit>=1.7.3"]

REQUIRED = ["flake8>=5.0.0", "bandit>=1.7.3"]

# What packages are optional?
EXTRAS = {
Expand Down