Get all matched identifiers from a repo Args: names (list): The list of identifiers to be searched backend (object): The backend object that provides search functionality num_result (int, optional): The maximum number of matches for each identifier to return. Default
(names, backend, num_result=3, verbose=False)
| 72 | return "\n".join(results) |
| 73 | |
| 74 | def search_py_elements_inside_project(names, backend, num_result=3, verbose=False): |
| 75 | """Get all matched identifiers from a repo |
| 76 | |
| 77 | Args: |
| 78 | names (list): The list of identifiers to be searched |
| 79 | backend (object): The backend object that provides search functionality |
| 80 | num_result (int, optional): The maximum number of matches for each identifier to return. Defaults to 2. |
| 81 | verbose (bool, optional): If true, additional information about the search results is provided. Defaults to False. |
| 82 | |
| 83 | Returns: |
| 84 | list: A list of matched identifiers |
| 85 | |
| 86 | Raises: |
| 87 | None |
| 88 | |
| 89 | Examples: |
| 90 | >>> search_py_elements_inside_project(['foo', 'bar'], backend) |
| 91 | {'foo': [{'name': 'FooClass', 'full_name': 'my_module.FooClass', 'documentation': 'This is the documentation for FooClass', 'implementation': 'class FooClass:\n def __init__(self):\n pass\n\n def foo_method(self):\n pass\n'}], |
| 92 | 'bar': [{'name': 'bar_function', 'full_name': 'my_module.bar_function', 'documentation': 'This is the documentation for bar_function', 'implementation': 'def bar_function():\n pass\n'}]} |
| 93 | """ |
| 94 | output_dict = {name: [] for name in names} |
| 95 | for name in names: |
| 96 | if not name.endswith(".py"): |
| 97 | class_definitions = backend.search(f"class {name}", all_scopes=True) |
| 98 | function_definitions = backend.search(f"def {name}", all_scopes=True) |
| 99 | variable_definitions = backend.search(name, all_scopes=True) |
| 100 | idx = 0 |
| 101 | for definition in class_definitions: |
| 102 | if definition.is_definition(): |
| 103 | extracted_definition = { |
| 104 | "path": definition.module_path, |
| 105 | "full_name": definition.full_name, |
| 106 | "implementation": get_code_jedi(definition, verbose) |
| 107 | } |
| 108 | output_dict[name].append(extracted_definition) |
| 109 | idx += 1 |
| 110 | if idx == num_result: |
| 111 | break |
| 112 | |
| 113 | idx = 0 |
| 114 | for definition in function_definitions: |
| 115 | if definition.is_definition(): |
| 116 | extracted_definition = { |
| 117 | "path": definition.module_path, |
| 118 | "full_name": definition.full_name, |
| 119 | "implementation": get_code_jedi(definition, verbose), |
| 120 | } |
| 121 | output_dict[name].append(extracted_definition) |
| 122 | idx += 1 |
| 123 | if idx == num_result: |
| 124 | break |
| 125 | |
| 126 | idx = 0 |
| 127 | for definition in variable_definitions: |
| 128 | extracted_definition = { |
| 129 | "path": definition.module_path, |
| 130 | "full_name": definition.full_name, |
| 131 | "implementation": definition.description, |
nothing calls this directly
no test coverage detected