44from bids .layout import BIDSLayout
55from bids .modeling import BIDSStatsModelsGraph
66from bids import __version__ as bids_version
7- import pkg_resources as pkgr
87from .utils import deroot , snake_to_camel , displayify , to_alphanum , generate_contrast_matrix
98
109PATH_PATTERNS = [
@@ -107,25 +106,22 @@ def _write_report(report_dict, out_dir, template_path=None):
107106 )
108107
109108 if template_path is None :
110- searchpath = pkgr . resource_filename ('bids' , '/ ' )
111- template_file = 'modeling/report/ report_template.jinja'
109+ loader = jinja2 . PackageLoader ('bids' , 'modeling/report ' )
110+ template_file = 'report_template.jinja'
112111 else :
113- searchpath , template_file = os .path .split (template_path )
112+ loader = jinja2 .FileSystemLoader (os .path .dirname (template_path ))
113+ template_file = os .path .basename (template_path )
114114
115- env = jinja2 .Environment (
116- loader = jinja2 .FileSystemLoader (searchpath = searchpath ))
117- tpl = env .get_template (template_file )
115+ tpl = jinja2 .Environment (loader = loader ).get_template (template_file )
118116
119117 model = snake_to_camel (report_dict ['model' ]['name' ])
120- target_file = os .path .join (
121- out_dir , f"{ model } _report.html"
122- )
118+ out_path = Path (out_dir )
119+ out_path .mkdir (parents = True , exist_ok = True )
123120
124- report_dict = deroot (report_dict , os . path . dirname ( target_file ))
121+ report_dict = deroot (report_dict , str ( out_path ))
125122
126123 html = tpl .render (report_dict )
127- Path (target_file ).parent .mkdir (parents = True , exist_ok = True )
128- Path (target_file ).write_text (html )
124+ Path .write_text (out_path / f"{ model } _report.html" , html )
129125
130126
131127def generate_report (
@@ -165,4 +161,4 @@ def generate_report(
165161
166162 report_dict = _build_report_dict (graph )
167163
168- _write_report (report_dict , output_dir )
164+ _write_report (report_dict , output_dir )
0 commit comments