[llvm] r315084 - Run pyformat on lit code.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 6 10:54:27 PDT 2017


Author: zturner
Date: Fri Oct  6 10:54:27 2017
New Revision: 315084

URL: http://llvm.org/viewvc/llvm-project?rev=315084&view=rev
Log:
Run pyformat on lit code.

Modified:
    llvm/trunk/test/lit.cfg.py
    llvm/trunk/utils/lit/lit/llvm/config.py
    llvm/trunk/utils/lit/lit/util.py

Modified: llvm/trunk/test/lit.cfg.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/lit.cfg.py?rev=315084&r1=315083&r2=315084&view=diff
==============================================================================
--- llvm/trunk/test/lit.cfg.py (original)
+++ llvm/trunk/test/lit.cfg.py Fri Oct  6 10:54:27 2017
@@ -38,7 +38,8 @@ config.test_exec_root = os.path.join(con
 llvm_config.with_environment('PATH', config.llvm_tools_dir, append_path=True)
 
 # Propagate some variables from the host environment.
-llvm_config.with_system_environment(['HOME', 'INCLUDE', 'LIB', 'TMP', 'TEMP', 'ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH'])
+llvm_config.with_system_environment(
+    ['HOME', 'INCLUDE', 'LIB', 'TMP', 'TEMP', 'ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH'])
 
 
 # Set up OCAMLPATH to include newly built OCaml libraries.
@@ -50,33 +51,37 @@ llvm_config.with_environment('OCAMLPATH'
 llvm_config.with_environment('OCAMLPATH', llvm_ocaml_lib, append_path=True)
 
 llvm_config.with_system_environment('CAML_LD_LIBRARY_PATH')
-llvm_config.with_environment('CAML_LD_LIBRARY_PATH', llvm_ocaml_lib, append_path=True)
+llvm_config.with_environment(
+    'CAML_LD_LIBRARY_PATH', llvm_ocaml_lib, append_path=True)
 
 # Set up OCAMLRUNPARAM to enable backtraces in OCaml tests.
 llvm_config.with_environment('OCAMLRUNPARAM', 'b')
 
 # Provide the path to asan runtime lib 'libclang_rt.asan_osx_dynamic.dylib' if
 # available. This is darwin specific since it's currently only needed on darwin.
+
+
 def get_asan_rtlib():
-    if not "Address" in config.llvm_use_sanitizer or \
-       not "Darwin" in config.host_os or \
-       not "x86" in config.host_triple:
-        return ""
+    if not 'Address' in config.llvm_use_sanitizer or \
+       not 'Darwin' in config.host_os or \
+       not 'x86' in config.host_triple:
+        return ''
     try:
         import glob
     except:
-        print("glob module not found, skipping get_asan_rtlib() lookup")
-        return ""
+        print('glob module not found, skipping get_asan_rtlib() lookup')
+        return ''
     # The libclang_rt.asan_osx_dynamic.dylib path is obtained using the relative
     # path from the host cc.
-    host_lib_dir = os.path.join(os.path.dirname(config.host_cc), "../lib")
+    host_lib_dir = os.path.join(os.path.dirname(config.host_cc), '../lib')
     asan_dylib_dir_pattern = host_lib_dir + \
-        "/clang/*/lib/darwin/libclang_rt.asan_osx_dynamic.dylib"
+        '/clang/*/lib/darwin/libclang_rt.asan_osx_dynamic.dylib'
     found_dylibs = glob.glob(asan_dylib_dir_pattern)
     if len(found_dylibs) != 1:
-        return ""
+        return ''
     return found_dylibs[0]
 
+
 lli = 'lli'
 # The target triple used by default by lli is the process target triple (some
 # triple appropriate for generating code for the current process) but because
@@ -84,23 +89,24 @@ lli = 'lli'
 # Windows.  FIXME: the process target triple should be used here, but this is
 # difficult to obtain on Windows.
 if re.search(r'cygwin|mingw32|windows-gnu|windows-msvc|win32', config.host_triple):
-  lli += ' -mtriple='+config.host_triple+'-elf'
-config.substitutions.append( ('%lli', lli ) )
+    lli += ' -mtriple=' + config.host_triple + '-elf'
+config.substitutions.append(('%lli', lli))
 
 # Similarly, have a macro to use llc with DWARF even when the host is win32.
 llc_dwarf = 'llc'
 if re.search(r'win32', config.target_triple):
-  llc_dwarf += ' -mtriple='+config.target_triple.replace('-win32', '-mingw32')
-config.substitutions.append( ('%llc_dwarf', llc_dwarf) )
+    llc_dwarf += ' -mtriple=' + \
+        config.target_triple.replace('-win32', '-mingw32')
+config.substitutions.append(('%llc_dwarf', llc_dwarf))
 
 # Add site-specific substitutions.
-config.substitutions.append( ('%gold', config.gold_executable) )
-config.substitutions.append( ('%go', config.go_executable) )
-config.substitutions.append( ('%llvmshlibdir', config.llvm_shlib_dir) )
-config.substitutions.append( ('%shlibext', config.llvm_shlib_ext) )
-config.substitutions.append( ('%exeext', config.llvm_exe_ext) )
-config.substitutions.append( ('%python', config.python_executable) )
-config.substitutions.append( ('%host_cc', config.host_cc) )
+config.substitutions.append(('%gold', config.gold_executable))
+config.substitutions.append(('%go', config.go_executable))
+config.substitutions.append(('%llvmshlibdir', config.llvm_shlib_dir))
+config.substitutions.append(('%shlibext', config.llvm_shlib_ext))
+config.substitutions.append(('%exeext', config.llvm_exe_ext))
+config.substitutions.append(('%python', config.python_executable))
+config.substitutions.append(('%host_cc', config.host_cc))
 
 # Provide the path to asan runtime lib if available. On darwin, this lib needs
 # to be loaded via DYLD_INSERT_LIBRARIES before libLTO.dylib in case the files
@@ -108,20 +114,20 @@ config.substitutions.append( ('%host_cc'
 ld64_cmd = config.ld64_executable
 asan_rtlib = get_asan_rtlib()
 if asan_rtlib:
-  ld64_cmd = "DYLD_INSERT_LIBRARIES={} {}".format(asan_rtlib, ld64_cmd)
-config.substitutions.append( ('%ld64', ld64_cmd) )
+    ld64_cmd = 'DYLD_INSERT_LIBRARIES={} {}'.format(asan_rtlib, ld64_cmd)
+config.substitutions.append(('%ld64', ld64_cmd))
 
 # OCaml substitutions.
 # Support tests for both native and bytecode builds.
-config.substitutions.append( ('%ocamlc',
-    "%s ocamlc -cclib -L%s %s" %
-        (config.ocamlfind_executable, config.llvm_lib_dir, config.ocaml_flags)) )
+config.substitutions.append(('%ocamlc',
+                             '%s ocamlc -cclib -L%s %s' %
+                             (config.ocamlfind_executable, config.llvm_lib_dir, config.ocaml_flags)))
 if config.have_ocamlopt:
-    config.substitutions.append( ('%ocamlopt',
-        "%s ocamlopt -cclib -L%s -cclib -Wl,-rpath,%s %s" %
-            (config.ocamlfind_executable, config.llvm_lib_dir, config.llvm_lib_dir, config.ocaml_flags)) )
+    config.substitutions.append(('%ocamlopt',
+                                 '%s ocamlopt -cclib -L%s -cclib -Wl,-rpath,%s %s' %
+                                 (config.ocamlfind_executable, config.llvm_lib_dir, config.llvm_lib_dir, config.ocaml_flags)))
 else:
-    config.substitutions.append( ('%ocamlopt', "true" ) )
+    config.substitutions.append(('%ocamlopt', 'true'))
 
 # For each occurrence of an llvm tool name as its own word, replace it
 # with the full path to the build directory holding that tool.  This
@@ -169,14 +175,14 @@ optional_tools = [
 llvm_config.add_tool_substitutions(optional_tools, config.llvm_tools_dir,
                                    warn_missing=False)
 
-### Targets
+# Targets
 
 config.targets = frozenset(config.targets_to_build.split())
 
 for arch in config.targets_to_build.split():
     config.available_features.add(arch.lower() + '-registered-target')
 
-### Features
+# Features
 
 # Others/can-execute.txt
 if sys.platform not in ['win32']:
@@ -195,24 +201,26 @@ if loadable_module:
 
 # Static libraries are not built if BUILD_SHARED_LIBS is ON.
 if not config.build_shared_libs:
-    config.available_features.add("static-libs")
+    config.available_features.add('static-libs')
 
 # Direct object generation
 if not 'hexagon' in config.target_triple:
-    config.available_features.add("object-emission")
+    config.available_features.add('object-emission')
 
 # LLVM can be configured with an empty default triple
 # Some tests are "generic" and require a valid default triple
 if config.target_triple:
-    config.available_features.add("default_triple")
+    config.available_features.add('default_triple')
 
 import subprocess
 
+
 def have_ld_plugin_support():
     if not os.path.exists(os.path.join(config.llvm_shlib_dir, 'LLVMgold.so')):
         return False
 
-    ld_cmd = subprocess.Popen([config.gold_executable, '--help'], stdout = subprocess.PIPE, env={'LANG': 'C'})
+    ld_cmd = subprocess.Popen(
+        [config.gold_executable, '--help'], stdout=subprocess.PIPE, env={'LANG': 'C'})
     ld_out = ld_cmd.stdout.read().decode()
     ld_cmd.wait()
 
@@ -233,21 +241,25 @@ def have_ld_plugin_support():
     if 'elf32ppc' in emulations:
         config.available_features.add('ld_emu_elf32ppc')
 
-    ld_version = subprocess.Popen([config.gold_executable, '--version'], stdout = subprocess.PIPE, env={'LANG': 'C'})
+    ld_version = subprocess.Popen(
+        [config.gold_executable, '--version'], stdout=subprocess.PIPE, env={'LANG': 'C'})
     if not 'GNU gold' in ld_version.stdout.read().decode():
         return False
     ld_version.wait()
 
     return True
 
+
 if have_ld_plugin_support():
     config.available_features.add('ld_plugin')
 
+
 def have_ld64_plugin_support():
     if not config.llvm_tool_lto_build or config.ld64_executable == '':
         return False
 
-    ld_cmd = subprocess.Popen([config.ld64_executable, '-v'], stderr = subprocess.PIPE)
+    ld_cmd = subprocess.Popen(
+        [config.ld64_executable, '-v'], stderr=subprocess.PIPE)
     ld_out = ld_cmd.stderr.read().decode()
     ld_cmd.wait()
 
@@ -256,22 +268,23 @@ def have_ld64_plugin_support():
 
     return True
 
+
 if have_ld64_plugin_support():
     config.available_features.add('ld64_plugin')
 
 # Ask llvm-config about asserts and global-isel.
 llvm_config.feature_config(
-  [('--assertion-mode', {'ON' : 'asserts'}),
-   ('--has-global-isel', {'ON' : 'global-isel'})])
+    [('--assertion-mode', {'ON': 'asserts'}),
+     ('--has-global-isel', {'ON': 'global-isel'})])
 
 if 'darwin' == sys.platform:
     try:
         sysctl_cmd = subprocess.Popen(['sysctl', 'hw.optional.fma'],
-                                    stdout = subprocess.PIPE)
+                                      stdout=subprocess.PIPE)
     except OSError:
-        print("Could not exec sysctl")
+        print('Could not exec sysctl')
     result = sysctl_cmd.stdout.read().decode('ascii')
-    if -1 != result.find("hw.optional.fma: 1"):
+    if -1 != result.find('hw.optional.fma: 1'):
         config.available_features.add('fma3')
     sysctl_cmd.wait()
 
@@ -282,5 +295,5 @@ if not re.match(r'^x86_64.*-(mingw32|win
 if config.have_libxar:
     config.available_features.add('xar')
 
-if config.llvm_libxml2_enabled == "1":
+if config.llvm_libxml2_enabled == '1':
     config.available_features.add('libxml2')

Modified: llvm/trunk/utils/lit/lit/llvm/config.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/llvm/config.py?rev=315084&r1=315083&r2=315084&view=diff
==============================================================================
--- llvm/trunk/utils/lit/lit/llvm/config.py (original)
+++ llvm/trunk/utils/lit/lit/llvm/config.py Fri Oct  6 10:54:27 2017
@@ -6,9 +6,11 @@ import sys
 
 import lit.util
 
+
 def binary_feature(on, feature, off_prefix):
     return feature if on else off_prefix + feature
 
+
 class LLVMConfig(object):
 
     def __init__(self, lit_config, config):
@@ -25,22 +27,21 @@ class LLVMConfig(object):
 
             # Seek sane tools in directories and set to $PATH.
             path = self.lit_config.getToolsPath(config.lit_tools_dir,
-                                           config.environment['PATH'],
-                                           ['cmp.exe', 'grep.exe', 'sed.exe'])
+                                                config.environment['PATH'],
+                                                ['cmp.exe', 'grep.exe', 'sed.exe'])
             if path is not None:
                 self.with_environment('PATH', path, append_path=True)
             self.use_lit_shell = True
 
         # Choose between lit's internal shell pipeline runner and a real shell.  If
         # LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override.
-        lit_shell_env = os.environ.get("LIT_USE_INTERNAL_SHELL")
+        lit_shell_env = os.environ.get('LIT_USE_INTERNAL_SHELL')
         if lit_shell_env:
             self.use_lit_shell = lit.util.pythonize_bool(lit_shell_env)
 
         if not self.use_lit_shell:
             features.add('shell')
 
-
         # Running on Darwin OS
         if platform.system() in ['Darwin']:
             # FIXME: lld uses the first, other projects use the second.
@@ -57,29 +58,31 @@ class LLVMConfig(object):
         host_triple = getattr(config, 'host_triple', None)
         target_triple = getattr(config, 'target_triple', None)
         if host_triple and host_triple == target_triple:
-            features.add("native")
+            features.add('native')
 
         # Sanitizers.
         sanitizers = getattr(config, 'llvm_use_sanitizer', '')
         sanitizers = frozenset(x.lower() for x in sanitizers.split(';'))
         features.add(binary_feature('address' in sanitizers, 'asan', 'not_'))
         features.add(binary_feature('memory' in sanitizers, 'msan', 'not_'))
-        features.add(binary_feature('undefined' in sanitizers, 'ubsan', 'not_'))
+        features.add(binary_feature(
+            'undefined' in sanitizers, 'ubsan', 'not_'))
 
         have_zlib = getattr(config, 'have_zlib', None)
         features.add(binary_feature(have_zlib, 'zlib', 'no'))
 
         # Check if we should run long running tests.
-        long_tests = lit_config.params.get("run_long_tests", None)
+        long_tests = lit_config.params.get('run_long_tests', None)
         if lit.util.pythonize_bool(long_tests):
-            features.add("long_tests")
+            features.add('long_tests')
 
         if target_triple:
             if re.match(r'^x86_64.*-apple', target_triple):
                 if 'address' in sanitizers:
-                    self.with_environment('ASAN_OPTIONS', 'detect_leaks=1', append_path=True)
+                    self.with_environment(
+                        'ASAN_OPTIONS', 'detect_leaks=1', append_path=True)
             if re.match(r'^x86_64.*-linux', target_triple):
-                features.add("x86_64-linux")
+                features.add('x86_64-linux')
             if re.match(r'.*-win32$', target_triple):
                 features.add('target-windows')
 
@@ -90,13 +93,14 @@ class LLVMConfig(object):
             gmalloc_path_str = lit_config.params.get('gmalloc_path',
                                                      '/usr/lib/libgmalloc.dylib')
             if gmalloc_path_str is not None:
-                self.with_environment('DYLD_INSERT_LIBRARIES', gmalloc_path_str)
+                self.with_environment(
+                    'DYLD_INSERT_LIBRARIES', gmalloc_path_str)
 
         breaking_checks = getattr(config, 'enable_abi_breaking_checks', None)
         if lit.util.pythonize_bool(breaking_checks):
             features.add('abi-breaking-checks')
 
-    def with_environment(self, variable, value, append_path = False):
+    def with_environment(self, variable, value, append_path=False):
         if append_path:
             # For paths, we should be able to take a list of them and process all
             # of them.
@@ -129,8 +133,7 @@ class LLVMConfig(object):
             value = os.pathsep.join(paths)
         self.config.environment[variable] = value
 
-
-    def with_system_environment(self, variables, append_path = False):
+    def with_system_environment(self, variables, append_path=False):
         if lit.util.is_string(variables):
             variables = [variables]
         for v in variables:
@@ -153,7 +156,7 @@ class LLVMConfig(object):
             stderr = lit.util.to_string(stderr)
             return (stdout, stderr)
         except OSError:
-            self.lit_config.fatal("Could not run process %s" % command)
+            self.lit_config.fatal('Could not run process %s' % command)
 
     def feature_config(self, features):
         # Ask llvm-config about the specified feature.
@@ -175,17 +178,18 @@ class LLVMConfig(object):
                     if re.search(re_pattern, feature_line):
                         self.config.available_features.add(feature)
 
-
     # Note that when substituting %clang_cc1 also fill in the include directory of
     # the builtin headers. Those are part of even a freestanding environment, but
     # Clang relies on the driver to locate them.
     def get_clang_builtin_include_dir(self, clang):
         # FIXME: Rather than just getting the version, we should have clang print
         # out its resource dir here in an easy to scrape form.
-        clang_dir, _ = self.get_process_output([clang, '-print-file-name=include'])
+        clang_dir, _ = self.get_process_output(
+            [clang, '-print-file-name=include'])
 
         if not clang_dir:
-          self.lit_config.fatal("Couldn't find the include dir for Clang ('%s')" % clang)
+            self.lit_config.fatal(
+                "Couldn't find the include dir for Clang ('%s')" % clang)
 
         clang_dir = clang_dir.strip()
         if sys.platform in ['win32'] and not self.use_lit_shell:
@@ -197,29 +201,31 @@ class LLVMConfig(object):
     def make_itanium_abi_triple(self, triple):
         m = re.match(r'(\w+)-(\w+)-(\w+)', triple)
         if not m:
-          self.lit_config.fatal("Could not turn '%s' into Itanium ABI triple" % triple)
+            self.lit_config.fatal(
+                "Could not turn '%s' into Itanium ABI triple" % triple)
         if m.group(3).lower() != 'win32':
-          # All non-win32 triples use the Itanium ABI.
-          return triple
+            # All non-win32 triples use the Itanium ABI.
+            return triple
         return m.group(1) + '-' + m.group(2) + '-mingw32'
 
     def make_msabi_triple(self, triple):
         m = re.match(r'(\w+)-(\w+)-(\w+)', triple)
         if not m:
-          self.lit_config.fatal("Could not turn '%s' into MS ABI triple" % triple)
+            self.lit_config.fatal(
+                "Could not turn '%s' into MS ABI triple" % triple)
         isa = m.group(1).lower()
         vendor = m.group(2).lower()
         os = m.group(3).lower()
         if os == 'win32':
-          # If the OS is win32, we're done.
-          return triple
+            # If the OS is win32, we're done.
+            return triple
         if isa.startswith('x86') or isa == 'amd64' or re.match(r'i\d86', isa):
-          # For x86 ISAs, adjust the OS.
-          return isa + '-' + vendor + '-win32'
+            # For x86 ISAs, adjust the OS.
+            return isa + '-' + vendor + '-win32'
         # -win32 is not supported for non-x86 targets; use a default.
         return 'i686-pc-win32'
 
-    def add_tool_substitutions(self, tools, search_dirs, warn_missing = True):
+    def add_tool_substitutions(self, tools, search_dirs, warn_missing=True):
         if lit.util.is_string(search_dirs):
             search_dirs = [search_dirs]
 
@@ -245,7 +251,8 @@ class LLVMConfig(object):
             if not tool_path:
                 if warn_missing:
                     # Warn, but still provide a substitution.
-                    self.lit_config.note('Did not find ' + tool_name + ' in %s' % search_dirs)
+                    self.lit_config.note(
+                        'Did not find ' + tool_name + ' in %s' % search_dirs)
                 tool_path = self.config.llvm_tools_dir + '/' + tool_name
 
             if tool_name == 'llc' and os.environ.get('LLVM_ENABLE_MACHINE_VERIFIER') == '1':
@@ -253,6 +260,6 @@ class LLVMConfig(object):
             if tool_name == 'llvm-go':
                 exe = getattr(self.config, 'go_executable', None)
                 if exe:
-                    tool_path += " go=" + exe
+                    tool_path += ' go=' + exe
 
             self.config.substitutions.append((tool, tool_pipe + tool_path))

Modified: llvm/trunk/utils/lit/lit/util.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/util.py?rev=315084&r1=315083&r2=315084&view=diff
==============================================================================
--- llvm/trunk/utils/lit/lit/util.py (original)
+++ llvm/trunk/utils/lit/lit/util.py Fri Oct  6 10:54:27 2017
@@ -9,12 +9,14 @@ import subprocess
 import sys
 import threading
 
+
 def norm_path(path):
     path = os.path.realpath(path)
     path = os.path.normpath(path)
     path = os.path.normcase(path)
     return path
 
+
 def is_string(value):
     try:
         # Python 2 and Python 3 are different here.
@@ -22,6 +24,7 @@ def is_string(value):
     except NameError:
         return isinstance(value, str)
 
+
 def pythonize_bool(value):
     if value is None:
         return False
@@ -36,14 +39,17 @@ def pythonize_bool(value):
             return False
     raise ValueError('"{}" is not a valid boolean'.format(value))
 
+
 def make_word_regex(word):
     return r'\b' + word + r'\b'
 
+
 def to_bytes(s):
     """Return the parameter as type 'bytes', possibly encoding it.
 
-    In Python2, the 'bytes' type is the same as 'str'. In Python3, they are
-    distinct.
+    In Python2, the 'bytes' type is the same as 'str'. In Python3, they
+    are distinct.
+
     """
     if isinstance(s, bytes):
         # In Python2, this branch is taken for both 'str' and 'bytes'.
@@ -54,12 +60,14 @@ def to_bytes(s):
     # Encode to UTF-8 to get 'bytes' data.
     return s.encode('utf-8')
 
+
 def to_string(b):
     """Return the parameter as type 'str', possibly encoding it.
 
     In Python2, the 'str' type is the same as 'bytes'. In Python3, the
     'str' type is (essentially) Python2's 'unicode' type, and 'bytes' is
     distinct.
+
     """
     if isinstance(b, str):
         # In Python2, this branch is taken for types 'str' and 'bytes'.
@@ -91,28 +99,32 @@ def to_string(b):
     except AttributeError:
         raise TypeError('not sure how to convert %s to %s' % (type(b), str))
 
+
 def detectCPUs():
-    """
-    Detects the number of CPUs on a system. Cribbed from pp.
+    """Detects the number of CPUs on a system.
+
+    Cribbed from pp.
+
     """
     # Linux, Unix and MacOS:
-    if hasattr(os, "sysconf"):
-        if "SC_NPROCESSORS_ONLN" in os.sysconf_names:
+    if hasattr(os, 'sysconf'):
+        if 'SC_NPROCESSORS_ONLN' in os.sysconf_names:
             # Linux & Unix:
-            ncpus = os.sysconf("SC_NPROCESSORS_ONLN")
+            ncpus = os.sysconf('SC_NPROCESSORS_ONLN')
             if isinstance(ncpus, int) and ncpus > 0:
                 return ncpus
-        else: # OSX:
+        else:  # OSX:
             return int(subprocess.check_output(['sysctl', '-n', 'hw.ncpu'],
                                                stderr=subprocess.STDOUT))
     # Windows:
-    if "NUMBER_OF_PROCESSORS" in os.environ:
-        ncpus = int(os.environ["NUMBER_OF_PROCESSORS"])
+    if 'NUMBER_OF_PROCESSORS' in os.environ:
+        ncpus = int(os.environ['NUMBER_OF_PROCESSORS'])
         if ncpus > 0:
             # With more than 32 processes, process creation often fails with
             # "Too many open files".  FIXME: Check if there's a better fix.
             return min(ncpus, 32)
-    return 1 # Default
+    return 1  # Default
+
 
 def mkdir_p(path):
     """mkdir_p(path) - Make the "path" directory, if it does not exist; this
@@ -132,6 +144,7 @@ def mkdir_p(path):
         if e.errno != errno.EEXIST:
             raise
 
+
 def listdir_files(dirname, suffixes=None, exclude_filenames=None):
     """Yields files in a directory.
 
@@ -158,6 +171,7 @@ def listdir_files(dirname, suffixes=None
 
     Yields:
         Filenames as returned by os.listdir (generally, str).
+
     """
     if exclude_filenames is None:
         exclude_filenames = set()
@@ -167,16 +181,17 @@ def listdir_files(dirname, suffixes=None
         if (os.path.isdir(os.path.join(dirname, filename)) or
             filename.startswith('.') or
             filename in exclude_filenames or
-            not any(filename.endswith(sfx) for sfx in suffixes)):
+                not any(filename.endswith(sfx) for sfx in suffixes)):
             continue
         yield filename
 
-def which(command, paths = None):
+
+def which(command, paths=None):
     """which(command, [paths]) - Look up the given command in the paths string
     (or the PATH environment variable, if unspecified)."""
 
     if paths is None:
-        paths = os.environ.get('PATH','')
+        paths = os.environ.get('PATH', '')
 
     # Check for absolute match first.
     if os.path.isfile(command):
@@ -202,22 +217,25 @@ def which(command, paths = None):
 
     return None
 
+
 def checkToolsPath(dir, tools):
     for tool in tools:
         if not os.path.exists(os.path.join(dir, tool)):
             return False
     return True
 
+
 def whichTools(tools, paths):
     for path in paths.split(os.pathsep):
         if checkToolsPath(path, tools):
             return path
     return None
 
-def printHistogram(items, title = 'Items'):
-    items.sort(key = lambda item: item[1])
 
-    maxValue = max([v for _,v in items])
+def printHistogram(items, title='Items'):
+    items.sort(key=lambda item: item[1])
+
+    maxValue = max([v for _, v in items])
 
     # Select first "nice" bar height that produces more than 10 bars.
     power = int(math.ceil(math.log(maxValue, 10)))
@@ -230,33 +248,34 @@ def printHistogram(items, title = 'Items
             power -= 1
 
     histo = [set() for i in range(N)]
-    for name,v in items:
-        bin = min(int(N * v/maxValue), N-1)
+    for name, v in items:
+        bin = min(int(N * v / maxValue), N - 1)
         histo[bin].add(name)
 
     barW = 40
     hr = '-' * (barW + 34)
     print('\nSlowest %s:' % title)
     print(hr)
-    for name,value in items[-20:]:
+    for name, value in items[-20:]:
         print('%.2fs: %s' % (value, name))
     print('\n%s Times:' % title)
     print(hr)
     pDigits = int(math.ceil(math.log(maxValue, 10)))
-    pfDigits = max(0, 3-pDigits)
+    pfDigits = max(0, 3 - pDigits)
     if pfDigits:
         pDigits += pfDigits + 1
     cDigits = int(math.ceil(math.log(len(items), 10)))
-    print("[%s] :: [%s] :: [%s]" % ('Range'.center((pDigits+1)*2 + 3),
+    print('[%s] :: [%s] :: [%s]' % ('Range'.center((pDigits + 1) * 2 + 3),
                                     'Percentage'.center(barW),
-                                    'Count'.center(cDigits*2 + 1)))
+                                    'Count'.center(cDigits * 2 + 1)))
     print(hr)
-    for i,row in enumerate(histo):
+    for i, row in enumerate(histo):
         pct = float(len(row)) / len(items)
         w = int(barW * pct)
-        print("[%*.*fs,%*.*fs) :: [%s%s] :: [%*d/%*d]" % (
-            pDigits, pfDigits, i*barH, pDigits, pfDigits, (i+1)*barH,
-            '*'*w, ' '*(barW-w), cDigits, len(row), cDigits, len(items)))
+        print('[%*.*fs,%*.*fs) :: [%s%s] :: [%*d/%*d]' % (
+            pDigits, pfDigits, i * barH, pDigits, pfDigits, (i + 1) * barH,
+            '*' * w, ' ' * (barW - w), cDigits, len(row), cDigits, len(items)))
+
 
 class ExecuteCommandTimeoutException(Exception):
     def __init__(self, msg, out, err, exitCode):
@@ -269,27 +288,30 @@ class ExecuteCommandTimeoutException(Exc
         self.err = err
         self.exitCode = exitCode
 
+
 # Close extra file handles on UNIX (on Windows this cannot be done while
 # also redirecting input).
 kUseCloseFDs = not (platform.system() == 'Windows')
+
+
 def executeCommand(command, cwd=None, env=None, input=None, timeout=0):
-    """
-        Execute command ``command`` (list of arguments or string)
-        with
-        * working directory ``cwd`` (str), use None to use the current
-          working directory
-        * environment ``env`` (dict), use None for none
-        * Input to the command ``input`` (str), use string to pass
-          no input.
-        * Max execution time ``timeout`` (int) seconds. Use 0 for no timeout.
-
-        Returns a tuple (out, err, exitCode) where
-        * ``out`` (str) is the standard output of running the command
-        * ``err`` (str) is the standard error of running the command
-        * ``exitCode`` (int) is the exitCode of running the command
+    """Execute command ``command`` (list of arguments or string) with.
+
+    * working directory ``cwd`` (str), use None to use the current
+      working directory
+    * environment ``env`` (dict), use None for none
+    * Input to the command ``input`` (str), use string to pass
+      no input.
+    * Max execution time ``timeout`` (int) seconds. Use 0 for no timeout.
+
+    Returns a tuple (out, err, exitCode) where
+    * ``out`` (str) is the standard output of running the command
+    * ``err`` (str) is the standard error of running the command
+    * ``exitCode`` (int) is the exitCode of running the command
+
+    If the timeout is hit an ``ExecuteCommandTimeoutException``
+    is raised.
 
-        If the timeout is hit an ``ExecuteCommandTimeoutException``
-        is raised.
     """
     if input is not None:
         input = to_bytes(input)
@@ -315,7 +337,7 @@ def executeCommand(command, cwd=None, en
             timerObject = threading.Timer(timeout, killProcess)
             timerObject.start()
 
-        out,err = p.communicate(input=input)
+        out, err = p.communicate(input=input)
         exitCode = p.wait()
     finally:
         if timerObject != None:
@@ -331,7 +353,7 @@ def executeCommand(command, cwd=None, en
             out=out,
             err=err,
             exitCode=exitCode
-            )
+        )
 
     # Detect Ctrl-C in subprocess.
     if exitCode == -signal.SIGINT:
@@ -339,6 +361,7 @@ def executeCommand(command, cwd=None, en
 
     return out, err, exitCode
 
+
 def usePlatformSdkOnDarwin(config, lit_config):
     # On Darwin, support relocatable SDKs by providing Clang with a
     # default system root path.
@@ -356,6 +379,7 @@ def usePlatformSdkOnDarwin(config, lit_c
             lit_config.note('using SDKROOT: %r' % sdk_path)
             config.environment['SDKROOT'] = sdk_path
 
+
 def findPlatformSdkVersionOnMacOS(config, lit_config):
     if 'darwin' in config.target_triple:
         try:
@@ -370,15 +394,15 @@ def findPlatformSdkVersionOnMacOS(config
             return out
     return None
 
+
 def killProcessAndChildren(pid):
-    """
-    This function kills a process with ``pid`` and all its
-    running children (recursively). It is currently implemented
-    using the psutil module which provides a simple platform
-    neutral implementation.
+    """This function kills a process with ``pid`` and all its running children
+    (recursively). It is currently implemented using the psutil module which
+    provides a simple platform neutral implementation.
+
+    TODO: Reimplement this without using psutil so we can       remove
+    our dependency on it.
 
-    TODO: Reimplement this without using psutil so we can
-          remove our dependency on it.
     """
     import psutil
     try:




More information about the llvm-commits mailing list