Skip to content

Commit eac5d62

Browse files
committed
Replace uses of deprecated pkg_resources
Follows https://importlib-resources.readthedocs.io/en/latest/migration.html to avoid use of `pkg_resources`, which has been deprecated.
1 parent 1269b52 commit eac5d62

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/cbmc_viewer/report.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import os
88
import shutil
99

10-
import pkg_resources
10+
from importlib import resources as importlib_resources
1111

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

3939
os.makedirs(report_dir, exist_ok=True)
40-
shutil.copy(pkg_resources.resource_filename(PACKAGE, VIEWER_CSS),
41-
report_dir)
42-
shutil.copy(pkg_resources.resource_filename(PACKAGE, VIEWER_JS),
43-
report_dir)
40+
41+
with importlib_resources.path(PACKAGE, VIEWER_CSS) as css_path:
42+
shutil.copy(css_path, report_dir)
43+
with importlib_resources.path(PACKAGE, VIEWER_JS) as js_path:
44+
shutil.copy(js_path, report_dir)
4445

4546
progress("Preparing report summary")
4647
markup_summary.Summary(

src/cbmc_viewer/templates.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import jinja2
77
from jinja2 import select_autoescape
88

9-
import pkg_resources
9+
from importlib import resources as importlib_resources
1010

1111
PACKAGE = 'cbmc_viewer'
1212
TEMPLATES = 'templates'
@@ -24,13 +24,13 @@ def env():
2424
global ENV
2525

2626
if ENV is None:
27-
template_dir = pkg_resources.resource_filename(PACKAGE, TEMPLATES)
28-
ENV = jinja2.Environment(
29-
loader=jinja2.FileSystemLoader(template_dir),
30-
autoescape=select_autoescape(
31-
enabled_extensions=('html'),
32-
default_for_string=True)
33-
)
27+
with importlib_resources.path(PACKAGE, TEMPLATES) as templates_path:
28+
ENV = jinja2.Environment(
29+
loader=jinja2.FileSystemLoader(str(templates_path)),
30+
autoescape=select_autoescape(
31+
enabled_extensions=('html'),
32+
default_for_string=True)
33+
)
3434
return ENV
3535

3636
def render_summary(summary):

0 commit comments

Comments
 (0)