summaryrefslogtreecommitdiff
path: root/astroid/builder.py
diff options
context:
space:
mode:
Diffstat (limited to 'astroid/builder.py')
-rw-r--r--astroid/builder.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/astroid/builder.py b/astroid/builder.py
index 7f3a0661..8f0a1d07 100644
--- a/astroid/builder.py
+++ b/astroid/builder.py
@@ -25,6 +25,7 @@ from __future__ import with_statement
import _ast
import os
import sys
+import textwrap
from astroid import bases
from astroid import exceptions
@@ -233,3 +234,15 @@ class AstroidBuilder(raw_building.InspectBuilder):
values.append(node)
except exceptions.InferenceError:
pass
+
+
+def parse(code, module_name='', path=None):
+ """Parses a source string in order to obtain an astroid AST from it
+
+ :param str code: The code for the module.
+ :param str module_name: The name for the module, if any
+ :param str path: The path for the module
+ """
+ code = textwrap.dedent(code)
+ return AstroidBuilder(MANAGER).string_build(
+ code, modname=module_name, path=path)