Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNT: Add Python 3.12 support #1057

Merged
merged 3 commits into from
May 10, 2024
Merged

Conversation

effigies
Copy link
Collaborator

@effigies effigies commented May 3, 2024

Builds on #1055, fixes one small bug and removes an import of the deprecated (and removed from default installations) pkg_resources.

Copy link

codecov bot commented May 3, 2024

Codecov Report

Attention: Patch coverage is 9.09091% with 10 lines in your changes are missing coverage. Please review.

Project coverage is 89.80%. Comparing base (87eecc5) to head (ec017e7).

Files Patch % Lines
bids/modeling/report/base.py 0.00% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1057      +/-   ##
==========================================
- Coverage   89.80%   89.80%   -0.01%     
==========================================
  Files          63       63              
  Lines        7178     7177       -1     
  Branches     1374     1374              
==========================================
- Hits         6446     6445       -1     
  Misses        532      532              
  Partials      200      200              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines -110 to +124
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)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adelavega This was your bit, but the coverage report indicates that it's not tested. Could you verify that this still works as you intended?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, will do but it might take me a bit because i completely forgot the context.

as an aside, we certainly did not promote this feature nearly enough in the docs or otherwise... so maybe once this is tested we should add to the stats-model website with a nice example. could also add some more model validation since this is what causes most users problems w/ stats-models/fitlins

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Context: #918

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I manually ran the Jinja2 code, and what I changed it to above does load the template correctly. I'm going to go ahead and merge.

Comment on lines +411 to +413
duration = math.ceil( # Round up to nearest second
round(bin_sr * self.get_duration(), 3) # Cut off at millisecond precision
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python 3.11:

>>> sum([480.1] * 9)
4390.9

Python 3.12:

>>> sum([480.1] * 9)
4320.900000000001

It seems to me that we don't care about errors in the sub-millisecond range, so round to the nearest millisecond and then round up to the nearest second. Reduces the scope of potential bad rounding to N.4995.

@effigies effigies merged commit 20007e5 into bids-standard:master May 10, 2024
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants