Skip to content

mpremote mkdir crashes on Windows if path does not start with : #17093

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

Open
Josverl opened this issue Apr 8, 2025 · 11 comments
Open

mpremote mkdir crashes on Windows if path does not start with : #17093

Josverl opened this issue Apr 8, 2025 · 11 comments
Labels

Comments

@Josverl
Copy link
Contributor

Josverl commented Apr 8, 2025

Port, board and/or hardware

Any, verified on esp32 and stm32

MicroPython version

mpflash list --json

[
{
"serialport": "COM24",
"connected": true,
"family": "micropython",
"description": "PYBv1.1 with STM32F405RG",
"version": "1.25.0-preview",
"port": "stm32",
"board": "PYBV11",
"variant": "DP_THREAD",
"cpu": "STM32F405RG",
"arch": "armv7emsp",
"mpy": "v6.3",
"build": "389",
"location": "1-6.1.1:x.1",
"toml": {}
}
]

Reproduction

The mip local install crashes in Git Bash on Windows

mpremote run "./ramdisk.py"
mpremote resume mkdir /ramdisk/lib

Note that this problem does NOT occur on Windows Powershell , it is Git Bash specific.

(this also means that Git bash is not a reliable tests environment for windows as a whole.)

Expected behaviour

Expected to create a folder in the ramdisk

Observed behaviour

EUROPE+josverl@josverl-sb5 MINGW64 /d/mypython/micropython/tools/mpremote/tests (mpremote-testfix)
$ mpremote run "./ramdisk.py"
mpremote resume mkdir /ramdisk/lib
mkdir :C:/Program Files/Git/ramdisk/lib
mpremote: Error with transport:
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
OSError: [Errno 22] EINVAL


mpremote resume mkdir :/ramdisk/lib
mkdir :/ramdisk/lib

Additional Information

discovered during attempts to test mpremote on windows.

Code of Conduct

Yes, I agree

@AJMansfield
Copy link
Contributor

Could you rerun your scenario with set -x tracing enabled and post the results?

@Josverl
Copy link
Contributor Author

Josverl commented Apr 9, 2025

just for clarity: This report is for the error in mpremote, not regarding the bash test harness.
So the bash tracing does not show much
I think the root cause is Git Bash

the workaround is simple: use a : prefix for mpremote mkdir :</absolute/path>

I Suggest to:

  • Add this to the mpremote docs
  • update the mpremote test to use a : path prefix ,
  • or handle the error as XFAIL on git bash ( requires a different test framework)

if I set a breakpoint on entry and look at the arguments passed to Python
For a command line of : mpremote resume mkdir /ramdisk/lib

sys.argv
['D:\\mypython\\micropython\\tools\\mpremote\\mpremote\\__main__.py', 'resume', 'mkdir', 'C:/Program Files/Git/ramdisk/lib']
special variables
function variables
0 ='D:\\mypython\\micropython\\tools\\mpremote\\mpremote\\__main__.py'
1 = 'resume'
2 ='mkdir'
3 ='C:/Program Files/Git/ramdisk/lib'
len() =4

I syspect that this is a (unexpected) side effect ot the way Git bash tries to translate absolute paths between the Posix universe with a single tree , and the Windows universe that allows both drive letters , and mount points.

#Git Bash
$ mount
C:/Program Files/Git on / type ntfs (binary,noacl,auto)
C:/Program Files/Git/usr/bin on /bin type ntfs (binary,noacl,auto)
C:/Users/josverl/AppData/Local/Temp on /tmp type ntfs (binary,noacl,posix=0,usertemp)
C: on /c type ntfs (binary,noacl,posix=0,user,noumount,auto)
D: on /d type refs (binary,noacl,posix=0,user,noumount,auto)
E: on /e type ntfs (binary,noacl,posix=0,user,noumount,auto)
F: on /f type vfat (binary,noacl,posix=0,user,noumount,auto)
bash Details

likely not relevant as explained above

$ set -x; mpremote resume mkdir /ramdisk/lib;set +x
++ __vsc_preexec_only -x
++ '[' 1 = 0 ']'
+ mpremote resume mkdir /ramdisk/lib
mkdir :C:/Program Files/Git/ramdisk/lib
mpremote: Error with transport:
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
OSError: [Errno 22] EINVAL

