fixing malparsed windows paths - #4374
Conversation
| source_dir = entry['directory'] | ||
|
|
||
| options = shlex.split(entry['command']) | ||
| options = shlex.split(entry['command'], posix=(os.name=='posix')) |
There was a problem hiding this comment.
The posix= parameter is designed to manage nuances between different Unix shells, so it's very mysterious how this helps with Windows and why?!
I realize this is still just a draft, but some... draft comments and a commit message draft would not hurt.
Generally speaking, shlex is NOT meant to help prepare Windows commands ("outputs"). According to its documentation, it's meant as a convenience to help parsing inputs to the program, like a simple configuration file or some parameters.
https://docs.python.org/3/library/shlex.html
Longer example of shlex abuse and Windows compatibility story in zephyrproject-rtos/west@94f8a04
There was a problem hiding this comment.
@marc-h38
"The posix= parameter is designed to manage nuances between different Unix shells, so it's very mysterious how this helps with Windows and why?!"
When the posix=false is not passed on windows, shlex is eating up back slashes:
here is some related issue:
#mesonbuild/meson#5726
There was a problem hiding this comment.
The posix= parameter is designed to manage nuances between different Unix shells,
Correction: posix=True means backwards-compatibility=False. This could/should be better documented. I found the evidence here:
python/cpython#38314 (comment)
so it's very mysterious how this helps with Windows and why?!
When the posix=false is not passed on windows, shlex is eating up back slashes:
Right, escaping rules are different between posix and non-posix:
https://docs.python.org/3/library/shlex.html#parsing-rules
However this is just one difference among a long list of other differences. shlex is effectively two pretty different parsers in one. Those other differences should be understood and evaluated in this particular context and the commit message should tell that story. When not, the "Pragrammatic Programmer" book names this "programming by coincidence".
Or maybe I should say "called" in the past tense now since AI is writing all the code ;-)
There was a problem hiding this comment.
here is some related issue: #mesonbuild/meson#5726
Apparently, the fix there was to stop (ab)using shlex for cases it was not designed to handle, and replace it with something else entirely.

Fixes #4277