From ccafbb7e0adf58014657401bba71b30e4bf471fb Mon Sep 17 00:00:00 2001 From: Antonio Cordero Balcazar Date: Mon, 4 May 2026 14:21:26 +0200 Subject: [PATCH] * Options as system variables * Additional tests --- ppp.py | 12 ++++++++++++ tests/tests_wildcards.py | 12 ++++++++++++ tests/wildcards/test.yaml | 14 ++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/ppp.py b/ppp.py index 8ce1708..4c60838 100644 --- a/ppp.py +++ b/ppp.py @@ -1,4 +1,5 @@ import dataclasses +from enum import Enum import logging import os import re @@ -583,6 +584,17 @@ class PromptPostProcessor: # pylint: disable=too-few-public-methods,too-many-in """ vs = self.state.variables vs.clear_system() + + # Option related variables + for opt_name in self.defopt.keys(): + opt_value = getattr(self.state.options, opt_name) + var_name = "_opt_" + opt_name + if isinstance(opt_value, (bool, str, int)): + vs.set_system(var_name, opt_value) + elif isinstance(opt_value, Enum): + vs.set_system(var_name, str(opt_value).split(".", 1)[-1]) + + # Model related variables sdchecks = {x: self.env_info.get("is_" + x, False) for x in self.known_models} sdchecks.update({"": True}) model_name_val = next((k for k, v in sdchecks.items() if v), "") diff --git a/tests/tests_wildcards.py b/tests/tests_wildcards.py index fc0b22f..c540717 100644 --- a/tests/tests_wildcards.py +++ b/tests/tests_wildcards.py @@ -383,6 +383,18 @@ class TestWildcards(TestPromptPostProcessorBase): ppp="nocup", ) + def test_wc_wildcardPS2_yaml(self): # yaml wildcard with object formatted choices and options and prefix and suffix + self.process( + InputTuple("the choices are: [__yaml/wildcardPS2__]", ""), + OutputTuple("the choices are: [(prefix2-choice2-suffix:1.5)]", ""), + ) + + def test_wc_wildcardAt_yaml(self): # yaml wildcard with attention in choices + self.process( + InputTuple("the choices are: [__yaml/wildcardAt__]", ""), + OutputTuple("the choices are: [(choice2:1.5)]", ""), + ) + def test_wc_anonymouswildcard_yaml(self): # yaml anonymous wildcard self.process( InputTuple("the choices are: __yaml/anonwildcards__", ""), diff --git a/tests/wildcards/test.yaml b/tests/wildcards/test.yaml index 65d664a..b904d18 100644 --- a/tests/wildcards/test.yaml +++ b/tests/wildcards/test.yaml @@ -37,6 +37,11 @@ yaml: - - + wildcardAt: + - (choice1:0.5) + - (choice2:1.5) + - (choice3:1) + wildcardPS: - { sampler: "~", @@ -51,6 +56,15 @@ yaml: - { weight: 2, text: choice2 } - { weight: 1, text: choice3 } + wildcardPS2: + - { + prefix: "(prefix{1|2}-", + suffix: "-suffix:1.5)", + } + - { text: choice1 } + - { text: choice2 } + - { text: choice3 } + more_nested: even_more_nested: # this would be __yaml/more_nested/even_more_nested__ - one