++ __vsc_preexec_only /ramdisk/lib
++ '[' 1 = 0 ']'
+ set +x

@AJMansfield
Copy link
Contributor

AJMansfield commented Apr 9, 2025

This is a bizarre bug. I've checked, this also happens with jq but NOT with the utilities that ship with Git Bash.
It also doesn't happen with other windows bash shells, e.g. the one included in the GAP runtime doesn't have this problem at all.

Ordinary quoting doesn't seem to prevent it -- <command> '/ramdisk/lib' is still expanded, and so is <command> "/ramdisk/lib".
<command> \'/ramdisk/lib\' (or the expansion generated by @Q) does pass intact, but the quote characters are then interpreted as actual characters in the name of a relative path element.

Test Script
#!/bin/bash
set -x
cat <<<'==================== Test Script ===================='
TEST_SH=$(mktemp --suffix=.sh)
tee $TEST_SH <<'TEST_SH'
set -x
f=/ramdisk/lib

ECHO_EXE=$(mktemp --suffix=.exe)
cp $(which echo) $ECHO_EXE

GREP_TXT=$(mktemp --suffix=.txt)
tee $GREP_TXT <<GREP_TXT
C:/Program Files/Git$f
did not expand $f if this line appears
GREP_TXT

ARGS_PY=$(mktemp --suffix=.py)
tee $ARGS_PY <<ARGS_PY
import sys
print(sys.argv)
ARGS_PY

cat <<<'--------------- echo: shell builtin? ----------------'
echo $f
echo ${f@Q}
echo \'$f\'

cat <<<'------------------ echo: echo.exe -------------------'
$ECHO_EXE $f
$ECHO_EXE ${f@Q}
$ECHO_EXE \'$f\'

cat <<<'----------- grep: winget install Git.Git ------------'
grep -F $f <$GREP_TXT
grep -F ${f@Q} <$GREP_TXT
grep -F \'$f\' <$GREP_TXT

cat <<<'---- python: winget install Anaconda.Miniconda3 -----'
python $ARG_PY -- $f
python $ARG_PY -- ${f@Q}
python $ARG_PY -- \'$f\'

cat <<<'----------- jq: winget install jqlang.jq ------------'
jq '{"file":input_filename}' $f
jq '{"file":input_filename}' ${f@Q}
jq '{"file":input_filename}' \'$f\'
TEST_SH

cat <<<'=================== Git /bin/bash ==================='
'C:/Program Files/Git/bin/bash.exe' $TEST_SH

cat <<<'================= Git /usr/bin/bash ================='
'C:/Program Files/Git/usr/bin/bash.exe' $TEST_SH

cat <<<'=============== GAP Runtime /bin/bash ==============='
"C:/Program Files/GAP-v4.12.2/runtime/bin/bash.exe" $TEST_SH
Test Output
+ cat
==================== Test Script ====================
++ mktemp --suffix=.sh
+ TEST_SH=/tmp/tmp.lk3e6ypFTY.sh
+ tee /tmp/tmp.lk3e6ypFTY.sh
set -x
f=/ramdisk/lib

ECHO_EXE=$(mktemp --suffix=.exe)
cp $(which echo) $ECHO_EXE

GREP_TXT=$(mktemp --suffix=.txt)
tee $GREP_TXT <<GREP_TXT
C:/Program Files/Git$f
did not expand $f if this line appears
GREP_TXT

ARGS_PY=$(mktemp --suffix=.py)
tee $ARGS_PY <<ARGS_PY
import sys
print(sys.argv)
ARGS_PY

cat <<<'--------------- echo: shell builtin? ----------------'
echo $f
echo ${f@Q}
echo \'$f\'

cat <<<'------------------ echo: echo.exe -------------------'
$ECHO_EXE $f
$ECHO_EXE ${f@Q}
$ECHO_EXE \'$f\'

cat <<<'----------- grep: winget install Git.Git ------------'
grep -F $f <$GREP_TXT
grep -F ${f@Q} <$GREP_TXT
grep -F \'$f\' <$GREP_TXT

