这是indexloc提供的服务,不要输入任何密码
Skip to content
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
2 changes: 1 addition & 1 deletion conda/models/match_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def conda_build_form(self):
version = self.get_raw_value("version")

if build:
assert version
version = version or "*"
builder += [version, build]
elif version:
builder.append(version)
Expand Down
3 changes: 1 addition & 2 deletions docs/source/dev-guide/deep-dives/solvers.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ First, let's define what each object does:
This query language has its own syntax and rules, detailed [here][conda_package_spec]. The
most important fields of a `MatchSpec` object are:
* `name`: the name of the package (e.g. `pytorch`); always expected.
* `version`: the version constraints (e.g. `1.8.*`); can be empty but if `build` is set, set it to
`*` to avoid issues with the `.conda_build_form()` method.
* `version`: the version constraints (e.g. `1.8.*`); can be empty. If `build` is set and `version` is not, `*` will be used as default.
* `build`: the build string constraints (e.g. `*cuda*`); can be empty.

```{admonition} Create a MatchSpec object from a PackageRecord instance
Expand Down
19 changes: 19 additions & 0 deletions news/11200-version-default-matchspec-conda-build-form
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* <news item>

### Bug fixes

* Set default value for `version` parameter when `build` is set in `MatchSpec.conda_build_form()`. (#11200 via #15025)

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
18 changes: 18 additions & 0 deletions tests/models/test_match_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -1436,6 +1436,24 @@ def test_invalid_version_reports_spec(spec):
assert spec in str(exc.value)


@pytest.mark.parametrize(
"build,version,expected_result",
[
(None, None, "python"),
("*123*", None, "python * *123*"),
(None, "3.*", "python 3.*"),
("*123*", "3.17", "python 3.17 *123*"),
],
ids=["name_only", "build_only", "version_only", "build_version"],
)
def test_conda_build_form(build, version, expected_result):
"""conda_build_form method handles missing values for build and/or version gracefully"""
kwargs = {"build": build, "version": version}
# only pass values that are not None
kwargs = {key: value for key, value in kwargs.items() if value is not None}
assert MatchSpec("python", **kwargs).conda_build_form() == expected_result


@pytest.mark.parametrize(
"input_spec,expected_output",
[
Expand Down
Loading