Skip to content

Commit

Permalink
feat: use repo-review 0.9 dynamic descriptions
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii committed Aug 3, 2023
1 parent d0c3669 commit c098240
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/_includes/interactive_repo_review.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
root.render(
<App
header={false}
deps={["sp-repo-review==2023.07.13", "repo-review==0.8.1"]}
deps={["sp-repo-review==2023.07.13", "repo-review==0.9.0"]}
/>,
);
</script>
27 changes: 21 additions & 6 deletions docs/assets/js/webapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,13 @@ function Results(props) {
<li key={`section-${key}`}>
<ul>
<MaterialUI.ListSubheader>
{props.families[key]}
{props.families[key].name}
</MaterialUI.ListSubheader>
{props.families[key].description && (
<MaterialUI.ListItem>
<span dangerouslySetInnerHTML={props.families[key].description} />
</MaterialUI.ListItem>
)}
{results_components}
</ul>
</li>,
Expand Down Expand Up @@ -221,13 +226,19 @@ class App extends React.Component {
try {
families_checks = pyodide.runPython(`
from pyodide.http import open_url
from repo_review.processor import process
from repo_review.processor import process, md_as_html
from repo_review.ghpath import GHPath
GHPath.open_url = staticmethod(open_url)
package = GHPath(repo="${state.repo}", branch="${state.branch}")
process(package)
result = process(package)
for v in result[0].values():
if v.get("description"):
v["description"] = md_as_html(v["description"])
result
`);
} catch (e) {
if (e.message.includes("KeyError: 'tree'")) {
Expand All @@ -251,8 +262,12 @@ class App extends React.Component {
const results = {};
const families = {};
for (const val of families_dict) {
const descr = families_dict.get(val).get("description");
results[val] = [];
families[val] = families_dict.get(val).get("name");
families[val] = {
name: families_dict.get(val).get("name").toString(),
description: descr && descr.toString(),
};
}
console.log(families);
for (const val of results_list) {
Expand Down Expand Up @@ -305,7 +320,7 @@ class App extends React.Component {
variant="outlined"
autoFocus={true}
onKeyDown={(e) => {
if (event.keyCode === 13)
if (e.keyCode === 13)
document.getElementById("branch-select").focus();
}}
onInput={(e) => this.setState({ repo: e.target.value })}
Expand All @@ -318,7 +333,7 @@ class App extends React.Component {
options={common_branches}
freeSolo={true}
onKeyDown={(e) => {
if (event.keyCode === 13) this.handleCompute();
if (e.keyCode === 13) this.handleCompute();
}}
onInputChange={(e, value) => this.setState({ branch: value })}
defaultValue={urlParams.get("branch")}
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ classifiers = [
dynamic = ["version", "readme"]
dependencies = [
"pyyaml",
"repo-review>=0.7,<0.9",
"repo-review>=0.7,<0.10",
]

[project.optional-dependencies]
Expand Down Expand Up @@ -71,7 +71,7 @@ precommit = "sp_repo_review.checks.precommit:precommit"
readthedocs = "sp_repo_review.checks.readthedocs:readthedocs"

[project.entry-points."repo_review.families"]
scikit-hep = "sp_repo_review.families:get_familes"
scikit-hep = "sp_repo_review.families:get_families"


[tool.hatch]
Expand Down
22 changes: 18 additions & 4 deletions src/sp_repo_review/families.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations

import typing
from typing import Any

__all__ = ["Family", "get_familes"]
__all__ = ["Family", "get_families"]


def __dir__() -> list[str]:
Expand All @@ -12,13 +13,26 @@ def __dir__() -> list[str]:
class Family(typing.TypedDict, total=False):
name: str # defaults to key
order: int # defaults to 0


def get_familes() -> dict[str, Family]:
description: str # Defaults to empty


def get_families(
pyproject: dict[str, Any] = {}, # noqa: B006
) -> dict[str, Family]:
pyproject_description = f"- Detected build backend: `{pyproject.get('build-system', {}).get('build-backend', 'MISSING')}`"
if classifiers := pyproject.get("project", {}).get("classifiers", []):
licenses = [
c.removeprefix("License :: ").removeprefix("OSI Approved :: ")
for c in classifiers
if c.startswith("License :: ")
]
if licenses:
pyproject_description += f"\n- Detected license(s): {', '.join(licenses)}"
return {
"general": Family(
name="General",
order=-3,
description=pyproject_description,
),
"pyproject": Family(
name="PyProject",
Expand Down

0 comments on commit c098240

Please sign in to comment.