cat <<<'---- python: winget install Anaconda.Miniconda3 -----'
python $ARG_PY -- $f
python $ARG_PY -- ${f@Q}
python $ARG_PY -- \'$f\'

cat <<<'----------- jq: winget install jqlang.jq ------------'
jq '{"file":input_filename}' $f
jq '{"file":input_filename}' ${f@Q}
jq '{"file":input_filename}' \'$f\'
+ cat
=================== Git /bin/bash ===================
+ 'C:/Program Files/Git/bin/bash.exe' /tmp/tmp.lk3e6ypFTY.sh
+ f=/ramdisk/lib
++ mktemp --suffix=.exe
+ ECHO_EXE=/tmp/tmp.PmFDkbSI3e.exe
++ which echo
+ cp /usr/bin/echo /tmp/tmp.PmFDkbSI3e.exe
++ mktemp --suffix=.txt
+ GREP_TXT=/tmp/tmp.2rfKR4vkkb.txt
+ tee /tmp/tmp.2rfKR4vkkb.txt
C:/Program Files/Git/ramdisk/lib
did not expand /ramdisk/lib if this line appears
++ mktemp --suffix=.py
+ ARGS_PY=/tmp/tmp.1PcpR8OhaP.py
+ tee /tmp/tmp.1PcpR8OhaP.py
import sys
print(sys.argv)
+ cat
--------------- echo: shell builtin? ----------------
+ echo /ramdisk/lib
/ramdisk/lib
+ echo ''\''/ramdisk/lib'\'''
'/ramdisk/lib'
+ echo ''\''/ramdisk/lib'\'''
'/ramdisk/lib'
+ cat
------------------ echo: echo.exe -------------------
+ /tmp/tmp.PmFDkbSI3e.exe /ramdisk/lib
/ramdisk/lib
+ /tmp/tmp.PmFDkbSI3e.exe ''\''/ramdisk/lib'\'''
'/ramdisk/lib'
+ /tmp/tmp.PmFDkbSI3e.exe ''\''/ramdisk/lib'\'''
'/ramdisk/lib'
+ cat
----------- grep: winget install Git.Git ------------
+ grep -F /ramdisk/lib
C:/Program Files/Git/ramdisk/lib
did not expand /ramdisk/lib if this line appears
+ grep -F ''\''/ramdisk/lib'\'''
+ grep -F ''\''/ramdisk/lib'\'''
+ cat
---- python: winget install Anaconda.Miniconda3 -----
+ python -- /ramdisk/lib
C:\Users\anson\anaconda3\envs\py311\python.exe: can't open file 'C:\\Program Files\\Git\\ramdisk\\lib': [Errno 2] No such file or directory
+ python -- ''\''/ramdisk/lib'\'''
C:\Users\anson\anaconda3\envs\py311\python.exe: can't open file "C:\\Users\\anson\\'\\ramdisk\\lib'": [Errno 2] No such file or directory
+ python -- ''\''/ramdisk/lib'\'''
C:\Users\anson\anaconda3\envs\py311\python.exe: can't open file "C:\\Users\\anson\\'\\ramdisk\\lib'": [Errno 2] No such file or directory
+ cat
----------- jq: winget install jqlang.jq ------------
+ jq '{"file":input_filename}' /ramdisk/lib
jq: error: Could not open file C:/Program Files/Git/ramdisk/lib: No such file or directory
+ jq '{"file":input_filename}' ''\''/ramdisk/lib'\'''
jq: error: Could not open file '/ramdisk/lib': No such file or directory
+ jq '{"file":input_filename}' ''\''/ramdisk/lib'\'''
jq: error: Could not open file '/ramdisk/lib': No such file or directory
+ cat
================= Git /usr/bin/bash =================
+ 'C:/Program Files/Git/usr/bin/bash.exe' /tmp/tmp.lk3e6ypFTY.sh
+ f=/ramdisk/lib
++ mktemp --suffix=.exe
+ ECHO_EXE=/tmp/tmp.raBm24eVEw.exe
++ which echo
+ cp /usr/bin/echo /tmp/tmp.raBm24eVEw.exe
++ mktemp --suffix=.txt
+ GREP_TXT=/tmp/tmp.BBpae5HIWh.txt
+ tee /tmp/tmp.BBpae5HIWh.txt
C:/Program Files/Git/ramdisk/lib
did not expand /ramdisk/lib if this line appears
++ mktemp --suffix=.py
+ ARGS_PY=/tmp/tmp.nywNzhqlo5.py
+ tee /tmp/tmp.nywNzhqlo5.py
import sys
print(sys.argv)
+ cat
--------------- echo: shell builtin? ----------------
+ echo /ramdisk/lib
/ramdisk/lib
+ echo ''\''/ramdisk/lib'\'''
'/ramdisk/lib'
+ echo ''\''/ramdisk/lib'\'''
'/ramdisk/lib'
+ cat
------------------ echo: echo.exe -------------------
+ /tmp/tmp.raBm24eVEw.exe /ramdisk/lib
/ramdisk/lib
+ /tmp/tmp.raBm24eVEw.exe ''\''/ramdisk/lib'\'''
'/ramdisk/lib'
+ /tmp/tmp.raBm24eVEw.exe ''\''/ramdisk/lib'\'''
'/ramdisk/lib'
+ cat
----------- grep: winget install Git.Git ------------
+ grep -F /ramdisk/lib
C:/Program Files/Git/ramdisk/lib
did not expand /ramdisk/lib if this line appears
+ grep -F ''\''/ramdisk/lib'\'''
+ grep -F ''\''/ramdisk/lib'\'''
+ cat
---- python: winget install Anaconda.Miniconda3 -----
+ python -- /ramdisk/lib
C:\Users\anson\anaconda3\envs\py311\python.exe: can't open file 'C:\\Program Files\\Git\\ramdisk\\lib': [Errno 2] No such file or directory
+ python -- ''\''/ramdisk/lib'\'''
C:\Users\anson\anaconda3\envs\py311\python.exe: can't open file "C:\\Users\\anson\\'\\ramdisk\\lib'": [Errno 2] No such file or directory
+ python -- ''\''/ramdisk/lib'\'''
C:\Users\anson\anaconda3\envs\py311\python.exe: can't open file "C:\\Users\\anson\\'\\ramdisk\\lib'": [Errno 2] No such file or directory
+ cat
----------- jq: winget install jqlang.jq ------------
+ jq '{"file":input_filename}' /ramdisk/lib
jq: error: Could not open file C:/Program Files/Git/ramdisk/lib: No such file or directory
+ jq '{"file":input_filename}' ''\''/ramdisk/lib'\'''
jq: error: Could not open file '/ramdisk/lib': No such file or directory
+ jq '{"file":input_filename}' ''\''/ramdisk/lib'\'''
jq: error: Could not open file '/ramdisk/lib': No such file or directory
+ cat
=============== GAP Runtime /bin/bash ===============
+ 'C:/Program Files/GAP-v4.12.2/runtime/bin/bash.exe' /tmp/tmp.lk3e6ypFTY.sh
+ f=/ramdisk/lib
++ mktemp --suffix=.exe
+ ECHO_EXE=/tmp/tmp.9WMs52PPd9.exe
++ which echo
+ cp /usr/bin/echo /tmp/tmp.9WMs52PPd9.exe
++ mktemp --suffix=.txt
+ GREP_TXT=/tmp/tmp.SbcrYKdzIO.txt
+ tee /tmp/tmp.SbcrYKdzIO.txt
C:/Program Files/Git/ramdisk/lib
did not expand /ramdisk/lib if this line appears
++ mktemp --suffix=.py
+ ARGS_PY=/tmp/tmp.YF7qTMspx7.py
+ tee /tmp/tmp.YF7qTMspx7.py
import sys
print(sys.argv)
+ cat
--------------- echo: shell builtin? ----------------
+ echo /ramdisk/lib
/ramdisk/lib
+ echo ''\''/ramdisk/lib'\'''
'/ramdisk/lib'
+ echo ''\''/ramdisk/lib'\'''
'/ramdisk/lib'
+ cat
------------------ echo: echo.exe -------------------
+ /tmp/tmp.9WMs52PPd9.exe /ramdisk/lib
/ramdisk/lib
+ /tmp/tmp.9WMs52PPd9.exe ''\''/ramdisk/lib'\'''
/ramdisk/lib
+ /tmp/tmp.9WMs52PPd9.exe ''\''/ramdisk/lib'\'''
/ramdisk/lib
+ cat
----------- grep: winget install Git.Git ------------
+ grep -F /ramdisk/lib
C:/Program Files/Git/ramdisk/lib
did not expand /ramdisk/lib if this line appears
+ grep -F ''\''/ramdisk/lib'\'''
C:/Program Files/Git/ramdisk/lib
did not expand /ramdisk/lib if this line appears
+ grep -F ''\''/ramdisk/lib'\'''
C:/Program Files/Git/ramdisk/lib
did not expand /ramdisk/lib if this line appears
+ cat
---- python: winget install Anaconda.Miniconda3 -----
+ python -- /ramdisk/lib
C:\Users\anson\anaconda3\envs\py311\python.exe: can't open file 'C:\\ramdisk\\lib': [Errno 2] No such file or directory
+ python -- ''\''/ramdisk/lib'\'''
C:\Users\anson\anaconda3\envs\py311\python.exe: can't open file "C:\\Users\\anson\\'\\ramdisk\\lib'": [Errno 2] No such file or directory
+ python -- ''\''/ramdisk/lib'\'''
C:\Users\anson\anaconda3\envs\py311\python.exe: can't open file "C:\\Users\\anson\\'\\ramdisk\\lib'": [Errno 2] No such file or directory
+ cat
----------- jq: winget install jqlang.jq ------------
+ jq '{"file":input_filename}' /ramdisk/lib
jq: error: Could not open file /ramdisk/lib: No such file or directory
+ jq '{"file":input_filename}' ''\''/ramdisk/lib'\'''
jq: error: Could not open file '/ramdisk/lib': No such file or directory
+ jq '{"file":input_filename}' ''\''/ramdisk/lib'\'''
jq: error: Could not open file '/ramdisk/lib': No such file or directory

