Skip to content

Commit

Permalink
Merge pull request #2151 from isuruf/multiple_space
Browse files Browse the repository at this point in the history
allow multiple spaces in python_min syntax
  • Loading branch information
beckermr authored Nov 21, 2024
2 parents 2b18d8d + 5881b09 commit b3ad532
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 6 deletions.
30 changes: 24 additions & 6 deletions conda_smithy/linter/hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,33 @@ def hint_noarch_python_use_python_min(
):
if noarch_value == "python" and not outputs_section:
hint = ""
for section_name, syntax, reqs in [
("host", "python {{ python_min }}", host_reqs),
("run", "python >={{ python_min }}", run_reqs),
("test.requires", "python {{ python_min }}", test_reqs),
for section_name, syntax, report_syntax, reqs in [
(
"host",
r"python\s+{{ python_min }}",
"python {{ python_min }}",
host_reqs,
),
(
"run",
r"python\s+>={{ python_min }}",
"python >={{ python_min }}",
run_reqs,
),
(
"test.requires",
r"python\s+{{ python_min }}",
"python {{ python_min }}",
test_reqs,
),
]:
if recipe_version == 1:
syntax = syntax.replace(
"{{ python_min }}", "${{ python_min }}"
)
report_syntax = report_syntax.replace(
"{{ python_min }}", "${{ python_min }}"
)
test_syntax = syntax
else:
test_syntax = syntax.replace("{{ python_min }}", "9999")
Expand All @@ -263,12 +281,12 @@ def hint_noarch_python_use_python_min(
if (
req.strip().split()[0] == "python"
and req != "python"
and test_syntax in req
and re.search(test_syntax, req)
):
break
else:
hint += (
f"\n - For the `{section_name}` section of the recipe, you should usually use `{syntax}` "
f"\n - For the `{section_name}` section of the recipe, you should usually use `{report_syntax}` "
f"for the `python` entry."
)

Expand Down
23 changes: 23 additions & 0 deletions news/2151-hint-less-spaces.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* Changed ``noarch-python`` hint to not require exactly one space between python and the Jinja2 expression. (#2151)

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
24 changes: 24 additions & 0 deletions tests/test_lint_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3200,6 +3200,30 @@ def test_hint_pip_no_build_backend(
),
[],
),
(
textwrap.dedent(
"""
{% set python_min = '3.7' %}
package:
name: python
build:
noarch: python
requirements:
host:
- python {{ python_min }}
run:
- python >={{ python_min }}
test:
requires:
- python {{ python_min }}
"""
),
[],
),
],
)
def test_hint_noarch_python_use_python_min(
Expand Down

0 comments on commit b3ad532

Please sign in to comment.