From 2a0ec2a31a5f67e03ee12e551c3cbd862d07ce45 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Thu, 29 Aug 2024 12:27:36 +1100 Subject: [PATCH 1/5] fix corner-case in stdlib linting --- conda_smithy/linter/lints.py | 6 ++++-- tests/test_lint_recipe.py | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/conda_smithy/linter/lints.py b/conda_smithy/linter/lints.py index a338b87fe..30c109f8e 100644 --- a/conda_smithy/linter/lints.py +++ b/conda_smithy/linter/lints.py @@ -796,8 +796,10 @@ 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_search = ( + "c_stdlib_stub" if recipe_version == 0 else "${{ stdlib" + ) + if has_compiler and not any(stdlib_search in x for x in build_reqs): if stdlib_lint not in lints: lints.append(stdlib_lint) diff --git a/tests/test_lint_recipe.py b/tests/test_lint_recipe.py index d2515db1c..fbe6b5988 100644 --- a/tests/test_lint_recipe.py +++ b/tests/test_lint_recipe.py @@ -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"], From 61fd65973ce5530f975688f5184906817d9a24a7 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Thu, 29 Aug 2024 12:28:55 +1100 Subject: [PATCH 2/5] add news --- news/2041-stdlib_corner_case.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 news/2041-stdlib_corner_case.rst diff --git a/news/2041-stdlib_corner_case.rst b/news/2041-stdlib_corner_case.rst new file mode 100644 index 000000000..c9eabdb78 --- /dev/null +++ b/news/2041-stdlib_corner_case.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* Fixed a corner-case in stdlib-linting (#2042) + +**Security:** + +* From 31ececa8780c60b05cc3880ea562a283c78529c0 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Sun, 1 Sep 2024 11:55:11 +1100 Subject: [PATCH 3/5] switch to regex for finding `{{ stdlib("c") }}` --- conda_smithy/linter/lints.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/conda_smithy/linter/lints.py b/conda_smithy/linter/lints.py index 30c109f8e..fa80fd80e 100644 --- a/conda_smithy/linter/lints.py +++ b/conda_smithy/linter/lints.py @@ -796,10 +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_search = ( - "c_stdlib_stub" if recipe_version == 0 else "${{ stdlib" + 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['\"]" ) - if has_compiler and not any(stdlib_search in x for x in build_reqs): + 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) From 5f00224d4d0247b705f2cf9fc5a04ef75f1f475e Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Sun, 1 Sep 2024 14:21:22 +1100 Subject: [PATCH 4/5] handle `m2w64_` case, tighten regex --- conda_smithy/linter/lints.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conda_smithy/linter/lints.py b/conda_smithy/linter/lints.py index fa80fd80e..531b77997 100644 --- a/conda_smithy/linter/lints.py +++ b/conda_smithy/linter/lints.py @@ -798,9 +798,9 @@ def flatten_reqs(reqs): has_compiler = any(pat_compiler_stub.match(rq) for rq in build_reqs) stdlib_regex = ( # we need the C stdlib, not just any invocation of the stdlib jinja - "c_stdlib_stub" + "^(m2w64_)?c_stdlib_stub$" if recipe_version == 0 - else r"\$\{\{ stdlib\(['\"]c['\"]" + else r"\$\{\{ stdlib\(['\"](m2w64_)?c['\"]\)" ) if has_compiler and not any( re.search(stdlib_regex, x) for x in build_reqs From f4c23165ea15837be21ab1e88713f1ea10cc796d Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Sun, 1 Sep 2024 14:26:48 +1100 Subject: [PATCH 5/5] make test_m2w64_stdlib_legal more robust against changes in lint text --- tests/test_lint_recipe.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_lint_recipe.py b/tests/test_lint_recipe.py index fbe6b5988..4759b1ccf 100644 --- a/tests/test_lint_recipe.py +++ b/tests/test_lint_recipe.py @@ -76,7 +76,7 @@ def test_stdlib_lint(comp_lang): def test_m2w64_stdlib_legal(): # allow recipes that _only_ depend on {{ stdlib("m2w64_c") }} - avoid_message = "This recipe is using a compiler" + avoid_message = "stdlib" with tmp_directory() as recipe_dir: with open(os.path.join(recipe_dir, "meta.yaml"), "w") as fh: @@ -92,7 +92,7 @@ def test_m2w64_stdlib_legal(): ) lints, _ = linter.main(recipe_dir, return_hints=True) - assert not any(lint.startswith(avoid_message) for lint in lints) + assert not any(avoid_message in lint for lint in lints) @pytest.mark.parametrize(