@AJMansfield
Copy link
Contributor

AJMansfield commented Apr 9, 2025

Deactivating my conda environment didn't change anything.

Test Output
+ cat
==================== Test Script ====================
++ mktemp --suffix=.sh
+ TEST_SH=/tmp/tmp.uzccWES4V2.sh
+ tee /tmp/tmp.uzccWES4V2.sh
set -x
f=/ramdisk/lib

ECHO_EXE=$(mktemp --suffix=.exe)
cp $(which echo) $ECHO_EXE

GREP_TXT=$(mktemp --suffix=.txt)
tee $GREP_TXT <<GREP_TXT
C:/Program Files/Git$f
did not expand $f if this line appears
GREP_TXT

ARGS_PY=$(mktemp --suffix=.py)
tee $ARGS_PY <<ARGS_PY
import sys
print(sys.argv)
ARGS_PY

cat <<<'--------------- echo: shell builtin? ----------------'
echo $f
echo ${f@Q}
echo \'$f\'

cat <<<'------------------ echo: echo.exe -------------------'
$ECHO_EXE $f
$ECHO_EXE ${f@Q}
$ECHO_EXE \'$f\'

cat <<<'----------- grep: winget install Git.Git ------------'
grep -F $f <$GREP_TXT
grep -F ${f@Q} <$GREP_TXT
grep -F \'$f\' <$GREP_TXT

