Home | History | Annotate | Download | only in refactor
      1 # Copyright 2015 The Chromium Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 """Style-preserving Python code transforms.
      6 
      7 This module provides components for modifying and querying Python code. They can
      8 be used to build custom refactorings and linters.
      9 """
     10 
     11 import functools
     12 import multiprocessing
     13 
     14 # pylint: disable=wildcard-import
     15 from py_utils.refactor.annotated_symbol import *
     16 from py_utils.refactor.module import Module
     17 
     18 
     19 def _TransformFile(transform, file_path):
     20   module = Module(file_path)
     21   result = transform(module)
     22   module.Write()
     23   return result
     24 
     25 
     26 def Transform(transform, file_paths):
     27   transform = functools.partial(_TransformFile, transform)
     28   return multiprocessing.Pool().map(transform, file_paths)
     29