dsa-ou / algoesup

Algorithmic essays support: examples, templates, guides, library
https://dsa-ou.github.io/algoesup/
BSD 3-Clause "New" or "Revised" License
2 stars 0 forks source link

"incomplete escape sequence" error for `%allowed` on Windows #16

Closed densnow closed 7 months ago

densnow commented 7 months ago

Using %allowed on Windows in Jupyter Notebook prints the following error:

Error on executing allowed  C:\Users\<username>\AppData\Local\Temp\tmppsw754ap.py:
incomplete escape \U at position 4

It's picking up the \U from \Users as an escape sequence. This appears to be a result of setting the shell=true arg in subprocess.run(), and passing the command as a concatenated string which is directly interpreted by the shell (including escape sequences).

If we set shell=false, we can (Hopefully) bypass the shell, and instead of passing a concatenated string we should pass a list of args starting with the executable.

See subprocesses - frequently used arguments for reference.

mwermelinger commented 7 months ago

Thanks for spotting. If you fix it for Windows and test on Linux, I can then test on macOS.

densnow commented 7 months ago

Everything in the first comment is true and using a list of args seems to be the best practice, but it did not solve the issue.

In the end I had to replace all instances of "\" with "/" in the temp file path. Windows can accept both as path separators, iand AFAIK "\" are not allowed in filenames or directory names on Windows, mac and Linux.