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

Unified Diff: tools/telemetry/telemetry/internal/util/find_dependencies.py

Issue 1306953007: Add module dir to sys.path in FindPythonDependencies (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update to current master Created 5 years, 3 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/telemetry/telemetry/internal/util/find_dependencies.py
diff --git a/tools/telemetry/telemetry/internal/util/find_dependencies.py b/tools/telemetry/telemetry/internal/util/find_dependencies.py
index 76c4b8b3933f49e1d9ff24dfbc001ffe7427fb70..aaa15104a26409f9945c86102595744d3f98fc5c 100644
--- a/tools/telemetry/telemetry/internal/util/find_dependencies.py
+++ b/tools/telemetry/telemetry/internal/util/find_dependencies.py
@@ -36,37 +36,44 @@ def FindBootstrapDependencies(base_dir):
def FindPythonDependencies(module_path):
logging.info('Finding Python dependencies of %s' % module_path)
- # Load the module to inherit its sys.path modifications.
- imp.load_source(
- os.path.splitext(os.path.basename(module_path))[0], module_path)
-
- # Analyze the module for its imports.
- graph = modulegraph.ModuleGraph()
- graph.run_script(module_path)
-
- # Filter for only imports in Chromium.
- for node in graph.nodes():
- if not node.filename:
- continue
- module_path = os.path.realpath(node.filename)
-
- _, incoming_edges = graph.get_edges(node)
- message = 'Discovered %s (Imported by: %s)' % (
- node.filename, ', '.join(
- d.filename for d in incoming_edges
- if d is not None and d.filename is not None))
- logging.info(message)
-
- # This check is done after the logging/printing above to make sure that we
- # also print out the dependency edges that include python packages that are
- # not in chromium.
- if not path.IsSubpath(module_path, path.GetChromiumSrcDir()):
- continue
-
- yield module_path
- if node.packagepath is not None:
- for p in node.packagepath:
- yield p
+ sys_path = sys.path
+ sys.path = list(sys_path)
+ try:
+ # Load the module to inherit its sys.path modifications.
+ sys.path.insert(0, os.path.abspath(os.path.dirname(module_path)))
+ imp.load_source(
+ os.path.splitext(os.path.basename(module_path))[0], module_path)
+
+ # Analyze the module for its imports.
+ graph = modulegraph.ModuleGraph()
+ graph.run_script(module_path)
+
+ # Filter for only imports in Chromium.
+ for node in graph.nodes():
+ if not node.filename:
+ continue
+ module_path = os.path.realpath(node.filename)
+
+ _, incoming_edges = graph.get_edges(node)
+ message = 'Discovered %s (Imported by: %s)' % (
+ node.filename, ', '.join(
+ d.filename for d in incoming_edges
+ if d is not None and d.filename is not None))
+ logging.info(message)
+
+ # This check is done after the logging/printing above to make sure that
+ # we also print out the dependency edges that include python packages
+ # that are not in chromium.
+ if not path.IsSubpath(module_path, path.GetChromiumSrcDir()):
+ continue
+
+ yield module_path
+ if node.packagepath is not None:
+ for p in node.packagepath:
+ yield p
+
+ finally:
+ sys.path = sys_path
def FindPageSetDependencies(base_dir):
« 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