cat <<<'---- python: winget install Anaconda.Miniconda3 -----'
python $ARG_PY -- $f
python $ARG_PY -- ${f@Q}
python $ARG_PY -- \'$f\'

cat <<<'----------- jq: winget install jqlang.jq ------------'
jq '{"file":input_filename}' $f
jq '{"file":input_filename}' ${f@Q}
jq '{"file":input_filename}' \'$f\'
+ cat
=================== Git /bin/bash ===================
+ 'C:/Program Files/Git/bin/bash.exe' /tmp/tmp.uzccWES4V2.sh
+ f=/ramdisk/lib
++ mktemp --suffix=.exe
+ ECHO_EXE=/tmp/tmp.2n0dUffToi.exe
++ which echo
+ cp /usr/bin/echo /tmp/tmp.2n0dUffToi.exe
++ mktemp --suffix=.txt
+ GREP_TXT=/tmp/tmp.TKf0XQyL6D.txt
+ tee /tmp/tmp.TKf0XQyL6D.txt
C:/Program Files/Git/ramdisk/lib
did not expand /ramdisk/lib if this line appears
++ mktemp --suffix=.py
+ ARGS_PY=/tmp/tmp.JjNMTsbgk3.py
+ tee /tmp/tmp.JjNMTsbgk3.py
import sys
print(sys.argv)
+ cat
--------------- echo: shell builtin? ----------------
+ echo /ramdisk/lib
/ramdisk/lib
+ echo ''\''/ramdisk/lib'\'''
'/ramdisk/lib'
+ echo ''\''/ramdisk/lib'\'''
'/ramdisk/lib'
+ cat
------------------ echo: echo.exe -------------------
+ /tmp/tmp.2n0dUffToi.exe /ramdisk/lib
/ramdisk/lib
+ /tmp/tmp.2n0dUffToi.exe ''\''/ramdisk/lib'\'''
'/ramdisk/lib'
+ /tmp/tmp.2n0dUffToi.exe ''\''/ramdisk/lib'\'''
'/ramdisk/lib'
+ cat
----------- grep: winget install Git.Git ------------
+ grep -F /ramdisk/lib
C:/Program Files/Git/ramdisk/lib
did not expand /ramdisk/lib if this line appears
+ grep -F ''\''/ramdisk/lib'\'''
+ grep -F ''\''/ramdisk/lib'\'''
+ cat
---- python: winget install Anaconda.Miniconda3 -----
+ python -- /ramdisk/lib
C:\Users\anson\anaconda3\python.exe: can't open file 'C:\\Program Files\\Git\\ramdisk\\lib': [Errno 2] No such file or directory
+ python -- ''\''/ramdisk/lib'\'''
C:\Users\anson\anaconda3\python.exe: can't open file "C:\\Users\\anson\\'\\ramdisk\\lib'": [Errno 2] No such file or directory
+ python -- ''\''/ramdisk/lib'\'''
C:\Users\anson\anaconda3\python.exe: can't open file "C:\\Users\\anson\\'\\ramdisk\\lib'": [Errno 2] No such file or directory
+ cat
----------- jq: winget install jqlang.jq ------------
+ jq '{"file":input_filename}' /ramdisk/lib
jq: error: Could not open file C:/Program Files/Git/ramdisk/lib: No such file or directory
+ jq '{"file":input_filename}' ''\''/ramdisk/lib'\'''
jq: error: Could not open file '/ramdisk/lib': No such file or directory
+ jq '{"file":input_filename}' ''\''/ramdisk/lib'\'''
jq: error: Could not open file '/ramdisk/lib': No such file or directory
+ cat
================= Git /usr/bin/bash =================
+ 'C:/Program Files/Git/usr/bin/bash.exe' /tmp/tmp.uzccWES4V2.sh
+ f=/ramdisk/lib
++ mktemp --suffix=.exe
+ ECHO_EXE=/tmp/tmp.6bgdoDNVxQ.exe
++ which echo
+ cp /usr/bin/echo /tmp/tmp.6bgdoDNVxQ.exe
++ mktemp --suffix=.txt
+ GREP_TXT=/tmp/tmp.KyDz7L1cMT.txt
+ tee /tmp/tmp.KyDz7L1cMT.txt
C:/Program Files/Git/ramdisk/lib
did not expand /ramdisk/lib if this line appears
++ mktemp --suffix=.py
+ ARGS_PY=/tmp/tmp.19JOuq4tiW.py
+ tee /tmp/tmp.19JOuq4tiW.py
import sys
print(sys.argv)
+ cat
--------------- echo: shell builtin? ----------------
+ echo /ramdisk/lib
/ramdisk/lib
+ echo ''\''/ramdisk/lib'\'''
'/ramdisk/lib'
+ echo ''\''/ramdisk/lib'\'''
'/ramdisk/lib'
+ cat
------------------ echo: echo.exe -------------------
+ /tmp/tmp.6bgdoDNVxQ.exe /ramdisk/lib
+ /tmp/tmp.6bgdoDNVxQ.exe ''\''/ramdisk/lib'\'''
+ /tmp/tmp.6bgdoDNVxQ.exe ''\''/ramdisk/lib'\'''
+ cat
----------- grep: winget install Git.Git ------------
+ grep -F /ramdisk/lib
C:/Program Files/Git/ramdisk/lib
did not expand /ramdisk/lib if this line appears
+ grep -F ''\''/ramdisk/lib'\'''
+ grep -F ''\''/ramdisk/lib'\'''
+ cat
---- python: winget install Anaconda.Miniconda3 -----
+ python -- /ramdisk/lib
C:\Users\anson\anaconda3\python.exe: can't open file 'C:\\Program Files\\Git\\ramdisk\\lib': [Errno 2] No such file or directory
+ python -- ''\''/ramdisk/lib'\'''
C:\Users\anson\anaconda3\python.exe: can't open file "C:\\Users\\anson\\'\\ramdisk\\lib'": [Errno 2] No such file or directory
+ python -- ''\''/ramdisk/lib'\'''
C:\Users\anson\anaconda3\python.exe: can't open file "C:\\Users\\anson\\'\\ramdisk\\lib'": [Errno 2] No such file or directory
+ cat
----------- jq: winget install jqlang.jq ------------
+ jq '{"file":input_filename}' /ramdisk/lib
jq: error: Could not open file C:/Program Files/Git/ramdisk/lib: No such file or directory
+ jq '{"file":input_filename}' ''\''/ramdisk/lib'\'''
jq: error: Could not open file '/ramdisk/lib': No such file or directory
+ jq '{"file":input_filename}' ''\''/ramdisk/lib'\'''
jq: error: Could not open file '/ramdisk/lib': No such file or directory
+ cat
=============== GAP Runtime /bin/bash ===============
+ 'C:/Program Files/GAP-v4.12.2/runtime/bin/bash.exe' /tmp/tmp.uzccWES4V2.sh
+ f=/ramdisk/lib
++ mktemp --suffix=.exe
+ ECHO_EXE=/tmp/tmp.A2T8P5Olgo.exe
++ which echo
+ cp /usr/bin/echo /tmp/tmp.A2T8P5Olgo.exe
++ mktemp --suffix=.txt
+ GREP_TXT=/tmp/tmp.SF3WOdenNf.txt
+ tee /tmp/tmp.SF3WOdenNf.txt
C:/Program Files/Git/ramdisk/lib
did not expand /ramdisk/lib if this line appears
++ mktemp --suffix=.py
+ ARGS_PY=/tmp/tmp.g9fRmy01LN.py
+ tee /tmp/tmp.g9fRmy01LN.py
import sys
print(sys.argv)
+ cat
--------------- echo: shell builtin? ----------------
+ echo /ramdisk/lib
/ramdisk/lib
+ echo ''\''/ramdisk/lib'\'''
'/ramdisk/lib'
+ echo ''\''/ramdisk/lib'\'''
'/ramdisk/lib'
+ cat
------------------ echo: echo.exe -------------------
+ /tmp/tmp.A2T8P5Olgo.exe /ramdisk/lib
+ /tmp/tmp.A2T8P5Olgo.exe ''\''/ramdisk/lib'\'''
+ /tmp/tmp.A2T8P5Olgo.exe ''\''/ramdisk/lib'\'''
+ cat
----------- grep: winget install Git.Git ------------
+ grep -F /ramdisk/lib
C:/Program Files/Git/ramdisk/lib
did not expand /ramdisk/lib if this line appears
+ grep -F ''\''/ramdisk/lib'\'''
C:/Program Files/Git/ramdisk/lib
did not expand /ramdisk/lib if this line appears
+ grep -F ''\''/ramdisk/lib'\'''
C:/Program Files/Git/ramdisk/lib
did not expand /ramdisk/lib if this line appears
+ cat
---- python: winget install Anaconda.Miniconda3 -----
+ python -- /ramdisk/lib
C:\Users\anson\anaconda3\python.exe: can't open file 'C:\\ramdisk\\lib': [Errno 2] No such file or directory
+ python -- ''\''/ramdisk/lib'\'''
C:\Users\anson\anaconda3\python.exe: can't open file "C:\\Users\\anson\\'\\ramdisk\\lib'": [Errno 2] No such file or directory
+ python -- ''\''/ramdisk/lib'\'''
C:\Users\anson\anaconda3\python.exe: can't open file "C:\\Users\\anson\\'\\ramdisk\\lib'": [Errno 2] No such file or directory
+ cat
----------- jq: winget install jqlang.jq ------------
+ jq '{"file":input_filename}' /ramdisk/lib
jq: error: Could not open file /ramdisk/lib: No such file or directory
+ jq '{"file":input_filename}' ''\''/ramdisk/lib'\'''
jq: error: Could not open file '/ramdisk/lib': No such file or directory
+ jq '{"file":input_filename}' ''\''/ramdisk/lib'\'''
jq: error: Could not open file '/ramdisk/lib': No such file or directory

