mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 22:26:08 -04:00
Apply resolve paths to path values in config (#3400)
This commit is contained in:
parent
f9dca9a458
commit
c1c5c0b93e
3 changed files with 10 additions and 2 deletions
|
|
@ -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:
|
||||
|
||||
|
|
|
|||
|
|
@ -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.")
|
||||
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue