How to use the astor.code_to_ast.parse_file function in astor

To help you get started, we’ve selected a few astor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github berkerpeksag / astor / tests / test_misc.py View on Github external
def test_aliases(self):
        self.assertIs(astor.parse_file, astor.code_to_ast.parse_file)
github bsc-wdc / compss / compss / programming_model / bindings / tmp / python / src / pycompss / util / translators / py2pycompss / translator_py2pycompss.py View on Github external
# Load user function code
        import astor
        func_ast = astor.code_to_ast(func)

        # Initialize output content
        output_imports = []
        task2headers = {}
        task2func_code = {}
        output_loops_code = []
        task_counter_id = 0

        # Process each par_py file
        for par_py in par_py_files:
            # Retrieve file AST
            par_py_ast = astor.code_to_ast.parse_file(par_py)

            # Process ast
            output_code = []
            task2new_name = {}
            task2original_args = {}
            task2new_args = {}
            task2ret_args = {}
            task2vars2subscripts = {}

            for statement in par_py_ast.body:
                if isinstance(statement, ast.Import):
                    from pycompss.util.translators.py2pycompss.components.code_cleaner import CodeCleaner
                    if not CodeCleaner.contains_import_statement(statement, output_imports):
                        output_imports.append(statement)
                elif isinstance(statement, ast.FunctionDef):
                    task_func_name = statement.name