Skip to content

Commit

Permalink
Merge pull request #2132 from conda-forge/more-bugz-noarch-lint
Browse files Browse the repository at this point in the history
fix: ensure linter works when python_min is set via jinja2
  • Loading branch information
beckermr authored Nov 14, 2024
2 parents 6789a15 + 266a732 commit bafe463
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
13 changes: 12 additions & 1 deletion conda_smithy/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
import json
import os
import re
import shutil
import tempfile
import time
Expand All @@ -18,6 +19,7 @@

RATTLER_BUILD = "rattler-build"
CONDA_BUILD = "conda-build"
SET_PYTHON_MIN_RE = re.compile(r"{%\s+set\s+python_min\s+=")


def _get_metadata_from_feedstock_dir(
Expand Down Expand Up @@ -118,6 +120,15 @@ def stub_subpackage_pin(*args, **kwargs):
return f"subpackage_pin {args[0]}"


def _munge_python_min(text):
new_lines = []
for line in text.splitlines(keepends=True):
if SET_PYTHON_MIN_RE.match(line):
line = "{% set python_min = '9999' %}\n"
new_lines.append(line)
return "".join(new_lines)


def render_meta_yaml(text):
env = jinja2.sandbox.SandboxedEnvironment(undefined=NullUndefined)

Expand Down Expand Up @@ -146,7 +157,7 @@ def render_meta_yaml(text):
mockos = MockOS()
py_ver = "3.7"
context = {"os": mockos, "environ": mockos.environ, "PY_VER": py_ver}
content = env.from_string(text).render(context)
content = env.from_string(_munge_python_min(text)).render(context)
return content


Expand Down
23 changes: 23 additions & 0 deletions news/2132-more-noarch-bugs.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 bug when linting for ``noarch: python`` syntax and using jinja2 set statements. (#2132)

**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 @@ -3176,6 +3176,30 @@ def test_hint_pip_no_build_backend(
),
["python >={{ python_min }}"],
),
(
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 bafe463

Please sign in to comment.