nat-n / poethepoet

A task runner that works well with poetry.
https://poethepoet.natn.io/
MIT License
1.45k stars 59 forks source link

cmd task: Strip quotes from token on Windows #145

Closed ameily closed 1 year ago

ameily commented 1 year ago

I found an issue related to #16 where, on Windows, a quoted token is being passed to the command still wrapped in quotes. This only happens on Windows because the shelx.split(posix=False) preserves them. You can verify this issue on Windows with the poethepoety test-quick task, which passes a quotes string to pytest and fails because the marker contains an invalid quote character:

Poe => pytest --cov=poethepoet -m "not slow"
# ... cut ...
ERROR: Wrong expression passed to '-m': "not slow": at column 1: unexpected character ""

I initially was seeing this with a call to cspell and have reproduced it with a small script / task.

# args.py
import sys
print(sys.argv)
# pyproject.toml
[tool.poe.tasks.args]
cmd = "python args.py \"hello world\" \"some/glob/**/*.py\""

The results of running the args task show that, on Windows, the quotes are preserved when they should be stripped.

$ poetry poe args
Poe => python args.py "hello world" "some/glob/**/*.py"
['args.py', '"hello world"', '"some/glob/**/*.py"']

I tried using some of the examples from #16 but I couldn't get them to work in my case, either the glob was being expanded by poe or the quote characters were being passed to the subprocess.

ameily commented 1 year ago

It looks like the Windows tests are failing because they expect the quoted behavior in stdout. If you're ok with my change, I'll update the tests and get them passing.

nat-n commented 1 year ago

Hi @ameily, thanks for working on this! If you fix the tests I'd be happy to merge it.

ameily commented 1 year ago

This should be good to go. Thanks for maintaining poe and being responsive! I useit for several Windows and Linux projects.