bug 1463425 - Fix flake8/pep8 issue by hand in build/ r=gps
authorSylvestre Ledru <sledru@mozilla.com>
Mon, 21 May 2018 23:58:19 +0200
changeset 419597 afa720beeefb08b8f0c3e2a7f88fde4530eddd69
parent 419596 c37fb2bf78d66c664f17af47a6d0f838e54850a2
child 419598 fba6f974041a3d3c22ef95c44f6e4262e8e5c52f
push id34040
push userebalazs@mozilla.com
push dateThu, 24 May 2018 09:37:05 +0000
treeherdermozilla-central@c411ccb6bb4a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs1463425
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 1463425 - Fix flake8/pep8 issue by hand in build/ r=gps MozReview-Commit-ID: AZdcEWyVV6e
build/build-clang/build-clang.py
build/clang-plugin/ThirdPartyPaths.py
build/clang-plugin/import_mozilla_checks.py
build/compare-mozconfig/compare-mozconfigs.py
build/mobile/remoteautomation.py
build/pgo/genpgocert.py
build/pgo/profileserver.py
build/unix/rewrite_asan_dylib.py
build/util/count_ctors.py
build/valgrind/mach_commands.py
build/valgrind/output_handler.py
build/win32/autobinscope.py
--- a/build/build-clang/build-clang.py
+++ b/build/build-clang/build-clang.py
@@ -102,17 +102,17 @@ def mkdir_p(path):
 
 
 def delete(path):
     if os.path.isdir(path):
         shutil.rmtree(path)
     else:
         try:
             os.unlink(path)
-        except:
+        except Exception:
             pass
 
 
 def install_libgcc(gcc_dir, clang_dir):
     out = subprocess.check_output([os.path.join(gcc_dir, "bin", "gcc"),
                                    '-print-libgcc-file-name'])
 
     libgcc_dir = os.path.dirname(out.rstrip())
--- a/build/clang-plugin/ThirdPartyPaths.py
+++ b/build/clang-plugin/ThirdPartyPaths.py
@@ -1,12 +1,13 @@
 #!/usr/bin/env python
 
 import json
 
+
 def generate(output, tpp_txt):
     """
     This file generates a ThirdPartyPaths.cpp file from the ThirdPartyPaths.txt
     file in /tools/rewriting, which is used by the Clang Plugin to help identify
     sources which should be ignored.
     """
 
     tpp_list = []
--- a/build/clang-plugin/import_mozilla_checks.py
+++ b/build/clang-plugin/import_mozilla_checks.py
@@ -1,15 +1,14 @@
 #!/usr/bin/python2.7
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 import os
-import re
 import sys
 import glob
 import shutil
 import errno
 
 import ThirdPartyPaths
 
 
