From 112a77f4bfed7b08e931b9c593e96b9c8e2f7d63 Mon Sep 17 00:00:00 2001 From: Dirk Pranke Date: Tue, 12 Mar 2019 01:50:42 +0000 Subject: [PATCH] Make sys a top-level import in gclient_paths. sys takes essentially no time to import (I think possibly because it's a built-in?), and importing it as-needed is fragile. Make it a top-level import to gclient_paths to prevent future breakages. BUG=939959 Change-Id: I1ebe1260afd927355d668acf3cab5067ff0a2e03 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1515669 Reviewed-by: Nico Weber Commit-Queue: Dirk Pranke --- gclient_paths.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gclient_paths.py b/gclient_paths.py index c02500e18..b860855fd 100644 --- a/gclient_paths.py +++ b/gclient_paths.py @@ -4,8 +4,11 @@ # This file is imported by various thin wrappers (around gn, clang-format, ...), # so it's meant to import very quickly. To keep it that way don't add more -# code, and even more importantly don't add more toplevel import statements. +# code, and even more importantly don't add more toplevel import statements, +# particularly for modules that are not builtin (see sys.builtin_modules_names, +# os isn't built in, but it's essential to this file). import os +import sys def FindGclientRoot(from_dir, filename='.gclient'): @@ -23,7 +26,6 @@ def FindGclientRoot(from_dir, filename='.gclient'): if path != real_from_dir: entries_filename = os.path.join(path, filename + '_entries') if not os.path.exists(entries_filename): - import sys # If .gclient_entries does not exist, a previous call to gclient sync # might have failed. In that case, we cannot verify that the .gclient # is the one we want to use. In order to not to cause too much trouble, @@ -106,7 +108,6 @@ def GetBuildtoolsPlatformBinaryPath(): if not buildtools_path: return None - import sys if sys.platform.startswith(('cygwin', 'win')): subdir = 'win' elif sys.platform == 'darwin': @@ -120,7 +121,6 @@ def GetBuildtoolsPlatformBinaryPath(): def GetExeSuffix(): """Returns '' or '.exe' depending on how executables work on this platform.""" - import sys if sys.platform.startswith(('cygwin', 'win')): return '.exe' return ''