feat(mma): Add dependency mapping to mma-exec
This commit is contained in:
@@ -127,3 +127,22 @@ def main():
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
import ast
|
||||||
|
def get_dependencies(filepath):
|
||||||
|
with open(filepath, 'r', encoding='utf-8') as f:
|
||||||
|
tree = ast.parse(f.read())
|
||||||
|
dependencies = []
|
||||||
|
for node in tree.body:
|
||||||
|
if isinstance(node, ast.Import):
|
||||||
|
for alias in node.names:
|
||||||
|
dependencies.append(alias.name.split('.')[0])
|
||||||
|
elif isinstance(node, ast.ImportFrom):
|
||||||
|
if node.module:
|
||||||
|
dependencies.append(node.module.split('.')[0])
|
||||||
|
seen = set()
|
||||||
|
result = []
|
||||||
|
for d in dependencies:
|
||||||
|
if d not in seen:
|
||||||
|
result.append(d)
|
||||||
|
seen.add(d)
|
||||||
|
return result
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import pytest
|
import pytest
|
||||||
from unittest.mock import patch, MagicMock
|
from unittest.mock import patch, MagicMock
|
||||||
from scripts.mma_exec import create_parser, get_role_documents, execute_agent, get_model_for_role
|
from scripts.mma_exec import create_parser, get_role_documents, execute_agent, get_model_for_role, get_dependencies
|
||||||
|
|
||||||
def test_parser_role_choices():
|
def test_parser_role_choices():
|
||||||
"""Test that the parser accepts valid roles and the prompt argument."""
|
"""Test that the parser accepts valid roles and the prompt argument."""
|
||||||
@@ -84,3 +84,15 @@ def test_execute_agent():
|
|||||||
assert kwargs.get("text") is True
|
assert kwargs.get("text") is True
|
||||||
|
|
||||||
assert result == mock_stdout
|
assert result == mock_stdout
|
||||||
|
|
||||||
|
def test_get_dependencies(tmp_path):
|
||||||
|
content = (
|
||||||
|
"import os\n"
|
||||||
|
"import sys\n"
|
||||||
|
"import file_cache\n"
|
||||||
|
"from mcp_client import something\n"
|
||||||
|
)
|
||||||
|
filepath = tmp_path / "mock_script.py"
|
||||||
|
filepath.write_text(content)
|
||||||
|
dependencies = get_dependencies(filepath)
|
||||||
|
assert dependencies == ['os', 'sys', 'file_cache', 'mcp_client']
|
||||||
|
|||||||
Reference in New Issue
Block a user