There doesn't seem to be any shell options or configuration set within the shell that even correspond to this -- not even just some environment variable with a value like C:/Program Files/Git that could act as the source for how it's determining the prefix to use when converting arguments that appear to look like root paths.

@Josverl
Copy link
Contributor Author

Josverl commented Apr 9, 2025

Possibly in https://github.com/msys2/MSYS2-packages/tree/master/bash but not something we can solve here.

@Josverl
Copy link
Contributor Author

Josverl commented Apr 10, 2025

Please relabel as [Docs] [Tests]

@AJMansfield
Copy link
Contributor

Possibly in https://github.com/msys2/MSYS2-packages/tree/master/bash but not something we can solve here.

It's possible there's something we could do about it for our own package. I'm currently looking into how it is that the programs that ship as built-in MSYS2 utilities are able to accept their path-like arguments untransformed -- since, one way or another, they definitely do receive their arguments without the transformation that Git Bash applies when running other programs like python and jq.

@AJMansfield
Copy link
Contributor

AJMansfield commented Apr 11, 2025

Found a page that documents this feature of MSYS2, and environment variables that can switch it off:
https://www.msys2.org/docs/filesystem-paths/#windows-unix-path-conversion

@AJMansfield
Copy link
Contributor

Try:

MSYS2_ARG_CONV_EXCL='*' mpremote mkdir /ramdisk/lib

