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 pinning expressions for prerelease builds #4272

Merged
merged 6 commits into from
Sep 1, 2021
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
13 changes: 12 additions & 1 deletion conda_build/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1514,7 +1514,18 @@ def apply_pin_expressions(version, min_pin='x.x.x.x.x.x.x', max_pin='x'):
if versions[p_idx][-1] == '.':
versions[p_idx] = versions[p_idx][:-1]
if versions[0]:
versions[0] = '>=' + versions[0]
if version.endswith(".*"):
version_order = VersionOrder(version[:-2])
elif version.endswith("*"):
version_order = VersionOrder(version[:-1])
else:
version_order = VersionOrder(version)
if version_order < VersionOrder(versions[0]):
# If the minimum is greater than the version this is a pre-release build.
# Use the version as the lower bound
versions[0] = '>=' + version
else:
versions[0] = '>=' + versions[0]
if versions[1]:
versions[1] = '<' + versions[1]
return ','.join([v for v in versions if v])
Expand Down
4 changes: 4 additions & 0 deletions docs/source/resources/variants.rst
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,10 @@ that was used at build time.
# produces pins like >=1.11,<2
variants = [{'numpy': '1.11', 'pin_run_as_build': {'numpy': {'min_pin': 'x.x', 'max_pin': 'x'}}}]

Note that for pre-release versions ``min_pin`` will be ignored and substituted
with the exact input version since pre-releases can never match ``>=x.x`` (see
`build-version-spec`_ for details on pre-release version matching).


Pinning at the variant level
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
25 changes: 25 additions & 0 deletions news/gh-4272-Fix-pinning-expressions-for-prerelease-builds.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Enhancements:
-------------

* <news item>

Bug fixes:
----------

* Fix pinning expressions for prerelease builds

Deprecations:
-------------

* <news item>

Docs:
-----

* <news item>

Other:
------

* <news item>

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pin_run_as_build:
foo:
min_pin: x.x
max_pin: x.x

foo:
- 3.10.0.rc1
16 changes: 16 additions & 0 deletions tests/test-recipes/metadata/_pinning_prerelease/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package:
name: foo
version: 3.10.0.rc1

outputs:
- name: foo
- name: bar
requirements:
host:
- foo
run:
- foo
test:
commands:
- echo "hello world"

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pin_run_as_build:
python:
min_pin: x.x
max_pin: x.x

python:
- 3.10.0rc1
16 changes: 16 additions & 0 deletions tests/test-recipes/metadata/_pinning_prerelease_python/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package:
name: foo
version: 3.10.0rc1

outputs:
- name: python
- name: bar
requirements:
host:
- python
run:
- python
test:
commands:
- echo "hello world"

16 changes: 16 additions & 0 deletions tests/test_api_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,19 @@ def test_run_exports_from_repo_without_channeldata(testing_config):
# these two will be missing if run_exports has failed.
assert ms[0][0].meta['requirements']['host'] == ["exporty"]
assert ms[0][0].meta['requirements']['run'] == ["exporty"]


def test_pin_expression_works_with_prereleases(testing_config):
recipe = os.path.join(metadata_dir, '_pinning_prerelease')
ms = api.render(recipe, config=testing_config)
assert len(ms) == 2
m = next(m_[0] for m_ in ms if m_[0].meta['package']['name'] == 'bar')
assert 'foo >=3.10.0.rc1,<3.11.0a0' in m.meta['requirements']['run']


def test_pin_expression_works_with_python_prereleases(testing_config):
recipe = os.path.join(metadata_dir, '_pinning_prerelease_python')
ms = api.render(recipe, config=testing_config)
assert len(ms) == 2
m = next(m_[0] for m_ in ms if m_[0].meta['package']['name'] == 'bar')
assert 'python >=3.10.0rc1,<3.11.0a0' in m.meta['requirements']['run']