From 0b53c1d98bec39ad01569eaabb0cebb1fdd961e6 Mon Sep 17 00:00:00 2001 From: beckermr Date: Wed, 20 Nov 2024 04:07:25 -0600 Subject: [PATCH 1/3] feat: add ruamel.yaml as parser for v1 --- conda_smithy/linter/lints.py | 14 +++++++++++ tests/test_lint_recipe.py | 47 ++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/conda_smithy/linter/lints.py b/conda_smithy/linter/lints.py index 34ea66597..029668295 100644 --- a/conda_smithy/linter/lints.py +++ b/conda_smithy/linter/lints.py @@ -1060,6 +1060,20 @@ def lint_recipe_is_parsable( else: parse_results[parse_name] = True + if recipe_version == 1: + parse_name = "ruamel.yaml" + try: + get_yaml(allow_duplicate_keys=False).load(recipe_text) + except Exception as e: + logger.warning( + "Error parsing recipe with ruamel.yaml: %s", + repr(e), + exc_info=e, + ) + parse_results[parse_name] = False + else: + parse_results[parse_name] = True + if parse_results: if any(pv is not None for pv in parse_results.values()): if not any(parse_results.values()): diff --git a/tests/test_lint_recipe.py b/tests/test_lint_recipe.py index 6a4248f5c..540dea840 100644 --- a/tests/test_lint_recipe.py +++ b/tests/test_lint_recipe.py @@ -3506,5 +3506,52 @@ def test_lint_recipe_parses_v1_spacing(): ), hints +def test_lint_recipe_parses_v1_duplicate_keys(): + with tempfile.TemporaryDirectory() as tmpdir: + with open(os.path.join(tmpdir, "recipe.yaml"), "w") as f: + f.write( + textwrap.dedent( + """ + package: + name: blah + + build: + number: ${{ build }} + number: 42 + + about: + home: something + license: MIT + license_file: LICENSE + summary: a test recipe + + extra: + recipe-maintainers: + - a + - b + """ + ) + ) + lints, hints = linter.main(tmpdir, return_hints=True, conda_forge=True) + assert not any( + lint.startswith( + "The recipe is not parsable by any of the known recipe parsers" + ) + for lint in lints + ), lints + assert not any( + hint.startswith( + "The recipe is not parsable by parser `conda-recipe-manager" + ) + for hint in hints + ), hints + assert any( + hint.startswith( + "The recipe is not parsable by parser `ruamel.yaml" + ) + for hint in hints + ), hints + + if __name__ == "__main__": unittest.main() From abca0af28c09bea997b8639114c333f2a4bc7702 Mon Sep 17 00:00:00 2001 From: beckermr Date: Wed, 20 Nov 2024 04:08:48 -0600 Subject: [PATCH 2/3] doc: add to news item --- news/2141-recipe-parsing-lint-hint.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/news/2141-recipe-parsing-lint-hint.rst b/news/2141-recipe-parsing-lint-hint.rst index 6239967e4..06ea6a765 100644 --- a/news/2141-recipe-parsing-lint-hint.rst +++ b/news/2141-recipe-parsing-lint-hint.rst @@ -1,6 +1,6 @@ **Added:** -* Added new ``conda-forge``-only hint+lint for recipe be able to be parsed. (#2141) +* Added new ``conda-forge``-only hint+lint for recipe be able to be parsed. (#2141, #2147) **Changed:** From 0ec65ac38365ea1a36885080928e43e2090f6a56 Mon Sep 17 00:00:00 2001 From: beckermr Date: Wed, 20 Nov 2024 04:12:45 -0600 Subject: [PATCH 3/3] fix: update tests for new parser --- tests/test_lint_recipe.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/test_lint_recipe.py b/tests/test_lint_recipe.py index 540dea840..eb12e9ffd 100644 --- a/tests/test_lint_recipe.py +++ b/tests/test_lint_recipe.py @@ -3492,7 +3492,7 @@ def test_lint_recipe_parses_v1_spacing(): ) ) lints, hints = linter.main(tmpdir, return_hints=True, conda_forge=True) - assert any( + assert not any( lint.startswith( "The recipe is not parsable by any of the known recipe parsers" ) @@ -3504,6 +3504,12 @@ def test_lint_recipe_parses_v1_spacing(): ) for hint in hints ), hints + assert not any( + hint.startswith( + "The recipe is not parsable by parser `ruamel.yaml" + ) + for hint in hints + ), hints def test_lint_recipe_parses_v1_duplicate_keys():