From 8ce504d80816387584ac93f96129a58bdf6b507a Mon Sep 17 00:00:00 2001 From: AntoinePrv Date: Thu, 31 Aug 2023 19:05:18 +0200 Subject: [PATCH] Fix path spearator on Win Posix shells --- libmamba/src/core/shell_init.cpp | 9 +++++---- micromamba/tests/test_shell.py | 11 ++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/libmamba/src/core/shell_init.cpp b/libmamba/src/core/shell_init.cpp index 6aa3c34e2f..ec6c58bfcc 100644 --- a/libmamba/src/core/shell_init.cpp +++ b/libmamba/src/core/shell_init.cpp @@ -26,6 +26,7 @@ #include "mamba/core/util.hpp" #include "mamba/core/util_os.hpp" #include "mamba/util/build.hpp" +#include "mamba/util/path_manip.hpp" #include "mamba/util/string.hpp" namespace mamba @@ -533,21 +534,21 @@ namespace mamba { std::string contents = data_micromamba_sh; // Using /unix/like/paths on Unix shell (even on Windows) - util::replace_all(contents, "$MAMBA_EXE", exe.generic_string()); + util::replace_all(contents, "$MAMBA_EXE", util::path_to_posix(exe.string())); return contents; } else if (shell == "csh") { std::string contents = data_micromamba_csh; // Using /unix/like/paths on Unix shell (even on Windows) - util::replace_all(contents, "$MAMBA_EXE", exe.generic_string()); + util::replace_all(contents, "$MAMBA_EXE", util::path_to_posix(exe.string())); return contents; } else if (shell == "xonsh") { std::string contents = data_mamba_xsh; // Using /unix/like/paths on Unix shell (even on Windows) - util::replace_all(contents, "$MAMBA_EXE", exe.generic_string()); + util::replace_all(contents, "$MAMBA_EXE", util::path_to_posix(exe.string())); return contents; } else if (shell == "powershell") @@ -574,7 +575,7 @@ namespace mamba { std::string contents = data_mamba_fish; // Using /unix/like/paths on Unix shell (even on Windows) - util::replace_all(contents, "$MAMBA_EXE", exe.generic_string()); + util::replace_all(contents, "$MAMBA_EXE", util::path_to_posix(exe.string())); return contents; } return ""; diff --git a/micromamba/tests/test_shell.py b/micromamba/tests/test_shell.py index 5c8993a937..a2e972257f 100644 --- a/micromamba/tests/test_shell.py +++ b/micromamba/tests/test_shell.py @@ -3,7 +3,7 @@ import platform import shutil import subprocess -from pathlib import Path +from pathlib import Path, PureWindowsPath import pytest @@ -32,6 +32,7 @@ def test_hook(tmp_home, tmp_root_prefix, shell_type): res = helpers.shell("hook", "-s", shell_type) mamba_exe = helpers.get_umamba() + mamba_exe_posix = PureWindowsPath(mamba_exe).as_posix() # suspend long path support on Windows # if platform.system() == "Windows": # mamba_exe = f"\\\\?\\{mamba_exe}" @@ -43,15 +44,15 @@ def test_hook(tmp_home, tmp_root_prefix, shell_type): assert not any(li.startswith("## EXPORTS ##") for li in lines) assert lines[2].startswith("## AFTER PARAM ####") elif shell_type in ("zsh", "bash", "posix"): - assert res.count(mamba_exe) == 3 + assert res.count(mamba_exe_posix) == 3 elif shell_type == "xonsh": - assert res.count(mamba_exe) == 8 + assert res.count(mamba_exe_posix) == 8 elif shell_type == "fish": - assert res.count(mamba_exe) == 5 + assert res.count(mamba_exe_posix) == 5 elif shell_type == "cmd.exe": assert res == "" elif shell_type == "tcsh": - assert res.count(mamba_exe) == 3 + assert res.count(mamba_exe_posix) == 3 res = helpers.shell("hook", "-s", shell_type, "--json") expected_keys = {"success", "operation", "context", "actions"}