Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>

Co-authored-by: Johan Mabille <johan.mabille@gmail.com>
Co-authored-by: Ayaz Salikhov <mathbunnyru@users.noreply.github.com>
  • Loading branch information
3 people committed Nov 21, 2024
1 parent d88ee58 commit 9612088
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
4 changes: 2 additions & 2 deletions micromamba/src/env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ set_env_command(CLI::App* com, Configuration& config)
}

// Add a `pip` subsection in `dependencies` listing wheels installed from PyPI
if (pip_versions_map.size() > 0)
if (!pip_versions_map.empty() > 0)
{
dependencies << (first_dependency_printed ? ",\n" : "") << " { \"pip\": [\n";
first_dependency_printed = false;
Expand Down Expand Up @@ -321,7 +321,7 @@ set_env_command(CLI::App* com, Configuration& config)
}
}
// Add a `pip` subsection in `dependencies` listing wheels installed from PyPI
if (pip_versions_map.size() > 0)
if (!pip_versions_map.empty() > 0)
{
dependencies << " - pip:\n";
for (const auto& [k, v] : pip_versions_map)
Expand Down
32 changes: 19 additions & 13 deletions micromamba/tests/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,31 +486,37 @@ def test_env_update_empty_base(tmp_home, tmp_root_prefix, tmp_path):
assert any(package["name"] == "python" for package in packages)


@pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True)
env_yaml_content_env_export_with_pip = """
channels:
- conda-forge
dependencies:
- pip
- pip:
- requests==2.32.3
"""


@pytest.mark.parametrize("json_flag", [None, "--json"])
def test_env_export_with_pip(tmp_home, tmp_root_prefix, tmp_path, json_flag):
env_name = "env-list_with_pip"
tmp_root_prefix / "envs" / env_name
def test_env_export_with_pip(tmp_path, json_flag):
env_name = "env_export_with_pip"

env_file_yml = tmp_path / "test_env_yaml_content_to_install_numpy_with_pip.yaml"
env_file_yml.write_text(env_yaml_content_create_pip_pkg_with_version)
env_file_yml.write_text(env_yaml_content_env_export_with_pip)

flags = list(filter(None, [json_flag]))
helpers.create("-n", env_name, *flags, no_dry_run=True)
helpers.install("-n", env_name, "-f", env_file_yml, *flags, no_dry_run=True)
helpers.create("-n", env_name, "-f", env_file_yml, no_dry_run=True)

ret = helpers.run_env("export", "-n", env_name, *flags)
output = helpers.run_env("export", "-n", env_name, *flags)

# JSON is already parsed
ret = yaml.unsafe_load(ret) if json_flag is None else ret
ret = output if json_flag else yaml.safe_load(output)

assert ret["name"] == env_name
assert env_name in ret["prefix"]
assert set(ret["channels"]) == {"conda-forge"}
assert any("pip" in dep for dep in ret["dependencies"])

# Check there's a dictionary with a `pip` entry in `dependencies` and that numpy is part of it.
pip_section_index = next(
i for i, dep in enumerate(ret["dependencies"]) if isinstance(dep, dict) and "pip" in dep
pip_section = next(
dep for dep in ret["dependencies"] if isinstance(dep, dict) and ["pip"] == [*dep]
)
assert ret["dependencies"][pip_section_index] == {"pip": ["numpy==1.26.4"]}
assert pip_section["pip"] == ["requests==2.32.3"]

0 comments on commit 9612088

Please sign in to comment.