Apply resolve paths to path values in config (#3400)

This commit is contained in:
Patrick Shriwise 2025-05-07 18:51:40 -06:00 committed by GitHub
parent f9dca9a458
commit c1c5c0b93e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 2 deletions

View file

@ -30,7 +30,8 @@ responsible for specifying one or more of the following:
Each of the above files can specified in several ways. In the Python API, a
:ref:`runtime configuration variable <usersguide_data_runtime>`
:data:`openmc.config` can be used to specify any of the above and is initialized
using a set of environment variables.
using a set of environment variables. Data configuration paths set in
:data:`openmc.config` will be expanded to absolute paths.
.. _usersguide_data_runtime:

View file

@ -60,7 +60,7 @@ class _Config(MutableMapping):
return repr(self._mapping)
def _set_path(self, key, value):
self._mapping[key] = p = Path(value)
self._mapping[key] = p = Path(value).resolve()
if not p.exists():
warnings.warn(f"'{value}' does not exist.")

View file

@ -1,5 +1,6 @@
from collections.abc import Mapping
import os
from pathlib import Path
import openmc
import pytest
@ -34,6 +35,12 @@ def test_config_basics():
with pytest.raises(KeyError):
openmc.config['🐖'] = '/like/to/eat/bacon'
# ensure relative paths are expanded into absolute
# paths
chain_path = Path('./chain.xml')
openmc.config['chain_file'] = chain_path
assert openmc.config['chain_file'] == chain_path.resolve()
def test_config_patch():
openmc.config['cross_sections'] = '/path/to/cross_sections.xml'