Skip to content

Commit f48cb8d

Browse files
authored
Merge pull request #43 from softwarepub/remove-jinja-dependency
Remove jinja; generate report from strings
2 parents 59f9ee6 + 368d108 commit f48cb8d

3 files changed

Lines changed: 14 additions & 24 deletions

File tree

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ dependencies = [
1313
"pyshacl[js]>=0.30.0",
1414
"rdflib>=7.1.1",
1515
"toml>=0.10.2",
16-
"jinja2>=3.1.6",
1716
]
1817
requires-python = ">=3.10"
1918
authors = [

src/software_card_policies/report.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# SPDX-License-Identifier: Apache-2.0
33
# SPDX-FileContributor: David Pape
44

5-
from jinja2 import Environment, PackageLoader, select_autoescape
65
from rdflib import Graph
76
from rdflib.namespace import RDF, SH
87

@@ -12,8 +11,17 @@
1211
def create_report(validation_graph: Graph, debug=False) -> str:
1312
shacl_report, *_ = validation_graph.subjects(RDF.type, SH.ValidationReport)
1413
validation_report = ValidationReport.from_graph(shacl_report, validation_graph)
15-
environment = Environment(
16-
loader=PackageLoader("software_card_policies"), autoescape=select_autoescape()
17-
)
18-
template = environment.get_template("report.j2")
19-
return template.render(validation_report=validation_report, debug=debug)
14+
15+
if validation_report.conforms:
16+
return "Validation succeeded!"
17+
18+
text = "Validation failed!\n"
19+
for validation_result in validation_report.results:
20+
text += "\n"
21+
text += f"{validation_result.severity}:\n"
22+
text += f"Breached policy: {validation_result.source_policy.name}\n"
23+
text += f"{validation_result.source_policy.description}\n"
24+
if debug:
25+
text += f"Debug: {validation_result.message}\n"
26+
27+
return text

src/software_card_policies/templates/report.j2

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)