Skip to content

Commit

Permalink
Merge pull request #2147 from conda-forge/parse-ruamel
Browse files Browse the repository at this point in the history
feat: add ruamel.yaml as parser for v1
  • Loading branch information
beckermr authored Nov 20, 2024
2 parents ff5e3a4 + 0ec65ac commit 3bf4acf
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
14 changes: 14 additions & 0 deletions conda_smithy/linter/lints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()):
Expand Down
2 changes: 1 addition & 1 deletion news/2141-recipe-parsing-lint-hint.rst
Original file line number Diff line number Diff line change
@@ -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:**

Expand Down
55 changes: 54 additions & 1 deletion tests/test_lint_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -3504,6 +3504,59 @@ 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():
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__":
Expand Down

0 comments on commit 3bf4acf

Please sign in to comment.