Issue #212 on hold

escaping curly braces in a tox command doesn't work

taleinat
created an issue

I was trying to delete a few specific files using the "find" command, but couldn't get tox to ignore the required curly braces in the command:

py26 runtests: commands[2] | find /Users/.../dev/.../.tox/py26 -name *.so -exec rm \{\} +
WARNING:test command found but not installed in testenv
  cmd: /usr/bin/find
  env: /Users/.../dev/.../.tox/py26
Maybe forgot to specify a dependency?
find: -exec: no terminating ";" or "+"
ERROR: InvocationError: '/usr/bin/find /Users/.../dev/.../.tox/py26 -name *.so -exec rm \\{\\} +'

Having "{}" in the tox command breaks since tox looks for a variable named "" in the config. The above is the result of attempting to escape the curly braces with back-slashes, as per the documentation: You can escape curly braces with the \ character if you need them, ...

My environment:

  • OSX 10.8
  • Python 3.4.2 (installed via pyenv)
  • tox 1.8.1 (installed via pip)

Comments (13)

  1. kjwilcox

    Encountered this on tox 2.1.1 on ubuntu 14.04 python 2.7.6.

    Made use of find -exec impossible since the slashes were leaked through. Managed to work around with -execdir, since that doesn't require the brackets.

  2. kjwilcox

    I managed to find a "better" workaround by invoking bash in the tox.ini

    bash -c \'find {envsitepackagesdir} -name my_directory_criteria -type d -print0 | xargs -0 django-admin.py test [] \'

  3. John Vandenberg

    Before that commit in 1.8.x, \{..\} would produce

    Traceback (most recent call last):
      File "/usr/bin/tox", line 9, in <module>
        load_entry_point('tox==1.8.0', 'console_scripts', 'tox')()
      File "/usr/lib/python2.7/site-packages/tox/_cmdline.py", line 25, in main
        config = parseconfig(args, 'tox')
      File "/usr/lib/python2.7/site-packages/tox/_config.py", line 42, in parseconfig
        parseini(config, inipath)
      File "/usr/lib/python2.7/site-packages/tox/_config.py", line 296, in __init__
        self._makeenvconfig(name, section, reader._subs, config)
      File "/usr/lib/python2.7/site-packages/tox/_config.py", line 359, in _makeenvconfig
        vc.commands = reader.getargvlist(section, "commands")
      File "/usr/lib/python2.7/site-packages/tox/_config.py", line 552, in getargvlist
        commandlist.append(self._processcommand(current_command))
      File "/usr/lib/python2.7/site-packages/tox/_config.py", line 581, in _processcommand
        new_word = self._replace(word)
      File "/usr/lib/python2.7/site-packages/tox/_config.py", line 730, in _replace
        return RE_ITEM_REF.sub(self._replace_match, x)
      File "/usr/lib/python2.7/site-packages/tox/_config.py", line 726, in _replace_match
        return handler(match)
      File "/usr/lib/python2.7/site-packages/tox/_config.py", line 697, in _replace_substitution
        val = self._substitute_from_other_section(sub_key)
      File "/usr/lib/python2.7/site-packages/tox/_config.py", line 686, in _substitute_from_other_section
        return self._replace(x)
      File "/usr/lib/python2.7/site-packages/tox/_config.py", line 730, in _replace
        return RE_ITEM_REF.sub(self._replace_match, x)
      File "/usr/lib/python2.7/site-packages/tox/_config.py", line 726, in _replace_match
        return handler(match)
      File "/usr/lib/python2.7/site-packages/tox/_config.py", line 697, in _replace_substitution
        val = self._substitute_from_other_section(sub_key)
      File "/usr/lib/python2.7/site-packages/tox/_config.py", line 691, in _substitute_from_other_section
        "substitution key %r not found" % key)
    tox.ConfigError: ConfigError: substitution key '\\' not found
    

    So it looks like it was a partial fix, avoiding the config layer claiming it as substitution, but the un-quoting part of the fix wasnt done.

  4. John Vandenberg

    A reasonable way to avoid this being a breaking change is to use {{..}} as the way to add literals, as that is the same syntax as str.format, and I am guessing that '{foo}' is an illegal variable name (or at least it is an improbable and silly name to be in use as a variable name.).

  5. Holger Krekel repo owner

    add changelog entry for latest PR merge: fix issue212: allow escaping curly brace chars "{" and "}" if you need the chars "{" and "}" to appear in your commands or other ini values. Thanks John Vandenberg.

    → <<cset b609deef30f3>>

  6. Log in to comment