Skip to content

Conversation

@shimwell
Copy link
Member

@shimwell shimwell commented Jan 5, 2026

Description

when getting the material names from a DAGMC file it appears that we don't close the file afterwards.

This PR change the code to use a context manager which automatically closes the file for us.

Fixes # (issue)

Checklist

  • I have performed a self-review of my own code
  • I have followed the style guidelines for Python source files (if applicable)

Copy link
Contributor

@GuySten GuySten left a comment

Choose a reason for hiding this comment

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

Looks good, @shimwell!

@GuySten GuySten changed the title Update dagmc.py Open dagmc model file within a context manager Jan 5, 2026
@GuySten GuySten enabled auto-merge (squash) January 5, 2026 16:13
Copy link
Contributor

@pshriwise pshriwise left a comment

Choose a reason for hiding this comment

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

Thanks for noting this and making the PR @shimwell!

Looks like CI test isn't happy with use of an HDF5 group after the file is closed.

openmc/dagmc.py Outdated
with h5py.File(self.filename) as dagmc_file_contents:
material_tags_hex = dagmc_file_contents['/tstt/tags/NAME'].get('values')
material_tags_ascii = []
for tag in material_tags_hex:
Copy link
Contributor

Choose a reason for hiding this comment

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

We access the HDF5 group here outside of the context manager, causing failures in testing.

I recommend we construct a list of the material strings inside the context manager block and iterate over the resulting list of strings in the loop here to do some cleanup.

Even better might be to create an internal function that sanitizes the material tag values and call that on each value of material_tags_hex.

@pshriwise
Copy link
Contributor

Looks like my comment came in a little behind your latest change @GuySten :)

@GuySten GuySten dismissed pshriwise’s stale review January 5, 2026 20:57

This review's feedback has been fullfilled.

@GuySten GuySten merged commit 60ddafa into openmc-dev:develop Jan 5, 2026
15 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.

3 participants