✨ feat(config): support subscript syntax and env_name in conditionals#3884
Merged
gaborbernat merged 1 commit intotox-dev:mainfrom Mar 17, 2026
Merged
✨ feat(config): support subscript syntax and env_name in conditionals#3884gaborbernat merged 1 commit intotox-dev:mainfrom
gaborbernat merged 1 commit intotox-dev:mainfrom
Conversation
8619461 to
b3f6ca3
Compare
Factor names like "3.14" are valid in tox for Python version-based environments but cannot be referenced in condition expressions because factor.3.14 is invalid Python syntax (the parser sees .3.14 as a float literal). Additionally, there was no way to check the full environment name in conditions, limiting conditional configuration capabilities. Add subscript syntax for both factor and env lookups (factor['3.14'] and env['CI']) to handle non-identifier names. Add env_name variable to enable exact environment name matching in conditions (env_name == 'test-3.14'). Refactored condition evaluation by extracting helper functions to reduce complexity and improve maintainability while maintaining backward compatibility with existing dot-syntax expressions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Factor names like
3.14are valid in tox for Python version-based environments, but they cannot be referenced inreplace = "if"condition expressions becausefactor.3.14is invalid Python syntax—the parser interprets.3.14as a float literal. This limitation prevents users from writing conditional configuration based on Python version factors. ✨ Additionally, there was no way to check the full environment name in conditions, limiting the ability to target specific environments with conditional values.This change adds subscript syntax for both
factorandenvlookups (factor['3.14']andenv['CI']) to handle names that aren't valid Python identifiers. It also introduces anenv_namevariable that resolves to the full environment name as a string, enabling exact name matching likeenv_name == 'test-3.14'. 🔧 The implementation refactors the condition evaluator by extracting helper functions to reduce complexity while maintaining full backward compatibility with existing dot-syntax expressions (factor.NAMEandenv.VAR).The new syntax works seamlessly with existing configurations. Users can now write version-specific conditional dependencies in environment configurations and target specific environments by name without workarounds. Documentation has been updated across reference, how-to, explanation, and tutorial sections with practical examples.