Skip to content

Commit

Permalink
Merge pull request #1057 from effigies/mnt/py312
Browse files Browse the repository at this point in the history
MNT: Add Python 3.12 support
  • Loading branch information
effigies authored May 10, 2024
2 parents 87eecc5 + ec017e7 commit 20007e5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
strategy:
matrix:
os: ['ubuntu-latest', 'macos-latest']
python-version: [3.8, 3.9, "3.10", "3.11"]
python-version: [3.8, 3.9, '3.10', '3.11', '3.12']
dependencies: ['full', 'pre']
include:
- os: ubuntu-latest
Expand Down
24 changes: 10 additions & 14 deletions bids/modeling/report/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from bids.layout import BIDSLayout
from bids.modeling import BIDSStatsModelsGraph
from bids import __version__ as bids_version
import pkg_resources as pkgr
from .utils import deroot, snake_to_camel, displayify, to_alphanum, generate_contrast_matrix

PATH_PATTERNS = [
Expand Down Expand Up @@ -107,25 +106,22 @@ def _write_report(report_dict, out_dir, template_path=None):
)

if template_path is None:
searchpath = pkgr.resource_filename('bids', '/')
template_file = 'modeling/report/report_template.jinja'
loader = jinja2.PackageLoader('bids', 'modeling/report')
template_file = 'report_template.jinja'
else:
searchpath, template_file = os.path.split(template_path)
loader = jinja2.FileSystemLoader(os.path.dirname(template_path))
template_file = os.path.basename(template_path)

env = jinja2.Environment(
loader=jinja2.FileSystemLoader(searchpath=searchpath))
tpl = env.get_template(template_file)
tpl = jinja2.Environment(loader=loader).get_template(template_file)

model = snake_to_camel(report_dict['model']['name'])
target_file = os.path.join(
out_dir, f"{model}_report.html"
)
out_path = Path(out_dir)
out_path.mkdir(parents=True, exist_ok=True)

report_dict = deroot(report_dict, os.path.dirname(target_file))
report_dict = deroot(report_dict, str(out_path))

html = tpl.render(report_dict)
Path(target_file).parent.mkdir(parents=True, exist_ok=True)
Path(target_file).write_text(html)
Path.write_text(out_path / f"{model}_report.html", html)


def generate_report(
Expand Down Expand Up @@ -165,4 +161,4 @@ def generate_report(

report_dict = _build_report_dict(graph)

_write_report(report_dict, output_dir)
_write_report(report_dict, output_dir)
4 changes: 3 additions & 1 deletion bids/variables/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,9 @@ def to_dense(self, sampling_rate=None):
else:
sampling_rate = bin_sr

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

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

0 comments on commit 20007e5

Please sign in to comment.