Path: blob/master/elisp/emacs-for-python/rope-dist/rope/refactor/topackage.py
1428 views
import rope.refactor.importutils1from rope.base.change import ChangeSet, ChangeContents, MoveResource, CreateFolder234class ModuleToPackage(object):56def __init__(self, project, resource):7self.project = project8self.pycore = project.pycore9self.resource = resource1011def get_changes(self):12changes = ChangeSet('Transform <%s> module to package' %13self.resource.path)14new_content = self._transform_relatives_to_absolute(self.resource)15if new_content is not None:16changes.add_change(ChangeContents(self.resource, new_content))17parent = self.resource.parent18name = self.resource.name[:-3]19changes.add_change(CreateFolder(parent, name))20parent_path = parent.path + '/'21if not parent.path:22parent_path = ''23new_path = parent_path + '%s/__init__.py' % name24if self.resource.project == self.project:25changes.add_change(MoveResource(self.resource, new_path))26return changes2728def _transform_relatives_to_absolute(self, resource):29pymodule = self.pycore.resource_to_pyobject(resource)30import_tools = rope.refactor.importutils.ImportTools(self.pycore)31return import_tools.relatives_to_absolutes(pymodule)323334