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

Add no-pip flag to list command #3696

Merged
merged 1 commit into from
Dec 18, 2024
Merged
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
11 changes: 0 additions & 11 deletions libmamba/include/mamba/api/list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,6 @@ namespace mamba
class Context;

void list(Configuration& config, const std::string& regex);

/*namespace detail
{
struct list_options;

void list_packages(const Context& ctx, std::string regex, ChannelContext& channel_context);

struct formatted_pkg;

bool compare_alphabetically(const formatted_pkg& a, const formatted_pkg& b);
}*/
}

#endif
4 changes: 2 additions & 2 deletions libmamba/include/mamba/core/prefix_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace mamba
using package_map = std::map<std::string, specs::PackageInfo>;

static expected_t<PrefixData>
create(const fs::u8path& prefix_path, ChannelContext& channel_context);
create(const fs::u8path& prefix_path, ChannelContext& channel_context, bool no_pip = false);

void add_packages(const std::vector<specs::PackageInfo>& packages);
void load_single_record(const fs::u8path& path);
Expand All @@ -45,7 +45,7 @@ namespace mamba

private:

PrefixData(const fs::u8path& prefix_path, ChannelContext& channel_context);
PrefixData(const fs::u8path& prefix_path, ChannelContext& channel_context, bool no_pip);

void load_site_packages();

Expand Down
9 changes: 8 additions & 1 deletion libmamba/src/api/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace mamba
struct list_options
{
bool full_name;
bool no_pip;
};

struct formatted_pkg
Expand Down Expand Up @@ -55,7 +56,11 @@ namespace mamba
list_options options
)
{
auto sprefix_data = PrefixData::create(ctx.prefix_params.target_prefix, channel_context);
auto sprefix_data = PrefixData::create(
ctx.prefix_params.target_prefix,
channel_context,
options.no_pip
);
if (!sprefix_data)
{
// TODO: propagate tl::expected mechanism
Expand Down Expand Up @@ -202,6 +207,8 @@ namespace mamba

detail::list_options options;
options.full_name = config.at("full_name").value<bool>();
options.no_pip = config.at("no_pip").value<bool>();

auto channel_context = ChannelContext::make_conda_compatible(config.context());
detail::list_packages(config.context(), regex, channel_context, std::move(options));
}
Expand Down
14 changes: 9 additions & 5 deletions libmamba/src/core/prefix_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@

namespace mamba
{
auto PrefixData::create(const fs::u8path& prefix_path, ChannelContext& channel_context)
auto
PrefixData::create(const fs::u8path& prefix_path, ChannelContext& channel_context, bool no_pip)
-> expected_t<PrefixData>
{
try
{
return PrefixData(prefix_path, channel_context);
return PrefixData(prefix_path, channel_context, no_pip);
}
catch (std::exception& e)
{
Expand All @@ -46,7 +47,7 @@ namespace mamba
}
}

PrefixData::PrefixData(const fs::u8path& prefix_path, ChannelContext& channel_context)
PrefixData::PrefixData(const fs::u8path& prefix_path, ChannelContext& channel_context, bool no_pip)
: m_history(prefix_path, channel_context)
, m_prefix_path(prefix_path)
, m_channel_context(channel_context)
Expand All @@ -62,8 +63,11 @@ namespace mamba
}
}
}
// Load packages installed with pip
load_site_packages();
// Load packages installed with pip if `no_pip` is not set to `true`
if (!no_pip)
{
load_site_packages();
}
}

void PrefixData::add_packages(const std::vector<specs::PackageInfo>& packages)
Expand Down
5 changes: 5 additions & 0 deletions micromamba/src/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ init_list_parser(CLI::App* subcom, Configuration& config)
.description("Only search for full names, i.e., ^<regex>$."));
subcom->add_flag("-f,--full-name", full_name.get_cli_config<bool>(), full_name.description());

auto& no_pip = config.insert(Configurable("no_pip", false)
.group("cli")
.description("Do not include pip-only installed packages."));
subcom->add_flag("--no-pip", no_pip.get_cli_config<bool>(), no_pip.description());

// TODO: implement this in libmamba/list.cpp
/*auto& canonical = config.insert(Configurable("canonical", false)
.group("cli")
Expand Down
27 changes: 16 additions & 11 deletions micromamba/tests/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ def test_list_name(tmp_home, tmp_root_prefix, tmp_xtensor_env, quiet_flag):
"""


@pytest.mark.parametrize("no_pip_flag", ["", "--no-pip"])
@pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True)
def test_list_with_pip(tmp_home, tmp_root_prefix, tmp_path):
def test_list_with_pip(tmp_home, tmp_root_prefix, tmp_path, no_pip_flag):
env_name = "env-list_with_pip"
tmp_root_prefix / "envs" / env_name

Expand All @@ -63,16 +64,20 @@ def test_list_with_pip(tmp_home, tmp_root_prefix, tmp_path):
helpers.create("-n", env_name, "python=3.12", "--json", no_dry_run=True)
helpers.install("-n", env_name, "-f", env_file_yml, "--json", no_dry_run=True)

res = helpers.umamba_list("-n", env_name, "--json")
assert any(
package["name"] == "numpy"
and package["version"] == "1.26.4"
and package["base_url"] == "https://pypi.org/"
and package["build_string"] == "pypi_0"
and package["channel"] == "pypi"
and package["platform"] == sys.platform + "-" + platform.machine()
for package in res
)
res = helpers.umamba_list("-n", env_name, "--json", no_pip_flag)
if no_pip_flag == "":
assert any(
package["name"] == "numpy"
and package["version"] == "1.26.4"
and package["base_url"] == "https://pypi.org/"
and package["build_string"] == "pypi_0"
and package["channel"] == "pypi"
and package["platform"] == sys.platform + "-" + platform.machine()
for package in res
)
else: # --no-pip
# Check that numpy installed with pip is not listed
assert all(package["name"] != "numpy" for package in res)


@pytest.mark.parametrize("env_selector", ["name", "prefix"])
Expand Down
Loading