Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(470)

Unified Diff: tools/telemetry/third_party/rope/rope/refactor/multiproject.py

Issue 1132103009: Example of refactoring using rope library. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/telemetry/third_party/rope/rope/refactor/multiproject.py
diff --git a/tools/telemetry/third_party/rope/rope/refactor/multiproject.py b/tools/telemetry/third_party/rope/rope/refactor/multiproject.py
new file mode 100644
index 0000000000000000000000000000000000000000..ac243bdafcea6a7fd01cbe547a4a94ac04dfa7e5
--- /dev/null
+++ b/tools/telemetry/third_party/rope/rope/refactor/multiproject.py
@@ -0,0 +1,78 @@
+"""This module can be used for performing cross-project refactorings
+
+See the "cross-project refactorings" section of ``docs/library.rst``
+file.
+
+"""
+
+from rope.base import resources, libutils
+
+
+class MultiProjectRefactoring(object):
+
+ def __init__(self, refactoring, projects, addpath=True):
+ """Create a multiproject proxy for the main refactoring
+
+ `projects` are other project.
+
+ """
+ self.refactoring = refactoring
+ self.projects = projects
+ self.addpath = addpath
+
+ def __call__(self, project, *args, **kwds):
+ """Create the refactoring"""
+ return _MultiRefactoring(self.refactoring, self.projects,
+ self.addpath, project, *args, **kwds)
+
+
+class _MultiRefactoring(object):
+
+ def __init__(self, refactoring, other_projects, addpath,
+ project, *args, **kwds):
+ self.refactoring = refactoring
+ self.projects = [project] + other_projects
+ for other_project in other_projects:
+ for folder in self.project.get_source_folders():
+ other_project.get_prefs().add('python_path', folder.real_path)
+ self.refactorings = []
+ for other in self.projects:
+ args, kwds = self._resources_for_args(other, args, kwds)
+ self.refactorings.append(
+ self.refactoring(other, *args, **kwds))
+
+ def get_all_changes(self, *args, **kwds):
+ """Get a project to changes dict"""
+ result = []
+ for project, refactoring in zip(self.projects, self.refactorings):
+ args, kwds = self._resources_for_args(project, args, kwds)
+ result.append((project, refactoring.get_changes(*args, **kwds)))
+ return result
+
+ def __getattr__(self, name):
+ return getattr(self.main_refactoring, name)
+
+ def _resources_for_args(self, project, args, kwds):
+ newargs = [self._change_project_resource(project, arg) for arg in args]
+ newkwds = dict((name, self._change_project_resource(project, value))
+ for name, value in kwds.items())
+ return newargs, newkwds
+
+ def _change_project_resource(self, project, obj):
+ if isinstance(obj, resources.Resource) and \
+ obj.project != project:
+ return libutils.path_to_resource(project, obj.real_path)
+ return obj
+
+ @property
+ def project(self):
+ return self.projects[0]
+
+ @property
+ def main_refactoring(self):
+ return self.refactorings[0]
+
+
+def perform(project_changes):
+ for project, changes in project_changes:
+ project.do(changes)
« no previous file with comments | « tools/telemetry/third_party/rope/rope/refactor/move.py ('k') | tools/telemetry/third_party/rope/rope/refactor/occurrences.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698