pre-commitpre-commit.compyproject.tomlbanditbandit-python

pyproject.toml : toml parser not available, reinstall with toml extra


I am configuring my pyproject.toml so that bandit excludes the test files but it gives me the error ERROR pyproject.toml : toml parser not available, reinstall with toml extra

this is my pyproject.toml

[tool.bandit]
exclude_dirs = ["*/test/*"]
tests = ["B201", "B301"]
skips = ["B101", "B601"]

[tool.pre-commit-hooks.bandit]
exclude = ["test*"]

And I run the following command: bandit -c pyproject.toml -r .


Solution

  • I solved the problem by adding to my requirements.txt bandit[toml]==1.7.4 to get it to work

    bandit[toml]==1.7.4
    

    and if you are working with pre-commit:

    -   repo:  https://github.com/PyCQA/bandit
        rev: 1.7.4
        hooks:
        -   id: bandit
            args: ["-c", "pyproject.toml"]
            additional_dependencies: [".[toml]"]