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

hash / number sign cannot be escaped in tox.ini #181

Closed
pytoxbot opened this issue Sep 17, 2016 · 8 comments
Closed

hash / number sign cannot be escaped in tox.ini #181

pytoxbot opened this issue Sep 17, 2016 · 8 comments

Comments

@pytoxbot
Copy link

The tox.ini parser does not provide a way to use the #-character as it is always interpreted as comment-begin.

The built-in python ini parser avoids the problem altogether by allowing comments to only start at line beginning.

With pip urls often containing the character this breaks several use cases.

@pytoxbot
Copy link
Author

Original comment by @hpk42

Merged in dstanek/tox/bug_181 (pull request #174)

Fixes bug 181; allow # in commands

→ <>

1 similar comment
@pytoxbot
Copy link
Author

Original comment by @hpk42

Merged in dstanek/tox/bug_181 (pull request #174)

Fixes bug 181; allow # in commands

→ <>

@pytoxbot
Copy link
Author

Original comment by @hpk42

Fixes bug 181; allow # in commands

If a # was in a command the original code naively removed it and
everything after assuming it was a comment. This meant that a #
could not be used in a command even if it was quoted or escaped.

This fix is backward incompatible because it no longer allows a
comment to appear after a line escape (). I think is is acceptable
because in most other environments a backslash would preceed a
newline to escape it and tell the interpreter to ignore it. This
brings tox's command behavior more in line with what Unix shells
or Python actually do.

→ <<cset 267db03b41e9>>

@pytoxbot
Copy link
Author

Original comment by @dstanek

I created a fix and submitted a pull request for this: https://bitbucket.org/hpk42/tox/pull-requests/174

@pytoxbot
Copy link
Author

Original comment by ludwigf

The current parser does ignore everything after # without a way to escape it.

Good for:

python test.py  # execute python test script

Bad for:

python -c 'print "i like # in my command"'

@pytoxbot
Copy link
Author

Original comment by @hpk42

Is this a problem for "deps" specifically? Just tried putting "#" in commands and that didn't cause problems. IOW, do you have a specific example?

(i agree we should probably go do things similar as the default parser but doing that now might break existing tox.ini files so i'd like to see how we can best advance now).

@jaraco
Copy link

jaraco commented Sep 9, 2019

I can't tell what the disposition of this is, but in my testing, it's still an issue. I used this tox testenv:

[testenv:hashsign]
skip_install = True
commands =
    python -c "import sys; print(sys.argv)" foo_\{name\}##bar

And I get this output:

$ tox -e hashsign                                                                                                        
hashsign run-test-pre: PYTHONHASHSEED='3983621339'
hashsign run-test: commands[0] | python -c 'import sys; print(sys.argv)' 'foo_{name}'
['-c', 'foo_{name}']
__________________________________________________________________ summary __________________________________________________________________
  hashsign: commands succeeded
  congratulations :)

My actual use-case is I want to pass a URL template to a command, a URL with a fragment:

commands =
    python -m jaraco.tidelift.publish-release-notes --template https://github.com/jaraco/configparser/blob/master/CHANGES.rst#v\{flat_ver\}

Is there a way to put # in a tox ini file?

@jaraco
Copy link

jaraco commented Sep 9, 2019

I found the answer in this stackoverflow answer. Wrap the result in ".

[testenv:hashsign]
skip_install = True
commands =
    python -c "import sys; print(sys.argv)" "foo_\{name\}##bar"
$ tox -e hashsign                                                                                                        
hashsign run-test-pre: PYTHONHASHSEED='3039365501'
hashsign run-test: commands[0] | python -c 'import sys; print(sys.argv)' 'foo_{name}##bar'
['-c', 'foo_{name}##bar']
__________________________________________________________________ summary __________________________________________________________________
  hashsign: commands succeeded
  congratulations :)

@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
Development

No branches or pull requests

2 participants