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 corner-case in stdlib linting #2042

Merged
merged 6 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
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
"c_stdlib_stub"
if recipe_version == 0
else r"\$\{\{ stdlib\(['\"]c['\"]"
h-vetinari marked this conversation as resolved.
Show resolved Hide resolved
)
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 = "This recipe is using a compiler"

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(lint.startswith(avoid_message) for lint in lints)


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