Skip to content

Support ternary resp. conditional operations in setenv #3650

@g3n35i5

Description

@g3n35i5

What's the problem this feature will solve?

I want to set an environment conditionally based on another environment variable, in my case

MATURITY = TAG_NAME ? 'production' : 'testing'

Currently, the substitutions only support the following features

  • FOO = {env:KEY:DEFAULTVALUE}: Sets FOO to env:KEY if defined, otherwise to DEFAULTVALUE
  • FOO = {env:KEY:}: Sets FOO to env:KEY if defined, otherwise to an empty string

Describe the solution you'd like

[testenv]
setenv =
    MATURITY = {env:TAG_NAME ? 'production' : 'testing'}

Alternative Solutions

I could use a toxfile.py with

from os import environ

from tox.config.sets import EnvConfigSet
from tox.plugin import impl
from tox.session.state import State


@impl
def tox_add_env_config(env_conf: EnvConfigSet, state: State) -> None:
    env_conf["set_env"].update(
        {"MATURITY": "production" if environ.get("TAG_NAME") else "testing"},
    )

But I'd rather use plain tox.ini syntax.

Additional context

N/A

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions