Skip to content

Commit

Permalink
Make the python_min linter check robust against if-else syntax (#2154)
Browse files Browse the repository at this point in the history
* Make the `python_min` linter check robust against if-else syntax

In `noarch: python` recipes, the thing being checked here should
always have `python` as a string and not in an `if:` block, so it
should be safe to skip the check. Fixes the linter failing
on rattler-build recipes with conditional requirements.

* refactor+doc+test: use new util function, added news item, and added tests

---------

Co-authored-by: Matthew R. Becker <[email protected]>
Co-authored-by: beckermr <[email protected]>
  • Loading branch information
3 people authored Nov 26, 2024
1 parent 04d862f commit f8edc69
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
6 changes: 6 additions & 0 deletions conda_smithy/linter/hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from conda_smithy.linter.utils import (
VALID_PYTHON_BUILD_BACKENDS,
find_local_config_file,
flatten_v1_if_else,
is_selector_line,
)
from conda_smithy.utils import get_yaml
Expand Down Expand Up @@ -245,6 +246,11 @@ def hint_noarch_python_use_python_min(
hints,
):
if noarch_value == "python" and not outputs_section:
if recipe_version == 1:
host_reqs = flatten_v1_if_else(host_reqs)
run_reqs = flatten_v1_if_else(run_reqs)
test_reqs = flatten_v1_if_else(test_reqs)

hint = ""
for section_name, syntax, report_syntax, reqs in [
(
Expand Down
23 changes: 23 additions & 0 deletions news/2154-fix-python_min-v1-hint.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* Fixed a bug where the ``python_min`` hint failed on v1 recipes. (#2154)

**Security:**

* <news item>
60 changes: 60 additions & 0 deletions tests/test_lint_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3358,6 +3358,66 @@ def test_hint_noarch_python_use_python_min(
),
[],
),
(
textwrap.dedent(
"""
package:
name: python
requirements:
run:
- if: blah
then: python
else: python 3.7
"""
),
[],
),
(
textwrap.dedent(
"""
package:
name: python
build:
noarch: python
requirements:
run:
- if: blah
then: python
"""
),
[
"python ${{ python_min }}",
"python >=${{ python_min }}",
],
),
(
textwrap.dedent(
"""
package:
name: python
build:
noarch: python
requirements:
host:
- if: blah
then: blahblah
else: python ${{ python_min }}
run:
- python >=${{ python_min }}
tests:
- requirements:
run:
- python ${{ python_min }}
"""
),
[],
),
],
)
def test_hint_noarch_python_use_python_min_v1(
Expand Down

0 comments on commit f8edc69

Please sign in to comment.