From f64c4c14d3c0d99d22597ced1e468562a7e210c2 Mon Sep 17 00:00:00 2001 From: Kate Case Date: Fri, 14 Apr 2023 11:16:53 -0400 Subject: [PATCH] Ansible already knows how to get examples --- src/ansiblelint/file_utils.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/ansiblelint/file_utils.py b/src/ansiblelint/file_utils.py index 8fd4e6331ed..d8657689909 100644 --- a/src/ansiblelint/file_utils.py +++ b/src/ansiblelint/file_utils.py @@ -1,7 +1,6 @@ """Utility functions related to file operations.""" from __future__ import annotations -import ast import copy import logging import os @@ -15,6 +14,7 @@ from tempfile import NamedTemporaryFile from typing import TYPE_CHECKING, Any, Iterator, cast +from ansible.parsing.plugin_docs import read_docstring import wcmatch.pathlib from wcmatch.wcmatch import RECURSIVE, WcMatch from yaml.error import YAMLError @@ -376,15 +376,8 @@ def parse_examples_from_plugin(self) -> str: The line numbers are stored in each node's LINE_NUMBER_KEY key. """ - parsed = ast.parse(self.content, self.path) - - examples = None - for node in parsed.body: - if isinstance(node, ast.Assign): - for target in node.targets: - if isinstance(target, ast.Name) and target.id == "EXAMPLES" and isinstance(node.value, ast.Constant): - examples = node.value.value - + docs = read_docstring(str(self.path)) + examples = docs["plainexamples"] return examples or "" @property