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: ensure linter works when python_min is set via jinja2 #2132

Merged
merged 2 commits into from
Nov 14, 2024
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_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
Loading