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

Unified Diff: tools/cr/cr/loader.py

Issue 1155193003: Ignore import errors in cr recursive module loading (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add _TryImport 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/cr/cr/loader.py
diff --git a/tools/cr/cr/loader.py b/tools/cr/cr/loader.py
index 21cb6f5f91bf8f8514c866e65f48a95e10eec265..b0bbb9f27616d336896c149ae5d163d5be5c4eee 100644
--- a/tools/cr/cr/loader.py
+++ b/tools/cr/cr/loader.py
@@ -46,6 +46,16 @@ def _Import(name):
return import_module(name, None)
+def _TryImport(name):
+ """Try to import a module or package if it is not already imported."""
+ try:
+ return _Import(name)
+ except ImportError:
+ if cr.context.verbose:
+ print 'Warning: Failed to load module', name
+ return None
+
+
def _ScanModule(module):
"""Runs all the scan_hooks for a module."""
scanner_tags = getattr(module, _MODULE_SCANNED_TAG, None)
@@ -76,12 +86,14 @@ def _ScanPackage(package):
packages.append(name)
elif basename.endswith('.py') and not basename.startswith('_'):
name = '.'.join([package.__name__, basename[:-3]])
- module = _Import(name)
- _ScanModule(module)
- modules.append(module)
+ module = _TryImport(name)
+ if module:
+ _ScanModule(module)
+ modules.append(module)
for name in packages:
- child = _Import(name)
- modules.extend(_ScanPackage(child))
+ child = _TryImport(name)
+ if child:
+ modules.extend(_ScanPackage(child))
return modules
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698