@@ -124,28 +123,28 @@ def do_import(mozilla_path, clang_tidy_p
 extern volatile int MozillaModuleAnchorSource;
 static int LLVM_ATTRIBUTE_UNUSED MozillaModuleAnchorDestination =
           MozillaModuleAnchorSource;
 ''')
 
 
 def main():
     if len(sys.argv) != 3:
-        print """\
+        print("""\
 Usage: import_mozilla_checks.py <mozilla-clang-plugin-path> <clang-tidy-path>
 Imports the Mozilla static analysis checks into a clang-tidy source tree.
-"""
+""")
 
         return
 
     mozilla_path = sys.argv[1]
     if not os.path.isdir(mozilla_path):
-        print "Invalid path to mozilla clang plugin"
+        print("Invalid path to mozilla clang plugin")
 
     clang_tidy_path = sys.argv[2]
     if not os.path.isdir(mozilla_path):
-        print "Invalid path to clang-tidy source directory"
+        print("Invalid path to clang-tidy source directory")
 
     do_import(mozilla_path, clang_tidy_path)
 
 
 if __name__ == '__main__':
     main()
--- a/build/compare-mozconfig/compare-mozconfigs.py
+++ b/build/compare-mozconfig/compare-mozconfigs.py
@@ -1,14 +1,14 @@
 #!/usr/bin/python
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
-# originally from https://hg.mozilla.org/build/tools/file/4ab9c1a4e05b/scripts/release/compare-mozconfigs.py
+# originally from https://hg.mozilla.org/build/tools/file/4ab9c1a4e05b/scripts/release/compare-mozconfigs.py  # NOQA: E501
 
 from __future__ import unicode_literals
 
 import logging
 import os
 import difflib
 import unittest
 
@@ -23,24 +23,27 @@ PLATFORMS = (
     'linux64',
     'macosx64',
     'win32',
     'win64',
 )
 
 log = logging.getLogger(__name__)
 
+
 class ConfigError(Exception):
     pass
 
+
 def readConfig(configfile):
     c = {}
     execfile(configfile, c)
     return c['whitelist']
 
+
 def verify_mozconfigs(mozconfig_pair, nightly_mozconfig_pair, platform,
                       mozconfigWhitelist):
     """Compares mozconfig to nightly_mozconfig and compare to an optional
     whitelist of known differences. mozconfig_pair and nightly_mozconfig_pair
     are pairs containing the mozconfig's identifier and the list of lines in
     the mozconfig."""
 
     # unpack the pairs to get the names, the names are just for
@@ -50,17 +53,18 @@ def verify_mozconfigs(mozconfig_pair, ni
 
     if not mozconfig_lines or not nightly_mozconfig_lines:
         log.info("Missing mozconfigs to compare for %s" % platform)
         return False
 
     success = True
 
     diff_instance = difflib.Differ()
-    diff_result = diff_instance.compare(mozconfig_lines, nightly_mozconfig_lines)
+    diff_result = diff_instance.compare(
+        mozconfig_lines, nightly_mozconfig_lines)
     diff_list = list(diff_result)
 
     for line in diff_list:
         clean_line = line[1:].strip()
         if (line[0] == '-' or line[0] == '+') and len(clean_line) > 1:
             # skip comment lines
             if clean_line.startswith('#'):
                 continue
@@ -93,33 +97,33 @@ def verify_mozconfigs(mozconfig_pair, ni
                 log.error(message % (mozconfig_name,
                                      nightly_mozconfig_name, clean_line))
             else:
                 log.error(message % (nightly_mozconfig_name,
                                      mozconfig_name, clean_line))
             success = False
     return success
 
+
 def get_mozconfig(path):
     """Consumes a path and returns a list of lines from the mozconfig file."""
     with open(path, 'rb') as fh:
         return fh.readlines()
 
 
 def compare(topsrcdir):
     app = os.path.join(topsrcdir, 'browser')
     whitelist = readConfig(os.path.join(app, 'config', 'mozconfigs',
                                         'whitelist'))
 
     success = True
 
     def normalize_lines(lines):
         return {l.strip() for l in lines}
 
-
     for platform in PLATFORMS:
         log.info('Comparing platform %s' % platform)
 
         mozconfigs_path = os.path.join(app, 'config', 'mozconfigs', platform)
 
         nightly_path = os.path.join(mozconfigs_path, 'nightly')
         beta_path = os.path.join(mozconfigs_path, 'beta')
         release_path = os.path.join(mozconfigs_path, 'release')
--- a/build/mobile/remoteautomation.py
+++ b/build/mobile/remoteautomation.py
@@ -32,17 +32,18 @@ class RemoteAutomation(Automation):
         self._remoteProfile = remoteProfile
         self._remoteLog = remoteLog
         self._processArgs = processArgs or {}
 
         self.lastTestSeen = "remoteautomation.py"
         Automation.__init__(self)
 
     # Set up what we need for the remote environment
-    def environment(self, env=None, xrePath=None, crashreporter=True, debugger=False, lsanPath=None, ubsanPath=None):
+    def environment(self, env=None, xrePath=None, crashreporter=True, debugger=False,
+                    lsanPath=None, ubsanPath=None):
         # Because we are running remote, we don't want to mimic the local env
         # so no copying of os.environ
         if env is None:
             env = {}
 
         if crashreporter and not debugger:
             env['MOZ_CRASHREPORTER_NO_REPORT'] = '1'
             env['MOZ_CRASHREPORTER'] = '1'
@@ -61,77 +62,79 @@ class RemoteAutomation(Automation):
         #
         # This may be used to disabled network connections during testing, e.g.
         # Switchboard & telemetry uploads.
         env.setdefault('MOZ_IN_AUTOMATION', '1')
 
         # Set WebRTC logging in case it is not set yet.
         # On Android, environment variables cannot contain ',' so the
         # standard WebRTC setting for NSPR_LOG_MODULES is not available.
-        # env.setdefault('NSPR_LOG_MODULES', 'signaling:5,mtransport:5,datachannel:5,jsep:5,MediaPipelineFactory:5')
+        # env.setdefault('NSPR_LOG_MODULES', 'signaling:5,mtransport:5,datachannel:5,jsep:5,MediaPipelineFactory:5')  # NOQA: E501
         env.setdefault('R_LOG_LEVEL', '6')
         env.setdefault('R_LOG_DESTINATION', 'stderr')
         env.setdefault('R_LOG_VERBOSE', '1')
 
         return env
 
-    def waitForFinish(self, proc, utilityPath, timeout, maxTime, startTime, debuggerInfo, symbolsPath, outputHandler=None):
+    def waitForFinish(self, proc, utilityPath, timeout, maxTime, startTime, debuggerInfo,
+                      symbolsPath, outputHandler=None):
         """ Wait for tests to finish.
             If maxTime seconds elapse or no output is detected for timeout
             seconds, kill the process and fail the test.
         """
         proc.utilityPath = utilityPath
         # maxTime is used to override the default timeout, we should honor that
         status = proc.wait(timeout=maxTime, noOutputTimeout=timeout)
         self.lastTestSeen = proc.getLastTestSeen
 
         topActivity = self._device.get_top_activity(timeout=60)
         if topActivity == proc.procName:
-            print "Browser unexpectedly found running. Killing..."
+            print("Browser unexpectedly found running. Killing...")
             proc.kill(True)
         if status == 1:
             if maxTime:
-                print "TEST-UNEXPECTED-FAIL | %s | application ran for longer than " \
+                print("TEST-UNEXPECTED-FAIL | %s | application ran for longer than "
                       "allowed maximum time of %s seconds" % (
-                          self.lastTestSeen, maxTime)
+                          self.lastTestSeen, maxTime))
             else:
-                print "TEST-UNEXPECTED-FAIL | %s | application ran for longer than " \
-                      "allowed maximum time" % (self.lastTestSeen)
+                print("TEST-UNEXPECTED-FAIL | %s | application ran for longer than "
+                      "allowed maximum time" % (self.lastTestSeen))
         if status == 2:
-            print "TEST-UNEXPECTED-FAIL | %s | application timed out after %d seconds with no output" \
-                % (self.lastTestSeen, int(timeout))
+            print("TEST-UNEXPECTED-FAIL | %s | application timed out after %d seconds with"
+                  "no output"
+                  % (self.lastTestSeen, int(timeout)))
 
         return status
 
     def deleteANRs(self):
         # empty ANR traces.txt file; usually need root permissions
         # we make it empty and writable so we can test the ANR reporter later
         traces = "/data/anr/traces.txt"
         try:
             self._device.shell_output('echo > %s' % traces, root=True)
             self._device.shell_output('chmod 666 %s' % traces, root=True)
         except Exception as e:
-            print "Error deleting %s: %s" % (traces, str(e))
+            print("Error deleting %s: %s" % (traces, str(e)))
 
     def checkForANRs(self):
         traces = "/data/anr/traces.txt"
         if self._device.is_file(traces):
             try:
                 t = self._device.get_file(traces)
                 if t:
                     stripped = t.strip()
                     if len(stripped) > 0:
-                        print "Contents of %s:" % traces
-                        print t
+                        print("Contents of %s:" % traces)
+                        print(t)
                 # Once reported, delete traces
                 self.deleteANRs()
             except Exception as e:
-                print "Error pulling %s: %s" % (traces, str(e))
+                print("Error pulling %s: %s" % (traces, str(e)))
         else:
-            print "%s not found" % traces
+            print("%s not found" % traces)
 
     def deleteTombstones(self):
         # delete any tombstone files from device
         self._device.rm("/data/tombstones", force=True,
                         recursive=True, root=True)
 
     def checkForTombstones(self):
         # pull any tombstones from device and move to MOZ_UPLOAD_DIR
@@ -150,19 +153,19 @@ class RemoteAutomation(Automation):
                     # multiple tombstones generated with the same name, for
                     # instance, after multiple robocop tests
                     for i in xrange(1, sys.maxint):
                         newname = "%s.%d.txt" % (f, i)
                         if not os.path.exists(newname):
                             os.rename(f, newname)
                             break
             else:
-                print "%s does not exist; tombstone check skipped" % remoteDir
+                print("%s does not exist; tombstone check skipped" % remoteDir)
         else:
-            print "MOZ_UPLOAD_DIR not defined; tombstone check skipped"
+            print("MOZ_UPLOAD_DIR not defined; tombstone check skipped")
 
     def checkForCrashes(self, directory, symbolsPath):
         self.checkForANRs()
         self.checkForTombstones()
 
         logcat = self._device.get_logcat(
             filter_out_regexps=fennecLogcatFilters)
 
@@ -179,47 +182,48 @@ class RemoteAutomation(Automation):
         try:
             dumpDir = tempfile.mkdtemp()
             remoteCrashDir = posixpath.join(self._remoteProfile, 'minidumps')
             if not self._device.is_dir(remoteCrashDir):
                 # If crash reporting is enabled (MOZ_CRASHREPORTER=1), the
                 # minidumps directory is automatically created when Fennec
                 # (first) starts, so its lack of presence is a hint that
                 # something went wrong.
-                print "Automation Error: No crash directory (%s) found on remote device" % remoteCrashDir
+                print("Automation Error: No crash directory (%s) found on remote device" %
+                      remoteCrashDir)
                 return True
             self._device.pull(remoteCrashDir, dumpDir)
 
             logger = get_default_logger()
             crashed = mozcrash.log_crashes(
                 logger, dumpDir, symbolsPath, test=self.lastTestSeen)
 
         finally:
             try:
                 shutil.rmtree(dumpDir)
             except Exception as e:
-                print "WARNING: unable to remove directory %s: %s" % (
-                    dumpDir, str(e))
+                print("WARNING: unable to remove directory %s: %s" % (
+                    dumpDir, str(e)))
         return crashed
 
     def buildCommandLine(self, app, debuggerInfo, profileDir, testURL, extraArgs):
         # If remote profile is specified, use that instead
         if self._remoteProfile:
             profileDir = self._remoteProfile
 
         # Hack for robocop, if app is "am" and extraArgs contains the rest of the stuff, lets
         # assume extraArgs is all we need
         if app == "am" and extraArgs[0] in ('instrument', 'start'):
             return app, extraArgs
 
         cmd, args = Automation.buildCommandLine(
             self, app, debuggerInfo, profileDir, testURL, extraArgs)
         try:
             args.remove('-foreground')
-        except:
+        except Exception:
             pass
         return app, args
 
     def Process(self, cmd, stdout=None, stderr=None, env=None, cwd=None):
         return self.RProcess(self._device, cmd, self._remoteLog, env, cwd, self._appName,
                              **self._processArgs)
 
     class RProcess(object):
@@ -238,17 +242,17 @@ class RemoteAutomation(Automation):
                 self.counts['pass'] = 0
                 self.counts['fail'] = 0
                 self.counts['todo'] = 0
 
             if cmd[0] == 'am':
                 cmd = ' '.join(cmd)
                 self.procName = app
                 if not self.device.shell_bool(cmd):
-                    print "remote_automation.py failed to launch %s" % cmd
+                    print("remote_automation.py failed to launch %s" % cmd)
             else:
                 args = cmd
                 if args[0] == app:
                     args = args[1:]
                 url = args[-1:][0]
                 if url.startswith('/'):
                     # this is probably a reftest profile directory, not a url
                     url = None
@@ -297,17 +301,17 @@ class RemoteAutomation(Automation):
 
             self.stdoutlen += len(newLogContent)
 
             if self.messageLogger is None:
                 testStartFilenames = re.findall(
                     r"TEST-START \| ([^\s]*)", newLogContent)
                 if testStartFilenames:
                     self.lastTestSeen = testStartFilenames[-1]
-                print newLogContent
+                print(newLogContent)
                 return True
 
             self.logBuffer += newLogContent
             lines = self.logBuffer.split('\n')
             lines = [l for l in lines if l]
 
             if lines:
                 if self.logBuffer.endswith('\n'):
@@ -335,17 +339,17 @@ class RemoteAutomation(Automation):
                                 try:
                                     val = int(m.group(1))
                                     if "Passed:" in line:
                                         self.counts['pass'] += val
                                     elif "Failed:" in line:
                                         self.counts['fail'] += val
                                     elif "Todo:" in line:
                                         self.counts['todo'] += val
-                                except:
+                                except Exception:
                                     pass
 
             return True
 
         @property
         def getLastTestSeen(self):
             return self.lastTestSeen
 
@@ -354,17 +358,17 @@ class RemoteAutomation(Automation):
         # If the process is still running after *timeout* seconds, return 1;
         # If the process is still running but no output is received in *noOutputTimeout*
         # seconds, return 2;
         # Else, once the process exits/goes to background, return 0.
         def wait(self, timeout=None, noOutputTimeout=None):
             timer = 0
             noOutputTimer = 0
             interval = 10
-            if timeout == None:
+            if timeout is None:
                 timeout = self.timeout
             status = 0
             top = self.procName
             slowLog = False
             endTime = datetime.datetime.now() + datetime.timedelta(seconds=timeout)
             while top == self.procName:
                 # Get log updates on each interval, but if it is taking
                 # too long, only do it every 60 seconds
@@ -385,17 +389,17 @@ class RemoteAutomation(Automation):
                     status = 1
                     break
                 if (noOutputTimeout and noOutputTimer > noOutputTimeout):
                     status = 2
                     break
                 if not hasOutput:
                     top = self.device.get_top_activity(timeout=60)
                     if top is None:
-                        print "Failed to get top activity, retrying, once..."
+                        print("Failed to get top activity, retrying, once...")
                         top = self.device.get_top_activity(timeout=60)
             # Flush anything added to stdout during the sleep
             self.read_stdout()
             return status
 
         def kill(self, stagedShutdown=False):
             if self.utilityPath:
                 # Take a screenshot to capture the screen state just before
@@ -403,33 +407,33 @@ class RemoteAutomation(Automation):
                 # options but they rarely work well with Firefox on the
                 # Android emulator. dump_screen provides an effective
                 # screenshot of the emulator and its host desktop.
                 dump_screen(self.utilityPath, get_default_logger())
             if stagedShutdown:
                 # Trigger an ANR report with "kill -3" (SIGQUIT)
                 try:
                     self.device.pkill(self.procName, sig=3, attempts=1)
-                except:
+                except:  # NOQA: E722
                     pass
                 time.sleep(3)
                 # Trigger a breakpad dump with "kill -6" (SIGABRT)
                 try:
                     self.device.pkill(self.procName, sig=6, attempts=1)
-                except:
+                except:  # NOQA: E722
                     pass
                 # Wait for process to end
                 retries = 0
                 while retries < 3:
                     if self.device.process_exist(self.procName):
-                        print "%s still alive after SIGABRT: waiting..." % self.procName
+                        print("%s still alive after SIGABRT: waiting..." % self.procName)
                         time.sleep(5)
                     else:
                         return
                     retries += 1
                 try:
                     self.device.pkill(self.procName, sig=9, attempts=1)
-                except:
-                    print "%s still alive after SIGKILL!" % self.procName
+                except:  # NOQA: E722
+                    print("%s still alive after SIGKILL!" % self.procName)
                 if self.device.process_exist(self.procName):
                     self.device.stop_application(self.procName)
             else:
                 self.device.stop_application(self.procName)
--- a/build/pgo/genpgocert.py
+++ b/build/pgo/genpgocert.py
@@ -9,17 +9,16 @@
 
 import mozinfo
 import os
 import random
 import re
 import shutil
 import subprocess
 import sys
-import tempfile
 import distutils
 
 from mozbuild.base import MozbuildObject
 from mozfile import NamedTemporaryFile, TemporaryDirectory
 from mozprofile.permissions import ServerLocations
 
 dbFiles = [
     re.compile("^cert[0-9]+\.db$"),
@@ -76,33 +75,31 @@ def writeCertspecForServerLocations(fd):
         customCertRE = re.compile("^cert=(?:\w+)")
         for _ in [i for i in loc.options if customCertRE.match(i)]:
             customCertOption = True
             break
 
         if not customCertOption:
             SAN.append(loc.host)
 
-    fd.write("issuer:printableString/CN=Temporary Certificate Authority/O=Mozilla Testing/OU=Profile Guided Optimization\n")
+    fd.write("issuer:printableString/CN=Temporary Certificate Authority/O=Mozilla Testing/OU=Profile Guided Optimization\n")  # NOQA: E501
     fd.write("subject:{}\n".format(SAN[0]))
     fd.write("extension:subjectAlternativeName:{}\n".format(",".join(SAN)))
 
 
 def constructCertDatabase(build, srcDir):
     certutil = build.get_binary_path(what="certutil")
     pk12util = build.get_binary_path(what="pk12util")
     openssl = distutils.spawn.find_executable("openssl")
     pycert = os.path.join(build.topsrcdir, "security", "manager", "ssl", "tests",
                           "unit", "pycert.py")
     pykey = os.path.join(build.topsrcdir, "security", "manager", "ssl", "tests",
                          "unit", "pykey.py")
 
-    with NamedTemporaryFile() as pwfile, NamedTemporaryFile() as rndfile, TemporaryDirectory() as pemfolder:
-        pgoCAPath = os.path.join(srcDir, "pgoca.p12")
-
+    with NamedTemporaryFile() as pwfile, TemporaryDirectory() as pemfolder:
         pwfile.write("\n")
         pwfile.flush()
 
         if dbFilesExist(srcDir):
             # Make sure all DB files from src are really deleted
             unlinkDbFiles(srcDir)
 
         # Copy  all .certspec and .keyspec files to a temporary directory
@@ -131,49 +128,54 @@ def constructCertDatabase(build, srcDir)
                     certspec_data = certspec_file.read()
                     with open(pem, "w") as pem_file:
                         status = runUtil(
                             pycert, [], inputdata=certspec_data, outputstream=pem_file)
                         if status:
                             return status
 
                 status = runUtil(certutil, [
-                                 "-A", "-n", name, "-t", "P,,", "-i", pem, "-d", srcDir, "-f", pwfile.name])
+                                 "-A", "-n", name, "-t", "P,,", "-i", pem,
+                                 "-d", srcDir, "-f", pwfile.name
+                                 ])
                 if status:
                     return status
 
             for keyspec in [i for i in files if i.endswith(".keyspec")]:
                 parts = keyspec.split(".")
                 name = parts[0]
                 key_type = parts[1]
                 if key_type not in ["ca", "client", "server"]:
-                    raise Exception("{}: keyspec filenames must be of the form XXX.client.keyspec or XXX.ca.keyspec (key_type={})".format(
-                        keyspec, key_type))
+                    raise Exception("{}: keyspec filenames must be of the form XXX.client.keyspec "
+                                    "or XXX.ca.keyspec (key_type={})".format(
+                                        keyspec, key_type))
                 key_pem = os.path.join(pemfolder, "{}.key.pem".format(name))
 
                 print("Generating private key {} (pem={})".format(name, key_pem))
 
                 with open(os.path.join(root, keyspec), "r") as keyspec_file:
                     keyspec_data = keyspec_file.read()
                     with open(key_pem, "w") as pem_file:
                         status = runUtil(
                             pykey, [], inputdata=keyspec_data, outputstream=pem_file)
                         if status:
                             return status
 
                 cert_pem = os.path.join(pemfolder, "{}.cert.pem".format(name))
                 if not os.path.exists(cert_pem):
-                    raise Exception("There has to be a corresponding certificate named {} for the keyspec {}".format(
-                        cert_pem, keyspec))
+                    raise Exception("There has to be a corresponding certificate named {} for "
+                                    "the keyspec {}".format(
+                                        cert_pem, keyspec))
 
                 p12 = os.path.join(pemfolder, "{}.key.p12".format(name))
                 print("Converting private key {} to PKCS12 (p12={})".format(
                     key_pem, p12))
                 status = runUtil(openssl, ["pkcs12", "-export", "-inkey", key_pem, "-in",
-                                           cert_pem, "-name", name, "-out", p12, "-passout", "file:"+pwfile.name])
+                                           cert_pem, "-name", name, "-out", p12, "-passout",
+                                           "file:"+pwfile.name])
                 if status:
                     return status
 
                 print("Importing private key {} to database".format(key_pem))
                 status = runUtil(
                     pk12util, ["-i", p12, "-d", srcDir, "-w", pwfile.name, "-k", pwfile.name])
                 if status:
                     return status
@@ -192,10 +194,10 @@ def constructCertDatabase(build, srcDir)
 
     return 0
 
 
 build = MozbuildObject.from_environment()
 certdir = os.path.join(build.topsrcdir, "build", "pgo", "certs")
 certificateStatus = constructCertDatabase(build, certdir)
 if certificateStatus:
-    print "TEST-UNEXPECTED-FAIL | SSL Server Certificate generation"
+    print("TEST-UNEXPECTED-FAIL | SSL Server Certificate generation")
 sys.exit(certificateStatus)
--- a/build/pgo/profileserver.py
+++ b/build/pgo/profileserver.py
@@ -6,17 +6,17 @@
 
 import json
 import os
 
 from buildconfig import substs
 from mozbuild.base import MozbuildObject
 from mozfile import TemporaryDirectory
 from mozhttpd import MozHttpd
-from mozprofile import FirefoxProfile, Profile, Preferences
+from mozprofile import FirefoxProfile, Preferences
 from mozprofile.permissions import ServerLocations
 from mozrunner import FirefoxRunner, CLI
 from six import string_types
 
 PORT = 8888
 
 PATH_MAPPINGS = {
     '/js-input/webkit/PerformanceTests': 'third_party/webkit/PerformanceTests',
@@ -61,17 +61,18 @@ if __name__ == '__main__':
         for k, v in prefs.items():
             if isinstance(v, string_types):
                 v = v.format(**interpolation)
             prefs[k] = Preferences.cast(v)
 
         profile = FirefoxProfile(profile=profilePath,
                                  preferences=prefs,
                                  addons=[os.path.join(
-                                     build.topsrcdir, 'tools', 'quitter', 'quitter@mozilla.org.xpi')],
+                                     build.topsrcdir, 'tools', 'quitter',
+                                     'quitter@mozilla.org.xpi')],
                                  locations=locations)
 
         env = os.environ.copy()
         env["MOZ_CRASHREPORTER_NO_REPORT"] = "1"
         env["XPCOM_DEBUG_BREAK"] = "warn"
 
         # For VC12+, make sure we can find the right bitness of pgort1x0.dll
         if not substs.get('HAVE_64BIT_BUILD'):
@@ -91,17 +92,17 @@ if __name__ == '__main__':
                                cmdargs=['javascript:Quitter.quit()'],
                                env=env)
         runner.start()
         runner.wait()
 
         jarlog = os.getenv("JARLOG_FILE")
         if jarlog:
             env["MOZ_JAR_LOG_FILE"] = os.path.abspath(jarlog)
-            print "jarlog: %s" % env["MOZ_JAR_LOG_FILE"]
+            print("jarlog: %s" % env["MOZ_JAR_LOG_FILE"])
 
         cmdargs = ["http://localhost:%d/index.html" % PORT]
         runner = FirefoxRunner(profile=profile,
                                binary=build.get_binary_path(
                                    where="staged-package"),
                                cmdargs=cmdargs,
                                env=env)
         runner.start(debug_args=debug_args, interactive=interactive)
--- a/build/unix/rewrite_asan_dylib.py
+++ b/build/unix/rewrite_asan_dylib.py
@@ -85,27 +85,31 @@ def scan_directory(path):
 
                         if os.path.isfile(copyDylibPath):
                             # Copy the runtime once to the main directory, which is passed
                             # as the argument to this function.
                             shutil.copy(copyDylibPath, path)
 
                             # Now rewrite the library itself
                             subprocess.check_call(
-                                [substs['INSTALL_NAME_TOOL'], '-id', '@executable_path/' + DYLIB_NAME, os.path.join(path, DYLIB_NAME)])
+                                [substs['INSTALL_NAME_TOOL'], '-id',
+                                 '@executable_path/' + DYLIB_NAME,
+                                 os.path.join(path, DYLIB_NAME)])
                             dylibCopied = True
                         else:
                             sys.stderr.write('dylib path in %s was not found at: %s\n' % (
                                 filename, copyDylibPath))
 
                     # Now use install_name_tool to rewrite the path in our binary
                     relpath = '' if path == root else os.path.relpath(
                         path, root) + '/'
                     subprocess.check_call([substs['INSTALL_NAME_TOOL'], '-change',
-                                           absDylibPath, '@executable_path/' + relpath + DYLIB_NAME, filename])
+                                           absDylibPath,
+                                           '@executable_path/' + relpath + DYLIB_NAME,
+                                           filename])
                     break
 
     if not dylibCopied:
         sys.stderr.write('%s could not be found\n' % DYLIB_NAME)
         sys.exit(1)
 
 
 if __name__ == '__main__':
--- a/build/util/count_ctors.py
+++ b/build/util/count_ctors.py
@@ -1,9 +1,8 @@
-
 #!/usr/bin/python
 import json
 
 import re
 import subprocess
 import sys
 
 
@@ -59,9 +58,9 @@ if __name__ == '__main__':
                 "subtests": [{
                     "name": "num_static_constructors",
                     "value": count_ctors(f),
                     "alertChangeType": "absolute",
                     "alertThreshold": 3
                 }]}
             ]
         }
-        print "PERFHERDER_DATA: %s" % json.dumps(perfherder_data)
+        print("PERFHERDER_DATA: %s" % json.dumps(perfherder_data))
--- a/build/valgrind/mach_commands.py
+++ b/build/valgrind/mach_commands.py
@@ -3,17 +3,16 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from __future__ import absolute_import, unicode_literals
 
 import json
 import logging
 import mozinfo
 import os
-import subprocess
 
 from mach.decorators import (
     Command,
     CommandArgument,
     CommandProvider,
 )
 from mozbuild.base import (
     MachCommandBase,
@@ -40,20 +39,17 @@ class MachCommands(MachCommandBase):
              conditions=[conditions.is_firefox, is_valgrind_build],
              description='Run the Valgrind test job (memory-related errors).')
     @CommandArgument('--suppressions', default=[], action='append',
                      metavar='FILENAME',
                      help='Specify a suppression file for Valgrind to use. Use '
                      '--suppression multiple times to specify multiple suppression '
                      'files.')
     def valgrind_test(self, suppressions):
-        import sys
-        import tempfile
 
-        from mozbuild.base import MozbuildObject
         from mozfile import TemporaryDirectory
         from mozhttpd import MozHttpd
         from mozprofile import FirefoxProfile, Preferences
         from mozprofile.permissions import ServerLocations
         from mozrunner import FirefoxRunner
         from mozrunner.utils import findInPath
         from six import string_types
         from valgrind.output_handler import OutputHandler
@@ -167,31 +163,34 @@ class MachCommands(MachCommandBase):
 
             finally:
                 errs = outputHandler.error_count
                 supps = outputHandler.suppression_count
                 if errs != supps:
                     status = 1  # turns the TBPL job orange
                     self.log(logging.ERROR, 'valgrind-fail-parsing',
                              {'errs': errs, 'supps': supps},
-                             'TEST-UNEXPECTED-FAIL | valgrind-test | error parsing: {errs} errors seen, but {supps} generated suppressions seen')
+                             'TEST-UNEXPECTED-FAIL | valgrind-test | error parsing: {errs} errors '
+                             'seen, but {supps} generated suppressions seen')
 
                 elif errs == 0:
                     status = 0
                     self.log(logging.INFO, 'valgrind-pass', {},
                              'TEST-PASS | valgrind-test | valgrind found no errors')
                 else:
                     status = 1  # turns the TBPL job orange
                     # We've already printed details of the errors.
 
-                if exitcode == None:
+                if exitcode is None:
                     status = 2  # turns the TBPL job red
                     self.log(logging.ERROR, 'valgrind-fail-timeout',
                              {'timeout': timeout},
-                             'TEST-UNEXPECTED-FAIL | valgrind-test | Valgrind timed out (reached {timeout} second limit)')
+                             'TEST-UNEXPECTED-FAIL | valgrind-test | Valgrind timed out '
+                             '(reached {timeout} second limit)')
                 elif exitcode != 0:
                     status = 2  # turns the TBPL job red
                     self.log(logging.ERROR, 'valgrind-fail-errors', {},
-                             'TEST-UNEXPECTED-FAIL | valgrind-test | non-zero exit code from Valgrind')
+                             'TEST-UNEXPECTED-FAIL | valgrind-test | non-zero exit code'
+                             'from Valgrind')
 
                 httpd.stop()
 
             return status
--- a/build/valgrind/output_handler.py
+++ b/build/valgrind/output_handler.py
@@ -33,17 +33,17 @@ class OutputHandler(object):
     Parsing the Valgrind output isn't ideal, and it may break in the future if
     Valgrind changes the format of the messages, or introduces new error kinds.
     To protect against this, we also count how many lines containing
     "<insert_a_suppression_name_here>" are seen. Thanks to the use of
     --gen-suppressions=yes, exactly one of these lines is present per error. If
     the count of these lines doesn't match the error count found during
     parsing, then the parsing has missed one or more errors and we can fail
     appropriately.
-    '''
+    '''  # NOQA: E501
 
     def __init__(self, logger):
         # The regexps in this list match all of Valgrind's errors. Note that
         # Valgrind is English-only, so we don't have to worry about
         # localization.
         self.logger = logger
         self.re_error = \
             r'==\d+== (' + \
--- a/build/win32/autobinscope.py
+++ b/build/win32/autobinscope.py
@@ -14,47 +14,48 @@
 import sys
 import subprocess
 import os
 
 BINSCOPE_OUTPUT_LOGFILE = r".\binscope_xml_output.log"
 
 # usage
 if len(sys.argv) < 3:
-    print """usage : autobinscope.by path_to_binary path_to_symbols [log_file_path]"
-		log_file_path is optional, log will be written to .\binscope_xml_output.log by default"""
+    print("""usage : autobinscope.by path_to_binary path_to_symbols [log_file_path]"
+    log_file_path is optional, log will be written to .\binscope_xml_output.log by default""")
     sys.exit(0)
 
 binary_path = sys.argv[1]
 symbol_path = sys.argv[2]
 
 if len(sys.argv) == 4:
     log_file_path = sys.argv[3]
 else:
     log_file_path = BINSCOPE_OUTPUT_LOGFILE
 
 # execute binscope against the binary, using the BINSCOPE environment
 # variable as the path to binscope.exe
 try:
     binscope_path = os.environ['BINSCOPE']
 except KeyError:
-    print "TEST-UNEXPECTED-FAIL | autobinscope.py | BINSCOPE environment variable is not set, can't check DEP/ASLR etc. status."
+    print("TEST-UNEXPECTED-FAIL | autobinscope.py | BINSCOPE environment variable is not set, "
+          "can't check DEP/ASLR etc. status.")
     sys.exit(0)
 
 try:
     proc = subprocess.Popen([
         binscope_path,
         "/NoLogo",
         "/Target", binary_path,
         "/SymPath", symbol_path,
         "/Checks", "ATLVersionCheck",
         "/Checks", "ATLVulnCheck",
         # We do not ship in the Windows Store
         "/SkippedChecks", "AppContainerCheck",
-        # The CompilerVersionCheck doesn't like clang-cl (we would need to set MinimumCompilerVersion)
+        # The CompilerVersionCheck doesn't like clang-cl (we would need to set MinimumCompilerVersion)  # NOQA: E501
         # But we check the compiler in our build system anyway, so this doesn't seem useful
         "/SkippedChecks", "CompilerVersionCheck",
         "/Checks", "DBCheck",
         "/Checks", "DefaultGSCookieCheck",
         "/Checks", "ExecutableImportsCheck",
         # FunctonPointersCheck is disabled per bug 1014002
         "/SkippedChecks", "FunctionPointersCheck",
         # GSCheck doesn't know how to deal with Rust libs
@@ -68,33 +69,34 @@ try:
         "/Checks", "SafeSEHCheck",
         "/Checks", "SharedSectionCheck",
         "/Checks", "VB6Check",
         "/Checks", "WXCheck"
     ], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
 
 except WindowsError, (errno, strerror):
     if errno != 2 and errno != 3:
-        print "TEST-UNEXPECTED-FAIL | autobinscope.py | Unexpected error %d : %s" (
-            errno, strerror)
+        print("TEST-UNEXPECTED-FAIL | autobinscope.py | Unexpected error %d : %s" (
+            errno, strerror))
         sys.exit(0)
     else:
-        print "TEST-UNEXPECTED-FAIL | autobinscope.py | Could not locate binscope at location : %s\n" % binscope_path
+        print("TEST-UNEXPECTED-FAIL | autobinscope.py | Could not locate binscope at location : "
+              "%s\n" % binscope_path)
         sys.exit(0)
 
 proc.wait()
 
 output = proc.communicate()[1].decode('utf-8').splitlines()
 
 errors = 0
 for line in output:
     print(line)
     if 'error' in line:
         errors += 1
 
 if proc.returncode != 0:
-    print "TEST-UNEXPECTED-FAIL | autobinscope.py | Binscope returned error code %d for file %s" % (
-        proc.returncode, binary_path)
+    print("TEST-UNEXPECTED-FAIL | autobinscope.py | Binscope returned error code %d for file %s" %
+          (proc.returncode, binary_path))
 elif errors != 0:
-    print "TEST-UNEXPECTED-FAIL | autobinscope.py | Binscope reported %d error(s) for file %s" % (
-        errors, binary_path)
+    print("TEST-UNEXPECTED-FAIL | autobinscope.py | Binscope reported %d error(s) for file %s" % (
+        errors, binary_path))
 else:
-    print "TEST-PASS | autobinscope.py | %s succeeded" % binary_path
+    print("TEST-PASS | autobinscope.py | %s succeeded" % binary_path)