Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jayvdb opened this issue Oct 17, 2020 · 3 comments · Fixed by #1691
Closed

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

jayvdb opened this issue Oct 17, 2020 · 3 comments · Fixed by #1691
Labels
bug:normal affects many people or has quite an impact

Comments

@jayvdb
Copy link

jayvdb commented Oct 17, 2020

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
@jayvdb jayvdb added the bug:normal affects many people or has quite an impact label Oct 17, 2020
@gaborbernat
Copy link
Member

Tagging @mkenigs as potential follow-up issue 👍

@jayvdb
Copy link
Author

jayvdb commented Oct 17, 2020

I've got a patch to fix this and the original problem (assuming I've understood it correctly), however I am also encountering a separate problem with \\ in the setenv which I'm attempting to get my head around so it can be either documented or, hopefully, fixed while I am at it.

jayvdb added a commit to jayvdb/tox that referenced this issue Oct 17, 2020
jayvdb added a commit to jayvdb/tox that referenced this issue Oct 17, 2020
@jayvdb
Copy link
Author

jayvdb commented Oct 17, 2020

Some basic misplaced \\ issues raised as #1692

jayvdb added a commit to jayvdb/tox that referenced this issue Oct 18, 2020
@tox-dev tox-dev locked and limited conversation to collaborators Jan 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug:normal affects many people or has quite an impact
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants