From d778662a2d5ebd2af3e4eb55b037edac41e747ed Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 12 Nov 2024 06:21:17 -0600 Subject: [PATCH 1/2] fix: ensure linter works when python_min is set --- conda_smithy/utils.py | 13 ++++++++++++- tests/test_lint_recipe.py | 24 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/conda_smithy/utils.py b/conda_smithy/utils.py index c4f58369b..17550ef5f 100644 --- a/conda_smithy/utils.py +++ b/conda_smithy/utils.py @@ -1,6 +1,7 @@ import datetime import json import os +import re import shutil import tempfile import time @@ -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( @@ -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) @@ -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 diff --git a/tests/test_lint_recipe.py b/tests/test_lint_recipe.py index 63818db63..cca9af5f8 100644 --- a/tests/test_lint_recipe.py +++ b/tests/test_lint_recipe.py @@ -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( From 266a7322d79371d3906b938c20ef1c6a7b456b8b Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 12 Nov 2024 06:23:02 -0600 Subject: [PATCH 2/2] doc: added news item --- news/2132-more-noarch-bugs.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 news/2132-more-noarch-bugs.rst diff --git a/news/2132-more-noarch-bugs.rst b/news/2132-more-noarch-bugs.rst new file mode 100644 index 000000000..3d4445066 --- /dev/null +++ b/news/2132-more-noarch-bugs.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* Fixed bug when linting for ``noarch: python`` syntax and using jinja2 set statements. (#2132) + +**Security:** + +*