or

MSYS2_ARG_CONV_EXCL=/ mpremote mkdir /ramdisk/lib

@AJMansfield
Copy link
Contributor

Just got my own Windows build environment working.

I can confirm that setting MSYS2_ARG_CONV_EXCL=/ resolves this issue.

As a somewhat clumsy first pass at an approach to fix, we could maybe add a launcher script, e.g. a file like mpremote.sh next to mpremote.py with contents like:

MSYS2_ARG_CONV_EXCL=/ "${0%.sh}.py" "$@"

Compare:

anson@Milwaukee-Win MINGW64 /c/Users/anson/Projects/mpy/micropython
$ ./tools/mpremote/mpremote.py mkdir /ramdisk/lib
mkdir :C:/msys64/ramdisk/lib
mpremote: mkdir: C:/msys64/ramdisk/lib: No such file or directory.

anson@Milwaukee-Win MINGW64 /c/Users/anson/Projects/mpy/micropython
$ ./tools/mpremote/mpremote.sh mkdir /ramdisk/lib
mkdir :/ramdisk/lib
mpremote: mkdir: /ramdisk/lib: No such file or directory.

There might be a way to configure the [project.scripts] section of mpremote's pyproject.toml to get it to emit MSYS2_ARG_CONV_EXCL=/ as part of the shell alias the install command creates; I'll see if I can figure out how to do this.

@Josverl
Copy link
Contributor Author

Josverl commented Apr 14, 2025

I don't have time to test this now, but plan to look at this next week

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants