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

escaping curly braces in a tox command doesn't work #212

Closed
pytoxbot opened this issue Sep 17, 2016 · 10 comments · Fixed by dropseed/sweep#11
Closed

escaping curly braces in a tox command doesn't work #212

pytoxbot opened this issue Sep 17, 2016 · 10 comments · Fixed by dropseed/sweep#11

Comments

@pytoxbot
Copy link

@pytoxbot pytoxbot commented Sep 17, 2016

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)
@pytoxbot
Copy link
Author

@pytoxbot pytoxbot commented Sep 17, 2016

Original comment by @hpk42

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.

→ <>

@pytoxbot
Copy link
Author

@pytoxbot pytoxbot commented Sep 17, 2016

Original comment by @msabramo

I don't depend on the current functionality.

@pytoxbot pytoxbot closed this Sep 17, 2016
@pytoxbot
Copy link
Author

@pytoxbot pytoxbot commented Sep 17, 2016

Original comment by @jayvdb

using {{..}} would also be a breaking change, as that is legal syntax; see https://bitbucket.org/hpk42/tox/pull-requests/186

@pytoxbot
Copy link
Author

@pytoxbot pytoxbot commented Sep 17, 2016

Original comment by @jayvdb

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.).

@pytoxbot
Copy link
Author

@pytoxbot pytoxbot commented Sep 17, 2016

Original comment by @jayvdb

The problem will be how to fix this, without breaking anyone who relies on the current approach. @msabramo, do you depend on the current functionality as you implemented it?

@pytoxbot
Copy link
Author

@pytoxbot pytoxbot commented Sep 17, 2016

Original comment by @jayvdb

https://bitbucket.org/hpk42/tox/pull-requests/185 fixes this for me

@pytoxbot
Copy link
Author

@pytoxbot pytoxbot commented Sep 17, 2016

Original comment by @jayvdb

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.

@pytoxbot
Copy link
Author

@pytoxbot pytoxbot commented Sep 17, 2016

Original comment by @jayvdb

It looks like this feature was introduced in https://bitbucket.org/hpk42/tox/commits/9d7345ef4b2be4f12a30a887fcda30c7b268c245 , and tests in https://bitbucket.org/hpk42/tox/commits/0c8a958f574b9d25eb16343e318cf88495087bd5

However I also cant find any version of tox, or tox incantation, where it works as explained in the documentation.

@pytoxbot
Copy link
Author

@pytoxbot pytoxbot commented Sep 17, 2016

Original comment by 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 [] '

@pytoxbot
Copy link
Author

@pytoxbot pytoxbot commented Sep 17, 2016

Original comment by 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.

@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
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

1 participant