Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _change_calls(self, call_changer, in_hierarchy=None, resources=None,
handle=taskhandle.NullTaskHandle()):
if resources is None:
resources = self.project.get_python_files()
changes = ChangeSet('Changing signature of <%s>' % self.name)
job_set = handle.create_jobset('Collecting Changes', len(resources))
finder = occurrences.create_finder(
self.project, self.name, self.pyname, instance=self.primary,
in_hierarchy=in_hierarchy and self.is_method())
if self.others:
name, pyname = self.others
constructor_finder = occurrences.create_finder(
self.project, name, pyname, only_calls=True)
finder = _MultipleFinders([finder, constructor_finder])
for file in resources:
job_set.started_job(file.path)
change_calls = _ChangeCallsInModule(
self.project, finder, file, call_changer)
changed_file = change_calls.get_changed_module()
if changed_file is not None:
changes.add_change(ChangeContents(file, changed_file))
def _calculate_changes(self, dest, resources, task_handle):
changes = ChangeSet('Moving module <%s>' % self.old_name)
job_set = task_handle.create_jobset('Collecting changes',
len(resources))
for module in resources:
job_set.started_job(module.path)
if module == self.source:
self._change_moving_module(changes, dest)
else:
source = self._change_occurrences_in_module(dest,
resource=module)
if source is not None:
changes.add_change(ChangeContents(module, source))
job_set.finished_job()
if self.project == self.source.project:
changes.add_change(MoveResource(self.source, dest.path))
return changes
def _perform_change(self, change_, description):
changes = rope.base.change.ChangeSet(description)
changes.add_change(change_)
self.project.do(changes)
def _basic_changes(self, changes):
if isinstance(changes, change.ChangeSet):
for child in changes.changes:
for atom in self._basic_changes(child):
yield atom
else:
yield changes
def _calculate_changes(self, dest, resources, task_handle):
changes = ChangeSet('Moving global <%s>' % self.old_name)
job_set = task_handle.create_jobset('Collecting Changes',
len(resources))
for file_ in resources:
job_set.started_job(file_.path)
if file_ == self.source:
changes.add_change(self._source_module_changes(dest))
elif file_ == dest:
changes.add_change(self._dest_module_changes(dest))
elif self.tools.occurs_in_module(resource=file_):
pymodule = self.project.get_pymodule(file_)
# Changing occurrences
placeholder = '__rope_renaming_%s_' % self.old_name
source = self.tools.rename_in_module(placeholder,
resource=file_)
should_import = source is not None
# Removing out of date imports
def count_changes(change):
"""Counts the number of basic changes a `Change` will make"""
if isinstance(change, ChangeSet):
result = 0
for child in change.changes:
result += count_changes(child)
return result
return 1
def _get_moved_resources(self, changes, undo=False):
result = {}
if isinstance(changes, rope.base.change.ChangeSet):
for change in changes.changes:
result.update(self._get_moved_resources(change))
if isinstance(changes, rope.base.change.MoveResource):
result[changes.resource] = changes.new_resource
if undo:
return dict([(value, key) for key, value in result.items()])
return result
def _get_moved_resources(self, changes, undo=False):
result = {}
if isinstance(changes, rope.base.change.ChangeSet):
for change in changes.changes:
result.update(self._get_moved_resources(change))
if isinstance(changes, rope.base.change.MoveResource):
result[changes.resource] = changes.new_resource
if undo:
return dict([(value, key) for key, value in result.items()])
return result