Skip to content

Commit 20007e5

Browse files
authored
Merge pull request #1057 from effigies/mnt/py312
MNT: Add Python 3.12 support
2 parents 87eecc5 + ec017e7 commit 20007e5

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
strategy:
3939
matrix:
4040
os: ['ubuntu-latest', 'macos-latest']
41-
python-version: [3.8, 3.9, "3.10", "3.11"]
41+
python-version: [3.8, 3.9, '3.10', '3.11', '3.12']
4242
dependencies: ['full', 'pre']
4343
include:
4444
- os: ubuntu-latest

bids/modeling/report/base.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from bids.layout import BIDSLayout
55
from bids.modeling import BIDSStatsModelsGraph
66
from bids import __version__ as bids_version
7-
import pkg_resources as pkgr
87
from .utils import deroot, snake_to_camel, displayify, to_alphanum, generate_contrast_matrix
98

109
PATH_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

131127
def 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)

bids/variables/variables.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,9 @@ def to_dense(self, sampling_rate=None):
408408
else:
409409
sampling_rate = bin_sr
410410

411-
duration = int(math.ceil(bin_sr * self.get_duration()))
411+
duration = math.ceil( # Round up to nearest second
412+
round(bin_sr * self.get_duration(), 3) # Cut off at millisecond precision
413+
)
412414
ts = np.zeros(duration, dtype=self.values.dtype)
413415

414416
onsets = np.round(self.onset * bin_sr).astype(int)

0 commit comments

Comments
 (0)