Skip to content

Conversation

@ckreibich
Copy link
Member

@ckreibich ckreibich commented Sep 25, 2025

This adds a pass over the (non-default) config options in the freshly loaded configparser, catching any interpolation errors and reporting them in our own terms. This has some subtlety since we cannot just check all config options due to configparser's built-in default-fallback behavior. Since btest pulls os.environ into the defaults, checking everything may well trip over some environment variables that aren't formatted for Python interpolation (as, in my case, HISTTIMEFORMAT).

This is a follow-up to #119 because regardless of whether or not we find the default Python error message intuitive, I think crashing out with a backtrace is excessive.

Resolves #119.

This adds a pass over the (non-default) config options in the freshly loaded
configparser, catching any interpolation errors and reporting them in our own
terms.

This has some subtlety since we cannot just check all config options, due to
configparser's built-in default-fallback behavior: since we pull os.environ into
the defaults, checking everything is brittle since there may well be some
environment variables that aren't formatted for Python interpolation (as, in my
case, HISTTIMEFORMAT).
@ckreibich
Copy link
Member Author

Btw — I am not sure whether we should still be patching itemsNoDefaults straight into the ConfigParser class. I can't find any reference of ConfigParser.itemsNoDefaults ever having been a method, so we're basically just plumbing a function into the class instead of inheriting, or simply defining a global function. I decided to steer clear of this here.

@ckreibich ckreibich merged commit de7f57e into master Oct 2, 2025
22 checks passed
@ckreibich ckreibich deleted the topic/christian/python-interpolation-errors branch October 2, 2025 16:41
awelzel added a commit that referenced this pull request Dec 10, 2025
In #122 there's spurious stderr output for Spicy's test suite reported.
This is due to the new code from #121 eagerly reading all keys in all
sections, even if some, like [environment-<tag>] sections for
alternatives, would never be used if not selected explicitly.

Move the interpolation check below Options.alternative wrangling and
skip sections that won't be used. This squelches the spurious stderr
output. I've added a test, though it's a bit opaque.
awelzel added a commit that referenced this pull request Dec 10, 2025
In #122 there's spurious stderr output for Spicy's test suite reported.
This is due to the new code from #121 eagerly reading all keys in all
sections, even if some, like [environment-<tag>] sections for
alternatives, would never be used if not selected explicitly.

Move the interpolation check below Options.alternative wrangling and
skip sections that won't be used. This squelches the spurious stderr
output. I've added a test, though it's a bit opaque.
awelzel added a commit that referenced this pull request Dec 16, 2025
In #122 there's spurious stderr output for Spicy's test suite reported.
This is due to the new code from #121 eagerly reading all keys in all
sections, even if some, like [environment-<tag>] sections for
alternatives, would never be used if not selected explicitly.

Move the interpolation check below Options.alternative wrangling and
skip sections that won't be used. This squelches the spurious stderr
output. I've added a test, though it's a bit opaque.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BTest [DEFAULT] variables only work in [btest] section, not others

3 participants