Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix relative path in local channel #3540

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -621,6 +621,19 @@ def 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
Loading