Skip to content

Commit

Permalink
Merge pull request #2042 from h-vetinari/stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
beckermr committed Sep 1, 2024
2 parents 392e36f + 0c3a641 commit aa3eaf2
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
11 changes: 9 additions & 2 deletions conda_smithy/linter/lints.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,8 +796,15 @@ def flatten_reqs(reqs):
# this check needs to be done per output --> use separate (unflattened) requirements
for build_reqs in all_build_reqs:
has_compiler = any(pat_compiler_stub.match(rq) for rq in build_reqs)
stdlib_stub = "c_stdlib_stub" if recipe_version == 0 else "${{ stdlib"
if has_compiler and stdlib_stub not in build_reqs:
stdlib_regex = (
# we need the C stdlib, not just any invocation of the stdlib jinja
"^(m2w64_)?c_stdlib_stub$"
if recipe_version == 0
else r"\$\{\{ stdlib\(['\"](m2w64_)?c['\"]\)"
)
if has_compiler and not any(
re.search(stdlib_regex, x) for x in build_reqs
):
if stdlib_lint not in lints:
lints.append(stdlib_lint)

Expand Down
23 changes: 23 additions & 0 deletions news/2041-stdlib_corner_case.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 corner-case in stdlib-linting (#2042)

**Security:**

* <news item>
21 changes: 21 additions & 0 deletions tests/test_lint_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,27 @@ def test_stdlib_lint(comp_lang):
assert any(lint.startswith(expected_message) for lint in lints)


def test_m2w64_stdlib_legal():
# allow recipes that _only_ depend on {{ stdlib("m2w64_c") }}
avoid_message = "stdlib"

with tmp_directory() as recipe_dir:
with open(os.path.join(recipe_dir, "meta.yaml"), "w") as fh:
fh.write(
"""
package:
name: foo
requirements:
build:
- {{ stdlib("m2w64_c") }}
- {{ compiler("m2w64_c") }}
"""
)

lints, _ = linter.main(recipe_dir, return_hints=True)
assert not any(avoid_message in lint for lint in lints)


@pytest.mark.parametrize(
"comp_lang",
["c", "cxx", "fortran", "rust", "m2w64_c", "m2w64_cxx", "m2w64_fortran"],
Expand Down

0 comments on commit aa3eaf2

Please sign in to comment.