From 63296e8c590e2899e12fb4134ff7df3115cad3f4 Mon Sep 17 00:00:00 2001 From: Gregory Szorc Date: Thu, 25 Jun 2015 12:12:15 -0700 Subject: [PATCH] Bug 1176642 - Defer import of urllib2; r=chmanchester This prevents 8 module imports from occurring at mach startup time. As part of this, I discovered a redundant import of "sys" and eliminated it. --- testing/taskcluster/mach_commands.py | 2 +- testing/xpcshell/mach_commands.py | 3 ++- tools/mach_commands.py | 5 +++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/testing/taskcluster/mach_commands.py b/testing/taskcluster/mach_commands.py index e4af069d9c5..f5560d0ee89 100644 --- a/testing/taskcluster/mach_commands.py +++ b/testing/taskcluster/mach_commands.py @@ -10,7 +10,6 @@ import os import json import copy import sys -import urllib2 from mach.decorators import ( CommandArgument, @@ -58,6 +57,7 @@ def docker_image(name): return '{}/{}:{}'.format(repository, name, version) def get_task(task_id): + import urllib2 return json.load(urllib2.urlopen("https://queue.taskcluster.net/v1/task/" + task_id)) diff --git a/testing/xpcshell/mach_commands.py b/testing/xpcshell/mach_commands.py index 3ed9755cfcc..03bd41a817f 100644 --- a/testing/xpcshell/mach_commands.py +++ b/testing/xpcshell/mach_commands.py @@ -10,7 +10,6 @@ import argparse import os import shutil import sys -import urllib2 from mozlog import structured @@ -322,6 +321,8 @@ class B2GXPCShellRunner(MozbuildObject): self.bin_dir = os.path.join(self.distdir, 'bin') def _download_busybox(self, b2g_home, emulator): + import urllib2 + target_device = 'generic' if emulator == 'x86': target_device = 'generic_x86' diff --git a/tools/mach_commands.py b/tools/mach_commands.py index 38e0d3c24a4..f4f7c7ec8dc 100644 --- a/tools/mach_commands.py +++ b/tools/mach_commands.py @@ -8,7 +8,6 @@ import sys import os import stat import platform -import urllib2 import errno from mach.decorators import ( @@ -219,8 +218,8 @@ class PastebinProvider(object): help='Specify the file to upload to pastebin.mozilla.org') def pastebin(self, language, poster, duration, file): - import sys import urllib + import urllib2 URL = 'https://pastebin.mozilla.org/' @@ -299,6 +298,8 @@ class FormatProvider(MachCommandBase): @CommandArgument('--show', '-s', action = 'store_true', help = 'Show diff output on instead of applying changes') def clang_format(self, show=False): + import urllib2 + plat = platform.system() fmt = plat.lower() + "/clang-format-3.5" fmt_diff = "clang-format-diff-3.5"