Skip to content

✨ feat(config): support subscript syntax and env_name in conditionals#3884

Merged
gaborbernat merged 1 commit intotox-dev:mainfrom
gaborbernat:dot
Mar 17, 2026
Merged

✨ feat(config): support subscript syntax and env_name in conditionals#3884
gaborbernat merged 1 commit intotox-dev:mainfrom
gaborbernat:dot

Conversation

@gaborbernat
Copy link
Copy Markdown
Member

Factor names like 3.14 are valid in tox for Python version-based environments, but they cannot be referenced in replace = "if" condition expressions because factor.3.14 is invalid Python syntax—the parser interprets .3.14 as 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 factor and env lookups (factor['3.14'] and env['CI']) to handle names that aren't valid Python identifiers. It also introduces an env_name variable that resolves to the full environment name as a string, enabling exact name matching like env_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.NAME and env.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.

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.
@gaborbernat gaborbernat merged commit 2d18e29 into tox-dev:main Mar 17, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant