Skip to content

Commit 2e68973

Browse files
fix: webapp support 0.12's skip reasons, add md_as_html method (#259)
* fix(webapp): support 0.12's skip reasons Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * style: pre-commit fixes * fix: md_as_html Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> --------- Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 76af623 commit 2e68973

File tree

4 files changed

+37
-16
lines changed

4 files changed

+37
-16
lines changed

docs/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@
6464
<App
6565
header={true}
6666
deps={[
67-
"repo-review~=0.11.3",
67+
"repo-review~=0.12.0",
6868
"sp-repo-review==2025.01.22",
69-
"validate-pyproject-schema-store==2025.01.20",
69+
"validate-pyproject-schema-store==2025.02.03",
7070
"validate-pyproject[all]~=0.22.0",
7171
]}
7272
/>,

docs/webapp.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function Results(props) {
9393
variant="body2"
9494
color="text.disabled"
9595
>
96-
{" [skipped]"}
96+
{` [skipped] ${result.skip_reason}`}
9797
</MaterialUI.Typography>
9898
);
9999
const msg = (
@@ -200,6 +200,7 @@ class App extends React.Component {
200200
msg: `<p>${DEFAULT_MSG}</p><h4>Packages:</h4> ${deps_str}`,
201201
progress: false,
202202
err_msg: "",
203+
skip_reason: "",
203204
url: "",
204205
};
205206
this.pyodide_promise = prepare_pyodide(props.deps);
@@ -231,15 +232,17 @@ class App extends React.Component {
231232
families_checks = pyodide.runPython(`
232233
from repo_review.processor import process, md_as_html
233234
from repo_review.ghpath import GHPath
235+
from dataclasses import replace
234236
235237
package = GHPath(repo="${state.repo}", branch="${state.branch}")
236-
result = process(package)
238+
families, checks = process(package)
237239
238-
for v in result[0].values():
240+
for v in families.values():
239241
if v.get("description"):
240242
v["description"] = md_as_html(v["description"])
243+
checks = [replace(v, err_msg=md_as_html(v.err_msg), skip_reason=md_as_html(v.skip_reason)) for v in checks]
241244
242-
result
245+
(families, checks)
243246
`);
244247
} catch (e) {
245248
if (e.message.includes("KeyError: 'tree'")) {
@@ -276,8 +279,9 @@ class App extends React.Component {
276279
name: val.name.toString(),
277280
description: val.description.toString(),
278281
state: val.result,
279-
err_msg: val.err_as_html().toString(),
282+
err_msg: val.err_msg.toString(),
280283
url: val.url.toString(),
284+
skip_reason: val.skip_reason.toString(),
281285
});
282286
}
283287

src/repo_review/html.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
import typing
77
from collections.abc import Mapping, Sequence
88

9-
import markdown_it
10-
119
from .families import Family, get_family_description, get_family_name
12-
from .processor import Result
10+
from .processor import Result, md_as_html
1311

1412
if typing.TYPE_CHECKING:
1513
from .__main__ import Status
@@ -37,16 +35,15 @@ def to_html(
3735
"""
3836
out = io.StringIO()
3937
print = functools.partial(builtins.print, file=out)
40-
md = markdown_it.MarkdownIt()
4138

4239
for family in families:
4340
family_name = get_family_name(families, family)
4441
family_description = get_family_description(families, family)
45-
family_results = [r for r in processed if r.family == family]
42+
family_results = [r.md_as_html() for r in processed if r.family == family]
4643
if family_results or family_description:
4744
print(f"<h3>{family_name}</h3>")
4845
if family_description:
49-
print(md.render(family_description).strip())
46+
print("<p>", md_as_html(family_description), "</p>")
5047
if family_results:
5148
print("<table>")
5249
print(
@@ -82,7 +79,7 @@ def to_html(
8279
if result.skip_reason:
8380
description += (
8481
f'<br/><span style="color:DarkKhaki;"><b>Skipped:</b> '
85-
f"<em>{md.render(result.skip_reason)}</em></span>"
82+
f"<em>{result.skip_reason}</em></span>"
8683
)
8784
print(f'<tr style="color: {color};">')
8885
print(f'<td><span role="img" aria-label="{result_txt}">{icon}</span></td>')
@@ -93,7 +90,7 @@ def to_html(
9390
print("<td>")
9491
print(description)
9592
print("<br/>")
96-
print(md.render(result.err_msg))
93+
print(result.err_msg)
9794
print("</td>")
9895
print("</tr>")
9996
if family_results:

src/repo_review/processor.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
import copy
44
import dataclasses
55
import graphlib
6+
import sys
67
import textwrap
78
import typing
89
import warnings
910
from collections.abc import Mapping, Set
10-
from typing import Any, TypeVar
11+
from typing import TYPE_CHECKING, Any, TypeVar
1112

1213
import markdown_it
1314

@@ -24,6 +25,12 @@
2425
from .fixtures import apply_fixtures, collect_fixtures, compute_fixtures, pyproject
2526
from .ghpath import EmptyTraversable
2627

28+
if TYPE_CHECKING:
29+
if sys.version_info >= (3, 11):
30+
from typing import Self
31+
else:
32+
from typing_extensions import Self
33+
2734
__all__ = [
2835
"CollectionReturn",
2936
"ProcessReturn",
@@ -84,9 +91,22 @@ class Result:
8491
def err_as_html(self) -> str:
8592
"""
8693
Produces HTML from the error message, assuming it is in markdown.
94+
Deprecated, use :meth:`md_as_html` directly instead.
8795
"""
8896
return md_as_html(self.err_msg)
8997

98+
def md_as_html(self) -> Self:
99+
"""
100+
Process fields that are assumed to be markdown.
101+
102+
.. versionadded:: 0.12.1
103+
"""
104+
return dataclasses.replace(
105+
self,
106+
err_msg=md_as_html(self.err_msg),
107+
skip_reason=md_as_html(self.skip_reason),
108+
)
109+
90110

91111
class ProcessReturn(typing.NamedTuple):
92112
"""

0 commit comments

Comments
 (0)