Skip to content

RecursionError when TOML set_env uses {env_site_packages_dir} #3758

@gaborbernat

Description

@gaborbernat

Issue

Using {env_site_packages_dir} (or similar substitutions that trigger environment creation) inside set_env in TOML format causes RecursionError: maximum recursion depth exceeded.

The same configuration works fine in INI format because the INI loader defers substitution resolution for set_env values, while the TOML loader eagerly resolves all substitutions via Unroll before constructing SetEnv.

Recursion cycle

set_env (contains {env_site_packages_dir})
  → Unroll resolves {env_site_packages_dir}
    → env_site_packages_dir needs _py_info → create_python_env()
      → reads system_site_packages config
        → default reads environment_variables
          → reads set_env → LOOP

Minimal example

tox.toml:

[env_run_base]
set_env._COVERAGE_SRC = "{env_site_packages_dir}{/}mypackage"

Running any tox command produces:

RecursionError: maximum recursion depth exceeded

Discovered via pypa/virtualenv#3050 when migrating from tox.ini to tox.toml.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug:normalaffects many people or has quite an impact

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions