Skip to content

Commit 22c75a8

Browse files
authored
Rework GitPython dependency to be an extra for bandit-baseline (#1099)
The only piece of code that requires GitPython is bandit-baseline. There tends to be an abundance of CVEs in the GitPython library due to its dependency on Git. By making GitPython optional via an extra, users who mostly use just the bandit command line and not bandit-baseline can benefit. However, this will require different install if a user wants to use bandit-baseline. This is now noted in the Getting Started doc, but you simply do: pip install bandit[GitPython] FYI, this option was suggested in PR #976. #976 Signed-off-by: Eric Brown <[email protected]>
1 parent 12e14f6 commit 22c75a8

File tree

6 files changed

+22
-4
lines changed

6 files changed

+22
-4
lines changed

bandit/cli/baseline.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
import sys
2020
import tempfile
2121

22-
import git
22+
try:
23+
import git
24+
except ImportError:
25+
git = None
2326

2427
bandit_args = sys.argv[1:]
2528
baseline_tmp_file = "_bandit_baseline_run.json_"
@@ -198,6 +201,11 @@ def initialize():
198201
report_fname = f"{report_basename}.{output_format}"
199202

200203
# #################### Check Requirements #################################
204+
if git is None:
205+
LOG.error("Git not available, reinstall with baseline extra")
206+
valid = False
207+
return (None, None, None)
208+
201209
try:
202210
repo = git.Repo(os.getcwd())
203211

doc/source/start.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ If you want to include TOML support, install it with the `toml` extras:
3131
3232
pip install bandit[toml]
3333
34+
If you want to use the bandit-baseline CLI, install it with the `baseline`
35+
extras:
36+
37+
.. code-block:: console
38+
39+
pip install bandit[baseline]
40+
3441
Run Bandit:
3542

3643
.. code-block:: console

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# The order of packages is significant, because pip processes them in the order
22
# of appearance. Changing the order has an impact on the overall integration
33
# process, which may cause wedges in the gate later.
4-
GitPython>=3.1.30 # BSD License (3 clause)
54
PyYAML>=5.3.1 # MIT
65
stevedore>=1.20.0 # Apache-2.0
76
colorama>=0.3.9;platform_system=="Windows" # BSD License (3 clause)

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ yaml =
3535
PyYAML
3636
toml =
3737
tomli>=1.1.0; python_version < "3.11"
38+
baseline =
39+
GitPython>=3.1.30
3840

3941
[entry_points]
4042
console_scripts =

test-requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ flake8>=4.0.0 # Apache-2.0
77
stestr>=2.5.0 # Apache-2.0
88
testscenarios>=0.5.0 # Apache-2.0/BSD
99
testtools>=2.3.0 # MIT
10-
tomli>=1.1.0;python_version<"3.11" # MIT
1110
beautifulsoup4>=4.8.0 # MIT
1211
pylint==1.9.4 # GPLv2

tox.ini

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ setenv =
1010
deps =
1111
-r{toxinidir}/requirements.txt
1212
-r{toxinidir}/test-requirements.txt
13+
extras =
14+
yaml
15+
toml
16+
baseline
1317
commands =
1418
find bandit -type f -name "*.pyc" -delete
1519
stestr run {posargs}
@@ -34,7 +38,6 @@ commands = flake8 {posargs} bandit
3438
bandit-baseline -r bandit -ll -ii
3539

3640
[testenv:pep8]
37-
skip_install = true
3841
ignore_errors = true
3942
deps = {[testenv]deps}
4043
.

0 commit comments

Comments
 (0)