Skip to content

Commit

Permalink
Fix relative path in local channels
Browse files Browse the repository at this point in the history
  • Loading branch information
Hind-M committed Oct 21, 2024
1 parent 607c390 commit 9c00786
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
9 changes: 8 additions & 1 deletion libmamba/src/specs/unresolved_channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,14 @@ namespace mamba::specs

auto parse_path(std::string_view str) -> std::string
{
auto out = util::path_to_posix(fs::u8path(str).lexically_normal().string());
auto out = fs::u8path(str).lexically_normal().string();
// Using `lexically_normal()` removes the information of the relative path
// => adding it back if originally there
if (str.substr(0, 2) == "./")
{
out = "./" + out;
}
out = util::path_to_posix(out);
out = util::rstrip(out, '/');
return out;
}
Expand Down
10 changes: 9 additions & 1 deletion libmamba/tests/src/specs/test_unresolved_channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,15 @@ TEST_SUITE("specs::unresolved_channel")
{
const auto uc = UnresolvedChannel::parse("./folder/../folder/.").value();
CHECK_EQ(uc.type(), Type::Path);
CHECK_EQ(uc.location(), "folder");
CHECK_EQ(uc.location(), "./folder");
CHECK_EQ(uc.platform_filters(), PlatformSet{});
}

SUBCASE("./folder/subfolder/")
{
const auto uc = UnresolvedChannel::parse("./folder/subfolder/").value();
CHECK_EQ(uc.type(), Type::Path);
CHECK_EQ(uc.location(), "./folder/subfolder");
CHECK_EQ(uc.platform_filters(), PlatformSet{});
}

Expand Down
13 changes: 13 additions & 0 deletions micromamba/tests/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,19 @@ def test_install_local_package(self):
res = helpers.install(f"file://{file_path}", "--json", default_channel=False)
assert "cph_test_data" in {pkg["name"] for pkg in res["actions"]["LINK"]}

def test_install_local_package_relative_path(self):
"""Attempts to install a locally built package from a relative local path."""
spec = "./micromamba/tests/test-server/repo::test-package"
res = helpers.install(spec, "--json", default_channel=False)
assert res["success"]

pkgs = res["actions"]["LINK"]
assert len(pkgs) == 1
pkg = pkgs[0]
assert pkg["name"] == "test-package"
assert pkg["version"] == "0.1"
assert pkg["url"].startswith("file://")

def test_force_reinstall(self, existing_cache):
"""Force reinstall installs existing package again."""
res = helpers.install("xtensor", "--json")
Expand Down

0 comments on commit 9c00786

Please sign in to comment.