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: Handle extra white-space in MatchSpec #3456

Merged
merged 15 commits into from
Sep 19, 2024

Conversation

jjerphan
Copy link
Member

@jjerphan jjerphan commented Sep 17, 2024

Fix #3453.

Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
@jjerphan jjerphan added the 1.x Related to mamba 1.x branch/versions label Sep 18, 2024
@JohanMabille JohanMabille added the release::bug_fixes For PRs fixing bugs label Sep 18, 2024
@jjerphan jjerphan removed the 1.x Related to mamba 1.x branch/versions label Sep 18, 2024
Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
@jjerphan jjerphan marked this pull request as ready for review September 18, 2024 09:53


@pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True)
def test_env_create_whitespace(tmp_home, tmp_root_prefix, tmp_path):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this test, tests in test_match_spec are enough to make sure the parsing is done correctly.
Adding this one is redundant and is not relevant in my opinion.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this, I just wanted to have a non-regression test for the reported issue.

Comment on lines +505 to +530
std::string raw_match_spec_str = std::string(str);
raw_match_spec_str = util::strip(raw_match_spec_str);

// Remove any with space after binary operators, such as:
// - `openmpi-4.1.4-ha1ae619_102`'s improperly encoded `constrains`: "cudatoolkit >= 10.2"
// - `pytorch-1.13.0-cpu_py310h02c325b_0.conda`'s improperly encoded
// `constrains`: "pytorch-cpu = 1.13.0", "pytorch-gpu = 99999999"
// - `fipy-3.4.2.1-py310hff52083_3.tar.bz2`'s improperly encoded `constrains` or
// `dep`: ">=4.5.2"
// - `infokonoha-4.6.3-pyhd8ed1ab_0.tar.bz2`'s `kytea >=0.1.4, 0.2.0` -> `kytea
// >=0.1.4,0.2.0`
// TODO: this solution reallocates memory several times potentially, but the
// number of operators is small and the strings are short, so it must be fine.
// If needed it can be optimized so that the string is only copied once.
for (const std::string& op : { ">=", "<=", "==", ">", "<", "!=", "=", "==", "," })
{
const std::string& bad_op = op + " ";
while (raw_match_spec_str.find(bad_op) != std::string::npos)
{
raw_match_spec_str = raw_match_spec_str.substr(0, raw_match_spec_str.find(bad_op)) + op
+ raw_match_spec_str.substr(
raw_match_spec_str.find(bad_op) + bad_op.size()
);
}
}

Copy link
Member

@Hind-M Hind-M Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we won't have a choice and we will need to fix this this way, but I really think that we should do this properly and stop postponing everything to later, because it will just increase the complexity (making it harder to change things afterwards), especially regarding the MatchSpec...
IIRC this should be rather handled here, so we need to adapt the logic accordingly (and try to keep the string_view).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with your proposal although there is some complexity with the low level parser: if we want to handle all the current cases while excluding the PEP 508 environment markers, I am afraid that the amount of complexity to manage will be far more complex that this horrible yet working and short solution.

In my opinion, the long-term robust solution (as discussed in the past) is to define a grammar for MatchSpec and use lexers to generate parsers in applications. But this goes far beyond the scope of this PR or the time we have at hand.

jjerphan and others added 4 commits September 19, 2024 13:59
Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>

Co-authored-by: Hind Montassif <hind.montassif@gmail.com>
Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>

Co-authored-by: Hind Montassif <hind.montassif@gmail.com>
jjerphan and others added 2 commits September 19, 2024 14:25
Co-authored-by: Hind-M <70631848+Hind-M@users.noreply.github.com>
Co-authored-by: Hind-M <70631848+Hind-M@users.noreply.github.com>
Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
@SylvainCorlay SylvainCorlay merged commit 1c75567 into mamba-org:main Sep 19, 2024
32 checks passed
@jjerphan jjerphan deleted the fix/handle-extra-white-space branch September 19, 2024 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release::bug_fixes For PRs fixing bugs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Micromamba 2.0rc5 - libmamba Error parsing version ""
4 participants