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 21, 2023
1 parent 044824b commit 7340fe4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 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 @@ -595,21 +596,21 @@ def-env "micromamba deactivate" [] {
{
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 Down Expand Up @@ -637,7 +638,7 @@ def-env "micromamba deactivate" [] {
{
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;
}
else if (shell == "nu")
Expand Down
13 changes: 7 additions & 6 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,19 +44,19 @@ 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
elif shell_type == "nu":
# insert dummy test, as the nu scripts contains
# no mention of mamba_exe; path is added in config.nu
assert res.count(mamba_exe) == 0
assert res.count(mamba_exe_posix) == 0

res = helpers.shell("hook", "-s", shell_type, "--json")
expected_keys = {"success", "operation", "context", "actions"}
Expand Down

0 comments on commit 7340fe4

Please sign in to comment.