Skip to content

Commit

Permalink
Fix path spearator on Win Posix shells
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoinePrv committed Sep 4, 2023
1 parent 07ce0c4 commit 8ce504d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
9 changes: 5 additions & 4 deletions libmamba/src/core/shell_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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 "";
Expand Down
11 changes: 6 additions & 5 deletions micromamba/tests/test_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import platform
import shutil
import subprocess
from pathlib import Path
from pathlib import Path, PureWindowsPath

import pytest

Expand Down Expand Up @@ -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}"
Expand All @@ -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"}
Expand Down

0 comments on commit 8ce504d

Please sign in to comment.