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

Use versioned links to docs #819

Merged
merged 1 commit into from Feb 22, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions bandit/core/docs_utils.py
Expand Up @@ -2,11 +2,13 @@
# Copyright 2016 Hewlett-Packard Development Company, L.P.
#
# SPDX-License-Identifier: Apache-2.0
# where our docs are hosted
BASE_URL = "https://bandit.readthedocs.io/en/latest/"
import bandit


def get_url(bid):
# where our docs are hosted
base_url = f"https://bandit.readthedocs.io/en/{bandit.__version__}/"

# NOTE(tkelsey): for some reason this import can't be found when stevedore
# loads up the formatter plugin that imports this file. It is available
# later though.
Expand All @@ -15,7 +17,7 @@ def get_url(bid):
info = extension_loader.MANAGER.plugins_by_id.get(bid)
if info is not None:
return "{}plugins/{}_{}.html".format(
BASE_URL,
base_url,
bid.lower(),
info.plugin.__name__,
)
Expand Down Expand Up @@ -51,6 +53,6 @@ def get_url(bid):
kind="imports", id=info["id"], name=info["name"]
)

return BASE_URL + ext.lower()
return base_url + ext.lower()

return BASE_URL # no idea, give the docs main page
return base_url # no idea, give the docs main page
2 changes: 1 addition & 1 deletion setup.cfg
Expand Up @@ -5,7 +5,7 @@ description_file =
README.rst
author = PyCQA
author_email = code-quality@python.org
home_page = https://bandit.readthedocs.io/en/latest/
home_page = https://bandit.readthedocs.io/
license = Apache-2.0 license
classifier =
Development Status :: 5 - Production/Stable
Expand Down
10 changes: 6 additions & 4 deletions tests/unit/core/test_docs_util.py
Expand Up @@ -3,26 +3,28 @@
# SPDX-License-Identifier: Apache-2.0
import testtools

from bandit.core.docs_utils import BASE_URL
import bandit
from bandit.core.docs_utils import get_url


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

BASE_URL = f"https://bandit.readthedocs.io/en/{bandit.__version__}/"

def test_overwrite_bib_info(self):
expected_url = BASE_URL + (
expected_url = self.BASE_URL + (
"blacklists/blacklist_calls.html" "#b304-b305-ciphers-and-modes"
)
self.assertEqual(get_url("B304"), get_url("B305"))
self.assertEqual(expected_url, get_url("B304"))

def test_plugin_call_bib(self):
expected_url = BASE_URL + "plugins/b101_assert_used.html"
expected_url = self.BASE_URL + "plugins/b101_assert_used.html"
self.assertEqual(expected_url, get_url("B101"))

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