From 16c551a7558c64f4bf59a575b94a84c1c6bd827b Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Fri, 3 May 2024 13:28:28 -0400 Subject: [PATCH 1/3] MNT: Use jinja2 PackageLoader instead of pkg_resources --- bids/modeling/report/base.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/bids/modeling/report/base.py b/bids/modeling/report/base.py index 2c3a31e8..6ddee975 100644 --- a/bids/modeling/report/base.py +++ b/bids/modeling/report/base.py @@ -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 = [ @@ -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( @@ -165,4 +161,4 @@ def generate_report( report_dict = _build_report_dict(graph) - _write_report(report_dict, output_dir) \ No newline at end of file + _write_report(report_dict, output_dir) From 4f1a161f8296778754b8eec27ffc2dda081c44f7 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Fri, 3 May 2024 17:14:37 -0400 Subject: [PATCH 2/3] FIX: Avoid rounding up for very small epsilons --- bids/variables/variables.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bids/variables/variables.py b/bids/variables/variables.py index e711c65e..deb48286 100644 --- a/bids/variables/variables.py +++ b/bids/variables/variables.py @@ -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) From ec017e74251bc5f6f463efad013d06d1e0df2dc6 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Fri, 3 May 2024 17:15:36 -0400 Subject: [PATCH 3/3] CI: Run tests on Python 3.12 --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a441f1e4..55181661 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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