Fix input_path resolving empty filenames to cwd - #4154
Merged
paulromano merged 7 commits intoOct 3, 2026
Merged
Conversation
UnstructuredMesh.from_hdf5 and DAGMCUniverse.from_hdf5 pass an empty string for filename when the HDF5 group has no stored filename, which happens for meshes and DAGMC universes built in memory and never backed by a file. input_path then resolved that empty string to the current working directory instead of leaving it empty, so filename silently became an arbitrary real path instead of indicating no file. input_path now returns an empty Path unresolved when given an empty filename, matching the from_hdf5 round-trip tests added in openmc-dev#4118.
Use the filesystem protocol rather than string formatting to inspect input filenames. An os.PathLike object can provide an empty filesystem path while its string representation is nonempty, causing the new guard to resolve a missing filename to the working or XML input directory. Normalize with os.fspath and cover empty and nonempty inputs with path resolution enabled and disabled, including an XML input context.
The session fixture disables path resolution, so the existing mesh and DAGMC reader tests do not catch empty filenames resolving to the working directory under the default configuration. Parameterize both tests over the enabled and disabled settings and patch configuration while reading the objects. The enabled cases fail against the pre-PR helper.
Replace the input-type, resolution-mode, and XML-context cross product with focused cases for empty filenames, ordinary paths, and XML-relative resolution. Keep one custom PathLike case for the filesystem-protocol regression. Exercise each HDF5 reader under the default enabled path resolution setting without duplicating its disabled-setting case.
paulromano
approved these changes
Oct 3, 2026
paulromano
enabled auto-merge (squash)
October 3, 2026 22:48
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Anyone who reads back an in-memory
UnstructuredMeshorDAGMCUniverse(one built from a MOAB/libmesh instance in memory and never backed by a
source file) from a summary or statepoint HDF5 file gets a
filenameattribute that silently points at the current working directory instead
of indicating that there is no file.
UnstructuredMesh.from_hdf5andDAGMCUniverse.from_hdf5pass an emptystring for
filenamewhen the HDF5 group has nofilenamedataset(added in #4118 to handle meshes/universes with no source file). That
empty string reaches
openmc.utility_funcs.input_path, which callsPath(filename).resolve()wheneveropenmc.config['resolve_paths']isTrue (the default).
Path('').resolve()resolves to the process'scurrent working directory, not to an empty path, so
mesh.filenameordagmc_universe.filenameends up set to whatever directory happened tobe current when the file was read. Code that checks
mesh.filename(forexample
mesh.filename.exists()to decide whether a source file isavailable) gets a wrong answer, since the working directory always
exists.
This also means the two round-trip assertions added in #4118
(
tests/unit_tests/test_mesh.py::test_umesh_from_hdf5_without_filenameand
tests/unit_tests/test_universe.py::test_dagmc_universe_from_hdf5_without_filename,both asserting
filename == Path()) do not actually hold under thedefault configuration.
input_pathnow returns an empty, unresolvedPathwhen given an emptyfilename, before the
resolve_pathsbranch runs. No other caller ofinput_path(cross section paths, source library/path, settings files)passes an empty string in normal use, so this only changes behavior for
the "no file" case.
Fixes # (none filed; found by code review)
Checklist