Skip to content

Instantly share code, notes, and snippets.

@jgarte
Forked from cowlicks/move_thing.py
Created June 12, 2022 00:59
Show Gist options
  • Save jgarte/7b65f6a020b39a4eb4bd4419e4f4d2d5 to your computer and use it in GitHub Desktop.
Save jgarte/7b65f6a020b39a4eb4bd4419e4f4d2d5 to your computer and use it in GitHub Desktop.
python mover of things
def move_thing(src_mod, dest_mod, find_str):
import os
import rope.base.project
from rope.base import libutils
from rope.refactor import move
project = rope.base.project.Project(os.getcwd())
origin = libutils.path_to_resource(project, src_mod)
destination = libutils.path_to_resource(project, dest_mod)
offset = origin.read().index(find_str)
move_object = move.create_move(project, origin, offset)
changes = move_object.get_changes(destination)
project.do(changes)
project.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment