(path: str, code: str, target: CompilationTarget)
return fix_code(code), dependencies
Applies all transformation for passed target.
Applies all transformation for passed target.
Applies all transformation for passed target .
def _transform(path: str, code: str, target: CompilationTarget) -> Tuple[str, List[str]]:
    """Applies all transformation for passed target."""
    debug(lambda: 'Compiling "{}"'.format(path))
    dependencies = []  # type: List[str]
    tree = ast.parse(code, path)
    debug(lambda: 'Initial ast:\n{}'.format(dump(tree)))

    for transformer in transformers:
        if transformer.target < target:
            debug(lambda: 'Skip transformer "{}"'.format(transformer.__name__))
            continue

        debug(lambda: 'Use transformer "{}"'.format(transformer.__name__))

        working_tree = deepcopy(tree)
        try:
            result = transformer.transform(working_tree)
        except:
            raise TransformationError(path, transformer,
                                      dump(tree), format_exc())

        if not result.tree_changed:
            debug(lambda: 'Tree not changed')
            continue

        tree = working_tree
        debug(lambda: 'Tree changed:\n{}'.format(dump(tree)))
        dependencies.extend(result.dependencies)

        try:
            code = unparse(tree)
            debug(lambda: 'Code changed:\n{}'.format(code))
        except:
            raise TransformationError(path, transformer,
                                      dump(tree), format_exc())

    return fix_code(code), dependencies
def _transform ( path : str , code : str , target : CompilationTarget ) -> Tuple [ str , List [ str ] ] : debug ( lambda : 'Compiling "{}"' . format ( path ) ) dependencies = [ ] # type: List[str] tree = ast . parse ( code , path ) debug ( lambda : 'Initial ast:\n{}' . format ( dump ( tree ) ) ) for transformer in transformers : if transformer . target < target : debug ( lambda : 'Skip transformer "{}"' . format ( transformer . __name__ ) ) continue debug ( lambda : 'Use transformer "{}"' . format ( transformer . __name__ ) ) working_tree = deepcopy ( tree ) try : result = transformer . transform ( working_tree ) except : raise TransformationError ( path , transformer , dump ( tree ) , format_exc ( ) ) if not result . tree_changed : debug ( lambda : 'Tree not changed' ) continue tree = working_tree debug ( lambda : 'Tree changed:\n{}' . format ( dump ( tree ) ) ) dependencies . extend ( result . dependencies ) try : code = unparse ( tree ) debug ( lambda : 'Code changed:\n{}' . format ( code ) ) except : raise TransformationError ( path , transformer , dump ( tree ) , format_exc ( ) ) return fix_code ( code ) , dependencies