MCPcopy Create free account
hub / github.com/modelscope/ms-agent / parse

Method parse

ms_agent/utils/parser_utils.py:62–79  ·  view source on GitHub ↗
(self, code_content: str)

Source from the content-addressed store, hash-verified

60 return ['py']
61
62 def parse(self, code_content: str) -> List[ImportInfo]:
63 imports = []
64
65 # Pattern 1: from ... import ...
66 from_pattern = r'^\s*from\s+([\w.]+)\s+import\s+(?:\(([^)]+)\)|([^\n]+))'
67 for match in re.finditer(from_pattern, code_content,
68 re.MULTILINE | re.DOTALL):
69 info = self._extract_from_import(match, code_content)
70 if info:
71 imports.append(info)
72
73 # Pattern 2: import ...
74 import_pattern = r'^\s*import\s+([\w.,\s]+)'
75 for match in re.finditer(import_pattern, code_content, re.MULTILINE):
76 infos = self._extract_simple_import(match)
77 imports.extend(infos)
78
79 return imports
80
81 def _extract_from_import(self, match,
82 code_content) -> Optional[ImportInfo]:

Callers

nothing calls this directly

Calls 2

_extract_from_importMethod · 0.95

Tested by

no test coverage detected