Refactor options manager - #39
Conversation
|
@JHopeCollins this is only a rough first attempt but I want to check with you on the approach. The main thing I'm doing is moving the options logic into the |
0b9e714 to
a0fd39a
Compare
|
Here's an example demonstrating what I believe to be quite unintuitive behaviour. I totally get why this isn't recommended practice, but I also think that we should always try and do the intuitive thing. @pytest.mark.skipnopetsc4py
@pytest.mark.parametrize("options_prefix", (None, "", "custom_"))
def test_commandline_options_change(caplog, options_prefix):
from petsc4py import PETSc
options = PETSc.Options()
om = petsctools.OptionsManager(
{"opt1": "value1"}, options_prefix=options_prefix
)
with om.inserted_options():
assert options[f"{om.options_prefix}opt1"] == "value1"
# Put some options in the database after the options manager is created
options[f"{om.options_prefix}opt1"] = "value2"
with om.inserted_options():
# NOTE: not 'value2' because we use the frozen value from when we first
# made the options manager
assert options[f"{om.options_prefix}opt1"] == "value1"
# the original option should be put back (currently it's dropped)
assert options[f"{om.options_prefix}opt1"] == "value2" |
JHopeCollins
left a comment
There was a problem hiding this comment.
Generally good, this looks like it deals with the original problem and also provides more information to users.
- We will no longer interfere with the global options dictionary or attempt to hide any entries from the auto-prefixed solver.
- We will warn you if you do use the auto-generated prefix that this is unstable, where previously we would confusingly just silently ignore some options.
I had some small requests then I'm happy to approve. The biggest one is actually fixing a bug from my DefaultOptionsSet PR!
Co-authored-by: Josh Hope-Collins <jhc.jss@gmail.com> Co-authored-by: Connor Ward <c.ward20@imperial.ac.uk>
Co-authored-by: Josh Hope-Collins <joshua.hope-collins13@imperial.ac.uk>
Key changes:
Closes #37
The MFE in the issue is fixed by this: