diff --git a/src/cbmc_viewer/report.py b/src/cbmc_viewer/report.py index 2e6fb28..08fffa3 100644 --- a/src/cbmc_viewer/report.py +++ b/src/cbmc_viewer/report.py @@ -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 @@ -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( diff --git a/src/cbmc_viewer/templates.py b/src/cbmc_viewer/templates.py index 7e91252..f8e82b8 100644 --- a/src/cbmc_viewer/templates.py +++ b/src/cbmc_viewer/templates.py @@ -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' @@ -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):