Skip to content

Commit

Permalink
Fix broken link in documentation and make bokeh links dynamic (#20)
Browse files Browse the repository at this point in the history
* Fix broken link in configuration documentation
* Make bokeh links dynamic
  • Loading branch information
karelvaculik authored Jun 1, 2024
1 parent 5eb725f commit 244a4f3
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 2.1.2 (2024-06-01)

- Version of installed `bokeh` package is now used to create matching JavaScript links.
- Fixed invalid link in Configuration page of documentation.

## 2.1.1 (2024-06-01)

- Fixed logging by replacing custom logger creation with standard `getLogger` call. The
Expand Down
5 changes: 4 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,15 @@ added to the HTML `<head>` element.
Some libraries, e.g. [DataTables](https://datatables.net/), require also [jQuery](https://jquery.com/), which is listed
separately in `external_links.ini`.

All links in `external_links.ini` are fixed except for Bokeh links.
Bokeh links contain placeholder `{BOKEH_VERSION}`, which is replaced by the version of installed `bokeh` package during report generation by Pyreball.

### config.ini File

`config.ini` file controls behaviour of Pyreball as well as how various elements should be displayed in the final HTML.
The default `config.ini` looks like this:

{{ inline_source("pyreball/cfg/config.ini", "cfg") }}
{{ inline_source("src/pyreball/cfg/config.ini", "cfg") }}

Detailed description is provided in
section [config.ini vs. CLI arguments vs. function arguments](#configini-vs-cli-arguments-vs-function-arguments).
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pyreball"
version = "2.1.1"
version = "2.1.2"
description = "Python reporting tool."
authors = ["Karel Vaculik <[email protected]>"]
license = "Apache-2.0"
Expand Down
22 changes: 22 additions & 0 deletions src/pyreball/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,27 @@ def _contains_class(html_text: str, class_name: str) -> bool:
return re.search(pattern, html_text) is not None


def _fill_bokeh_version_in_external_links(external_links: Dict[str, List[str]]) -> None:
"""Fill-in version of installed bokeh package into external links.
The links are updated inplace.
Args:
external_links: Dictionary with external links.
"""
if "bokeh" in external_links:
try:
import bokeh

bokeh_version = bokeh.__version__
except ImportError:
bokeh_version = "3.2.2"
external_links["bokeh"] = [
link.replace("{BOKEH_VERSION}", bokeh_version)
for link in external_links["bokeh"]
]


def _insert_js_and_css_links(
html_content: str, external_links: Dict[str, List[str]]
) -> str:
Expand Down Expand Up @@ -721,6 +742,7 @@ def main() -> None:
filename=LINKS_INI_FILENAME,
directory=config_directory,
)
_fill_bokeh_version_in_external_links(external_links=external_links)

parameters = merge_parameter_dictionaries(
primary_parameters=cli_parameters,
Expand Down
10 changes: 5 additions & 5 deletions src/pyreball/cfg/external_links.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ altair =
<script src="https://cdn.jsdelivr.net/npm/vega-lite@5"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-embed@6"></script>
bokeh =
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-3.2.2.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-widgets-3.2.2.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-tables-3.2.2.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-gl-3.2.2.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-3.2.2.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-{BOKEH_VERSION}.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-widgets-{BOKEH_VERSION}.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-tables-{BOKEH_VERSION}.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-gl-{BOKEH_VERSION}.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-{BOKEH_VERSION}.min.js" crossorigin="anonymous"></script>
datatables =
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.6/css/jquery.dataTables.min.css" />
<script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
Expand Down
53 changes: 52 additions & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import os
import sys
import textwrap
from pathlib import Path
from unittest.mock import patch
from unittest.mock import Mock, patch

import pytest

from pyreball.__main__ import (
_contains_class,
_fill_bokeh_version_in_external_links,
_get_config_directory,
_get_output_dir_and_file_stem,
_insert_heading_title_and_toc,
Expand Down Expand Up @@ -370,6 +372,55 @@ def test__contains_class(html_text, class_name, expected_result):
assert _contains_class(html_text, class_name) == expected_result


@pytest.mark.parametrize(
"external_links,expected",
[
(
{},
{},
),
(
{"something": ["else"]},
{"something": ["else"]},
),
(
{
"bokeh": [
(
'<script src="https://cdn.bokeh.org/bokeh/release/bokeh'
'-{BOKEH_VERSION}.min.js" crossorigin="anonymous"></script>'
),
(
'<script src="https://cdn.bokeh.org/bokeh/release/bokeh-'
'widgets-{BOKEH_VERSION}.min.js" crossorigin="anonymous">'
"</script>"
),
]
},
{
"bokeh": [
(
'<script src="https://cdn.bokeh.org/bokeh/release/bokeh'
'-1.2.3.min.js" crossorigin="anonymous"></script>'
),
(
'<script src="https://cdn.bokeh.org/bokeh/release/bokeh-'
'widgets-1.2.3.min.js" crossorigin="anonymous">'
"</script>"
),
]
},
),
],
)
def test__fill_bokeh_version_in_external_links(external_links, expected):
bokeh_package_mock = Mock()
bokeh_package_mock.__version__ = "1.2.3"
with patch.dict(sys.modules, {"bokeh": bokeh_package_mock}):
_fill_bokeh_version_in_external_links(external_links)
assert external_links == expected


@pytest.mark.parametrize(
"html_content,external_links,expected_result",
[
Expand Down

0 comments on commit 244a4f3

Please sign in to comment.