Skip to content

Commit

Permalink
fix: Skip empty lines in environment spec files
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>

Co-authored-by: Alphonse de Lamartine <alphonse@de-lamartine.fr>
  • Loading branch information
jjerphan and Alphonse de Lamartine committed Dec 6, 2024
1 parent b6150db commit 3dcf91b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
8 changes: 7 additions & 1 deletion libmamba/src/api/install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,13 @@ namespace mamba
std::vector<std::string> f_specs;
for (auto& line : file_contents)
{
if (line[0] != '#' && line[0] != '@')
// Skip comment lines and empty lines
// Comment lines start with '#' or '@' preceded by whitespaces or tabs
auto is_comment = util::starts_with(line, "#")
|| util::starts_with(line, "@");
auto is_empty = std::all_of(line.begin(), line.end(), ::isspace);

if (!is_comment && !is_empty)
{
f_specs.push_back(line);
}
Expand Down
27 changes: 27 additions & 0 deletions micromamba/tests/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -1441,3 +1441,30 @@ def test_create_empty_or_absent_dependencies(tmp_path):
"-p", env_prefix, "-f", tmp_path / "env_spec_absent_dependencies.yaml", "--json"
)
assert res["success"]


env_spec_empty_lines_and_comments = """
# The line below are empty (various number of spaces)
"""

env_spec_empty_lines_and_comments += "\n"
env_spec_empty_lines_and_comments += " \n"
env_spec_empty_lines_and_comments += " \n"
env_spec_empty_lines_and_comments += " \n"
env_spec_empty_lines_and_comments += "# Un seul check vous manque, \n"
env_spec_empty_lines_and_comments += "@ et tout est explosé\n"
env_spec_empty_lines_and_comments += "numpy\n"


def test_create_with_empty_lines_and_comments(tmp_path):
# Non-regression test for

env_prefix = tmp_path / "env-one_empty_line"

env_spec = tmp_path / "env_spec_with_one_empty_line.txt"

with open(env_spec, "w") as f:
f.write(env_spec_empty_lines_and_comments)

res = helpers.create("-p", env_prefix, "-f", env_spec, "--json")
assert res["success"]

0 comments on commit 3dcf91b

Please sign in to comment.