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

Unified Diff: tools/telemetry/third_party/rope/rope/base/stdmods.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/base/stdmods.py
diff --git a/tools/telemetry/third_party/rope/rope/base/stdmods.py b/tools/telemetry/third_party/rope/rope/base/stdmods.py
new file mode 100644
index 0000000000000000000000000000000000000000..457a4facaff1b7f991b6f8631186830786622b90
--- /dev/null
+++ b/tools/telemetry/third_party/rope/rope/base/stdmods.py
@@ -0,0 +1,46 @@
+import os
+import sys
+
+from rope.base import utils
+
+
+def _stdlib_path():
+ import distutils.sysconfig
+ return distutils.sysconfig.get_python_lib(standard_lib=True,
+ plat_specific=True)
+
+
+@utils.cached(1)
+def standard_modules():
+ return python_modules() | dynload_modules()
+
+
+@utils.cached(1)
+def python_modules():
+ result = set()
+ lib_path = _stdlib_path()
+ if os.path.exists(lib_path):
+ for name in os.listdir(lib_path):
+ path = os.path.join(lib_path, name)
+ if os.path.isdir(path):
+ if '-' not in name:
+ result.add(name)
+ else:
+ if name.endswith('.py'):
+ result.add(name[:-3])
+ return result
+
+
+@utils.cached(1)
+def dynload_modules():
+ result = set(sys.builtin_module_names)
+ dynload_path = os.path.join(_stdlib_path(), 'lib-dynload')
+ if os.path.exists(dynload_path):
+ for name in os.listdir(dynload_path):
+ path = os.path.join(dynload_path, name)
+ if os.path.isfile(path):
+ if name.endswith('.dll'):
+ result.add(os.path.splitext(name)[0])
+ if name.endswith('.so'):
+ result.add(os.path.splitext(name)[0].replace('module', ''))
+ return result
« no previous file with comments | « tools/telemetry/third_party/rope/rope/base/simplify.py ('k') | tools/telemetry/third_party/rope/rope/base/taskhandle.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698