Python rope

From wikinotes

Rope is a refactoring library for python.

It is designed to be implemented by an editor, but you may use it directly from python.

Configuration

Rope configuration is stored within /src/.ropeproject/config.py

Some settings that I prefer:

# If `True`, rope will insert new module imports as
# `from <package> import <module>` by default.
prefs['prefer_modules_from_imports'] = True

# If `True`, rope will remove all top-level import statements and
# reinsert them at the top of the module when making changes.
prefs['pull_imports_to_top'] = False

Usage

from rope.base import libutils

# set project
myresource = libutils.path_to_resource(
    myproject, 
    '/home/will/progs/python/general')

# set target module
resource = libutils.path_to_resource(
    myproject, 
    '/home/will/progs/python/general/module.py')

from rope.refactor.extract import ExtractVariable
extractor = ExtractVariable(myproject, resource, start, end) # Define extractor range (character range of match?)
changes = extractor.get_changes('extracted_variable')        # Calculate all places changes would need to be performed (if var is changed to?)
myproject.do(changes)                                        # Perform changes

Plugins

ropevim

Using ropevim, greatly simplifies it's usage. It gets variable/function names from the text under the cursor.
Here are some of the default keybindings for ropevim.

<C-x> p o <codefix> (p)roject (o)pen create/open rope project
<C-x> p u/r <codefix> (p)roject (u)ndo(r)edo undo/redo refactoring
<C-c> r a d doctag under cursor
<C-c> r r rename class/variable/...
<C-c> r 1 r rename module
<C-c> r a f find occurrences (may be useful... )
<C-c> r a g goto a function definition (for when ctags lets me down)