Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/cbmc_viewer/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os
import shutil

import pkg_resources
from importlib import resources as importlib_resources

from cbmc_viewer import markup_code
from cbmc_viewer import markup_summary
Expand Down Expand Up @@ -37,10 +37,11 @@ def report(config, sources, symbols, results, coverage, traces, properties,
trace_dir = os.path.join(report_dir, markup_trace.TRACES)

os.makedirs(report_dir, exist_ok=True)
shutil.copy(pkg_resources.resource_filename(PACKAGE, VIEWER_CSS),
report_dir)
shutil.copy(pkg_resources.resource_filename(PACKAGE, VIEWER_JS),
report_dir)

with importlib_resources.path(PACKAGE, VIEWER_CSS) as css_path:
shutil.copy(css_path, report_dir)
with importlib_resources.path(PACKAGE, VIEWER_JS) as js_path:
shutil.copy(js_path, report_dir)

progress("Preparing report summary")
markup_summary.Summary(
Expand Down
22 changes: 14 additions & 8 deletions src/cbmc_viewer/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import jinja2
from jinja2 import select_autoescape

import pkg_resources
from importlib import resources as importlib_resources

PACKAGE = 'cbmc_viewer'
TEMPLATES = 'templates'
Expand All @@ -24,13 +24,19 @@ def env():
global ENV

if ENV is None:
template_dir = pkg_resources.resource_filename(PACKAGE, TEMPLATES)
ENV = jinja2.Environment(
loader=jinja2.FileSystemLoader(template_dir),
autoescape=select_autoescape(
enabled_extensions=('html'),
default_for_string=True)
)
try:
ctxmgr = importlib_resources.as_file(
importlib_resources.files(PACKAGE) / TEMPLATES)
except AttributeError:
# Python 3.7 and 3.8
ctxmgr = importlib_resources.path(PACKAGE, TEMPLATES)
with ctxmgr as templates_path:
ENV = jinja2.Environment(
loader=jinja2.FileSystemLoader(str(templates_path)),
autoescape=select_autoescape(
enabled_extensions=('html'),
default_for_string=True)
)
return ENV

def render_summary(summary):
Expand Down
Loading