setup-msys2 icon indicating copy to clipboard operation
setup-msys2 copied to clipboard

Conflicts with pytest and WSL

Open eine opened this issue 4 years ago • 8 comments

Recently, GitHub added WSL to the virtual environment used in GitHub Actions (actions/virtual-environments#1081). As a result, C:\Windows\System32\bash.exe is created. This is NOT an issue for users of setup-msys2 with the default path-type or with strict. However, it might be conflictive for users of mode inherit.

Moreover, in Python, when pytest is used along with check_call(['bash',...]), it is resolved to C:\Windows\System32\bash.exe and it fails if the user has not explicitly configured WSL before. A workaround is to use which from shutil. See https://github.com/actions/virtual-environments/pull/1081#issuecomment-661524144.

Curiously, the problem is found in MINGW terminals only, not in MSYS. See https://github.com/msys2/setup-msys2/runs/892341986. I think it is because https://github.com/msys2/setup-msys2/runs/892341986?check_suite_focus=true#step:6:7 and https://github.com/msys2/setup-msys2/runs/892341966?check_suite_focus=true#step:6:7 (platform msys vs win32).

/cc @The-Compiler

eine avatar Jul 21 '20 12:07 eine

I'd guess cygwin (and thus the msys Python build) has it's own exe lookup and thus ignores the system directory. Since our bash is always first in our PATH, things shouldn't be a problem independent of pathtype.

Not sure if there is anything we can do here, except to suggest users to delete %SYSTEM32%\\bash.exe if it is a problem.

lazka avatar Jul 22 '20 06:07 lazka

@lazka, I did not check whether this is a problem with pytest only, or with any Python script which uses check_call or other resources from subprocess.

Not sure if there is anything we can do here, except to suggest users to delete %SYSTEM32%\bash.exe if it is a problem.

Using shutil.which('bash') instead of 'bash' solves the issue. If this is reproducible with any Python script that uses subprocess.* and 'bash', I believe we should add a comment in the README. If this is not specific to the virtual environment, but it can be reproduced on any host with MSYS2 and WSL, it might need to be documented somewhere else.

eine avatar Jul 22 '20 13:07 eine

@lazka, I did not check whether this is a problem with pytest only, or with any Python script which uses check_call or other resources from subprocess.

I'd guess any API which calls CreateProcess() internally. But, the question is why would any native Windows app call "bash.exe"? I'd guess that this is a corner case and/or hack in most cases.

lazka avatar Jul 22 '20 18:07 lazka

@lazka, the use case is using pytest in MINGW32/MINGW64 to handle multiple test scripts. Some are makefiles, other are python scripts, other are shell scripts. See https://github.com/msys2/setup-msys2/commit/c167722af9b757063fd9c0e21f6aeb689e9d076a. So, it is not a native Windows app, but a multiplatform testsuite composed mainly of a pytest script and shell/bash scripts.

eine avatar Jul 22 '20 18:07 eine

This is the result if bash is not called:

  • https://github.com/msys2/setup-msys2/commit/f01e00cfeb5344c03a54b1a3d419afc7a82addcb
  • https://github.com/msys2/setup-msys2/runs/899776128?check_suite_focus=true

eine avatar Jul 23 '20 01:07 eine

Ref msys2/msys2-autobuild#1

eine avatar Jul 27 '20 14:07 eine

I guess the only thing we can do here is add a section about bash.exe and tar.exe in the README.

lazka avatar Feb 26 '21 12:02 lazka

The WSL's bash.exe is also get confused with a meson build. CI runs System32/bash.exe while calling find_program() with a shell script. Here is the project's meson.build file https://github.com/Genymobile/scrcpy/blob/master/server/meson.build

Biswa96 avatar Dec 20 '21 04:12 Biswa96