Skip to content

Commit 7fbf9d5

Browse files
authored
Use versioned links to docs (#819)
In the report of a Bandit run, there are links to the docs as part of the more information. Today, these links are always to the latest docs. So depending on the version of Bandit you're running, these links could contain inaccurate information for that version. That's why this change makes it so a specific version of Bandit is pinned to refer to a specific version of documentation. Signed-off-by: Eric Brown <[email protected]>
1 parent 4a18a92 commit 7fbf9d5

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

bandit/core/docs_utils.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
# Copyright 2016 Hewlett-Packard Development Company, L.P.
33
#
44
# SPDX-License-Identifier: Apache-2.0
5-
# where our docs are hosted
6-
BASE_URL = "https://bandit.readthedocs.io/en/latest/"
5+
import bandit
76

87

98
def get_url(bid):
9+
# where our docs are hosted
10+
base_url = f"https://bandit.readthedocs.io/en/{bandit.__version__}/"
11+
1012
# NOTE(tkelsey): for some reason this import can't be found when stevedore
1113
# loads up the formatter plugin that imports this file. It is available
1214
# later though.
@@ -15,7 +17,7 @@ def get_url(bid):
1517
info = extension_loader.MANAGER.plugins_by_id.get(bid)
1618
if info is not None:
1719
return "{}plugins/{}_{}.html".format(
18-
BASE_URL,
20+
base_url,
1921
bid.lower(),
2022
info.plugin.__name__,
2123
)
@@ -51,6 +53,6 @@ def get_url(bid):
5153
kind="imports", id=info["id"], name=info["name"]
5254
)
5355

54-
return BASE_URL + ext.lower()
56+
return base_url + ext.lower()
5557

56-
return BASE_URL # no idea, give the docs main page
58+
return base_url # no idea, give the docs main page

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description_file =
55
README.rst
66
author = PyCQA
77
author_email = [email protected]
8-
home_page = https://bandit.readthedocs.io/en/latest/
8+
home_page = https://bandit.readthedocs.io/
99
license = Apache-2.0 license
1010
classifier =
1111
Development Status :: 5 - Production/Stable

tests/unit/core/test_docs_util.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,28 @@
33
# SPDX-License-Identifier: Apache-2.0
44
import testtools
55

6-
from bandit.core.docs_utils import BASE_URL
6+
import bandit
77
from bandit.core.docs_utils import get_url
88

99

1010
class DocsUtilTests(testtools.TestCase):
1111
"""This set of tests exercises bandit.core.docs_util functions."""
1212

13+
BASE_URL = f"https://bandit.readthedocs.io/en/{bandit.__version__}/"
14+
1315
def test_overwrite_bib_info(self):
14-
expected_url = BASE_URL + (
16+
expected_url = self.BASE_URL + (
1517
"blacklists/blacklist_calls.html" "#b304-b305-ciphers-and-modes"
1618
)
1719
self.assertEqual(get_url("B304"), get_url("B305"))
1820
self.assertEqual(expected_url, get_url("B304"))
1921

2022
def test_plugin_call_bib(self):
21-
expected_url = BASE_URL + "plugins/b101_assert_used.html"
23+
expected_url = self.BASE_URL + "plugins/b101_assert_used.html"
2224
self.assertEqual(expected_url, get_url("B101"))
2325

2426
def test_import_call_bib(self):
25-
expected_url = BASE_URL + (
27+
expected_url = self.BASE_URL + (
2628
"blacklists/blacklist_imports.html" "#b413-import-pycrypto"
2729
)
2830
self.assertEqual(expected_url, get_url("B413"))

0 commit comments

Comments
 (0)