4
4
from bids .layout import BIDSLayout
5
5
from bids .modeling import BIDSStatsModelsGraph
6
6
from bids import __version__ as bids_version
7
- import pkg_resources as pkgr
8
7
from .utils import deroot , snake_to_camel , displayify , to_alphanum , generate_contrast_matrix
9
8
10
9
PATH_PATTERNS = [
@@ -107,25 +106,22 @@ def _write_report(report_dict, out_dir, template_path=None):
107
106
)
108
107
109
108
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'
112
111
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 )
114
114
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 )
118
116
119
117
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 )
123
120
124
- report_dict = deroot (report_dict , os . path . dirname ( target_file ))
121
+ report_dict = deroot (report_dict , str ( out_path ))
125
122
126
123
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 )
129
125
130
126
131
127
def generate_report (
@@ -165,4 +161,4 @@ def generate_report(
165
161
166
162
report_dict = _build_report_dict (graph )
167
163
168
- _write_report (report_dict , output_dir )
164
+ _write_report (report_dict , output_dir )
0 commit comments