-
Notifications
You must be signed in to change notification settings - Fork 370
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
Changes from 13 commits
b095102
2b5a30f
60658f7
90a8af8
facfa9f
6cb7a00
6f6e041
fb05fe9
e65bc9b
7bed635
6944d93
589092d
2146c4f
bba3c3a
01c5e68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
channels: | ||
- conda-forge | ||
dependencies: | ||
- python > 3.11 | ||
- numpy < 2.0 | ||
- pytorch-cpu = 1.13.0 | ||
- scipy >= 1.5.0, < 2.0.0 | ||
- scikit-learn >1.0.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -361,6 +361,7 @@ def test_env_update_pypi_with_conda_forge(tmp_home, tmp_root_prefix, tmp_path): | |
## See: https://github.com/mamba-org/mamba/issues/2059 | ||
pip_list_output = helpers.umamba_run("-p", env_prefix, "pip", "list", "--format=json") | ||
pip_packages_list = yaml.safe_load(pip_list_output) | ||
|
||
# When numpy 2.0.0 is installed using mamba, | ||
# `numpy-2.0.0.dist-info/` is still created in `env_prefix/lib/pythonx.x/site-packages/` alongside `numpy-1.26.4.dist-info` | ||
# therefore causing an unexpected result when listing the version. | ||
|
@@ -370,3 +371,44 @@ def test_env_update_pypi_with_conda_forge(tmp_home, tmp_root_prefix, tmp_path): | |
pkg["name"] == "numpy" and Version(pkg["version"]) >= Version("1.26.4") | ||
for pkg in pip_packages_list | ||
) | ||
|
||
|
||
@pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True) | ||
def test_env_create_whitespace(tmp_home, tmp_root_prefix, tmp_path): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need this test, tests in There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
# Non-regression test for: https://github.com/mamba-org/mamba/issues/3453 | ||
|
||
env_prefix = tmp_path / "env-extra-white-space" | ||
|
||
create_spec_file = tmp_path / "env-extra-white-space.yaml" | ||
|
||
shutil.copyfile(__this_dir__ / "env-extra-white-space.yaml", create_spec_file) | ||
|
||
res = helpers.run_env("create", "-p", env_prefix, "-f", create_spec_file, "-y", "--json") | ||
assert res["success"] | ||
|
||
# Check that the env was created | ||
assert env_prefix.exists() | ||
# Check that the env has the right packages | ||
packages = helpers.umamba_list("-p", env_prefix, "--json") | ||
|
||
assert any( | ||
package["name"] == "python" and Version(package["version"]) > Version("3.11") | ||
for package in packages | ||
) | ||
assert any( | ||
package["name"] == "numpy" and Version(package["version"]) < Version("2.0") | ||
for package in packages | ||
) | ||
assert any( | ||
package["name"] == "pytorch-cpu" and Version(package["version"]) == Version("1.13.0") | ||
for package in packages | ||
) | ||
assert any( | ||
package["name"] == "scipy" | ||
and Version("1.5.0") <= Version(package["version"]) < Version("2.0.0") | ||
for package in packages | ||
) | ||
assert any( | ||
package["name"] == "scikit-learn" and Version(package["version"]) > Version("1.0.0") | ||
for package in packages | ||
) |
There was a problem hiding this comment.
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
).There was a problem hiding this comment.
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.