Skip to content

Curly braces cannot be escaped in setenv definition since 3.20.0 #1690

@jayvdb

Description

@jayvdb

Somewhat similar to #1502 , but this is a regression caused by #1656 , which has a test which is precisely what is not wanted. It appears there wasnt an issue created about that problem, but it appears to be that the runtime environment for the invoked commands contains backslashes. That should have been solved by leaving the tox substitution framework working as-is, and post-processing the substitutions when they are injected into the new process environment, to whatever extent that is possible (seems feasible to me, but maybe I have missed something).

The following emits \{a\}

[testenv]
setenv =
  FOO=\\\{a\\\}
commands =
  echo "{env:FOO}"

Removing the \\ results in an startup error.

[testenv]
setenv =
  FOO=\{a\}
commands =
  echo "{env:FOO}"
using tox.ini: /home/jayvdb/projects/tox/my-tox-tests/tests/tox.ini (pid 27501)
  removing /home/jayvdb/projects/tox/my-tox-tests/tests/.tox/log
Traceback (most recent call last):
  File "/home/jayvdb/.cache/tox/my-tox-tests/py38-tox3_20/bin/tox", line 8, in <module>
    sys.exit(cmdline())
  File "/home/jayvdb/.cache/tox/my-tox-tests/py38-tox3_20/lib/python3.8/site-packages/tox/session/__init__.py", line 44, in cmdline
    main(args)
  File "/home/jayvdb/.cache/tox/my-tox-tests/py38-tox3_20/lib/python3.8/site-packages/tox/session/__init__.py", line 65, in main
    config = load_config(args)
  File "/home/jayvdb/.cache/tox/my-tox-tests/py38-tox3_20/lib/python3.8/site-packages/tox/session/__init__.py", line 81, in load_config
    config = parseconfig(args)
  File "/home/jayvdb/.cache/tox/my-tox-tests/py38-tox3_20/lib/python3.8/site-packages/tox/config/__init__.py", line 278, in parseconfig
    ParseIni(config, config_file, content)
  File "/home/jayvdb/.cache/tox/my-tox-tests/py38-tox3_20/lib/python3.8/site-packages/tox/config/__init__.py", line 1249, in __init__
    raise tox.exception.ConfigError(
tox.exception.ConfigError: ConfigError: with_escaped_bracket_setenv failed with ConfigError: substitution key 'a' not found at Traceback (most recent call last):
  File "/home/jayvdb/.cache/tox/my-tox-tests/py38-tox3_20/lib/python3.8/site-packages/tox/config/__init__.py", line 1225, in run
    results[name] = cur_self.make_envconfig(name, section, subs, config)
  File "/home/jayvdb/.cache/tox/my-tox-tests/py38-tox3_20/lib/python3.8/site-packages/tox/config/__init__.py", line 1379, in make_envconfig
    res = meth(env_attr.name, env_attr.default, replace=replace)
  File "/home/jayvdb/.cache/tox/my-tox-tests/py38-tox3_20/lib/python3.8/site-packages/tox/config/__init__.py", line 1659, in getargvlist
    return _ArgvlistReader.getargvlist(self, s, replace=replace)
  File "/home/jayvdb/.cache/tox/my-tox-tests/py38-tox3_20/lib/python3.8/site-packages/tox/config/__init__.py", line 1872, in getargvlist
    commands.append(cls.processcommand(reader, current_command, replace))
  File "/home/jayvdb/.cache/tox/my-tox-tests/py38-tox3_20/lib/python3.8/site-packages/tox/config/__init__.py", line 1909, in processcommand
    new_word = reader._replace(word)
  File "/home/jayvdb/.cache/tox/my-tox-tests/py38-tox3_20/lib/python3.8/site-packages/tox/config/__init__.py", line 1716, in _replace
    replaced = Replacer(self, crossonly=crossonly).do_replace(value)
  File "/home/jayvdb/.cache/tox/my-tox-tests/py38-tox3_20/lib/python3.8/site-packages/tox/config/__init__.py", line 1756, in do_replace
    expanded = substitute_once(value)
  File "/home/jayvdb/.cache/tox/my-tox-tests/py38-tox3_20/lib/python3.8/site-packages/tox/config/__init__.py", line 1750, in substitute_once
    return self.RE_ITEM_REF.sub(self._replace_match, x)
  File "/home/jayvdb/.cache/tox/my-tox-tests/py38-tox3_20/lib/python3.8/site-packages/tox/config/__init__.py", line 1797, in _replace_match
    return self._replace_substitution(match)
  File "/home/jayvdb/.cache/tox/my-tox-tests/py38-tox3_20/lib/python3.8/site-packages/tox/config/__init__.py", line 1835, in _replace_substitution
    val = self._substitute_from_other_section(sub_key)
  File "/home/jayvdb/.cache/tox/my-tox-tests/py38-tox3_20/lib/python3.8/site-packages/tox/config/__init__.py", line 1829, in _substitute_from_other_section
    raise tox.exception.ConfigError("substitution key {!r} not found".format(key))
tox.exception.ConfigError: ConfigError: substitution key 'a' not found

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug:normalaffects many people or has quite an impact

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions