This is still a work-in-progress; there is much more to do. Existing functionality may not be perfect.
Enable python source code refactoring through AST modifications.
Sample use cases:
pasta.dump(pasta.parse(src)) == src.
2.7 and up to
pasta depends on
import pasta tree = pasta.parse(source_code) # ... Augment contents of tree ... source_code = pasta.dump(tree)
Pasta includes some common augmentations out-of-the-box. These can be used as building blocks for more complex refactoring actions.
There will be more of these basic augmentations added over time. Stay tuned!
Rewrites references to an imported name, module or package. For some more
# Rewrite references from one module to another rename.rename_external(tree, 'pkg.subpkg.module', 'pkg.other_module') # Rewrite references from one package to another rename.rename_external(tree, 'pkg.subpkg', 'pkg.other_pkg') # Rewrite references to an imported name in another module rename.rename_external(tree, 'pkg.module.Query', 'pkg.module.ExecuteQuery')
Changing the indentation level of a block of code is not supported. This is not an issue for renames, but would cause problems for refactors like extracting a method.
pasta works under the assumption that the python version that the code is
written for and the version used to run pasta are the same. This is because
pasta relies on
Some python features are not fully supported, including
This project uses
facilitate testing and packaging.
# Run all tests python setup.py test # Run a single test suite python setup.py test -s pasta.base.annotate_test.suite
This is not an official Google product.