[infer] Apply python lint warnings on the Infer python code

Summary: Apply python lint warnings on the Infer python code

Reviewed By: sblackshear, jvillard

Differential Revision: D3970514

fbshipit-source-id: 962f6ca
master
Jeremy Dubreil 8 years ago committed by Facebook Github Bot
parent dab5786789
commit dfa12b17f1

@ -1,5 +1,12 @@
#!/usr/bin/env python2.7
# Copyright (c) 2015 - present Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
@ -7,7 +14,6 @@ from __future__ import unicode_literals
import argparse
import imp
import json
import locale
import logging
import os
@ -40,9 +46,10 @@ MODULE_TO_COMMAND = {
'ndk-build': ['ndk-build'],
}
def get_commands():
"""Return all commands that are supported."""
#flatten and dedup the list of commands
# flatten and dedup the list of commands
return set(sum(MODULE_TO_COMMAND.values(), []))
@ -110,7 +117,8 @@ def create_argparser(parents=[]):
default=None,
help=('Command to run the compiler/build-system. '
'Supported build commands (run `infer --help -- <cmd_name>` for '
'extra help, e.g. `infer --help -- javac`): ' + supported_commands),
'extra help, e.g. `infer --help -- javac`): {}'.format(
supported_commands)),
)
return parser
@ -151,10 +159,10 @@ def main():
validate_args(imported_module, args)
remove_infer_out = (imported_module is not None
and not args.reactive
and capture_module_name != 'analyze'
and not args.buck)
remove_infer_out = (imported_module is not None and
not args.reactive and
capture_module_name != 'analyze' and
not args.buck)
if remove_infer_out:
analyze.remove_infer_out(args.infer_out)

@ -11,10 +11,7 @@ from __future__ import print_function
from __future__ import unicode_literals
import argparse
import codecs
import csv
import glob
import json
import logging
import multiprocessing
import os
@ -35,7 +32,7 @@ def get_infer_version():
try:
return subprocess.check_output([
utils.get_cmd_in_bin_dir(INFER_ANALYZE_BINARY), '-version'])
except:
except subprocess.CalledProcessError:
utils.stdout('Failed to run {0} binary, exiting'
.format(INFER_ANALYZE_BINARY))
sys.exit(os.EX_UNAVAILABLE)
@ -180,6 +177,7 @@ infer_group.add_argument('--specs-dir-list-file',
'in <file> to the list of directories to be '
'searched for spec files')
def remove_infer_out(infer_out):
# it is safe to ignore errors here because recreating the infer_out
# directory will fail later
@ -199,6 +197,7 @@ def reset_start_file(results_dir, touch_if_present=False):
# create new empty file - this will update modified timestamp
open(start_path, 'w').close()
def clean(infer_out):
directories = [
'multicore', 'classnames', 'sources',
@ -367,7 +366,6 @@ class AnalyzerWrapper(object):
elif self.args.project_root:
infer_options += ['-project_root', self.args.project_root]
infer_options = map(utils.decode_or_not, infer_options)
infer_options_str = ' '.join(infer_options)
os.environ['INFER_OPTIONS'] = utils.encode(infer_options_str)
@ -470,8 +468,9 @@ class AnalyzerWrapper(object):
infer_print_cmd + infer_print_options
)
if exit_status != os.EX_OK:
logging.error('Error with InferPrint with the command: '
+ infer_print_cmd)
logging.error(
'Error with InferPrint with the command: {}'.format(
infer_print_cmd))
else:
issues.clean_csv(self.args, csv_report)
issues.clean_json(self.args, json_report)
@ -479,7 +478,6 @@ class AnalyzerWrapper(object):
return exit_status
def read_proc_stats(self):
proc_stats_path = os.path.join(
self.args.infer_out,
@ -529,7 +527,6 @@ class AnalyzerWrapper(object):
bugs_out, xml_out)
def analyze_and_report(self):
should_print_errors = False
if self.args.analyzer not in [config.ANALYZER_COMPILE,
config.ANALYZER_CAPTURE]:
if self.args.analyzer == config.ANALYZER_LINTERS:

@ -30,7 +30,7 @@ import time
import traceback
import zipfile
from inferlib import analyze, config, issues, utils
from inferlib import config, issues, utils
ANALYSIS_SUMMARY_OUTPUT = 'analysis_summary.txt'
@ -76,7 +76,7 @@ def prepare_build(args):
# Create a temporary directory as a cache for jar files.
infer_cache_dir = os.path.join(args.infer_out, 'cache')
if not os.path.isdir(infer_cache_dir):
os.mkdir(infer_cache_dir)
os.mkdir(infer_cache_dir)
infer_options += ['--infer_cache', infer_cache_dir]
temp_files = [infer_cache_dir]
@ -254,7 +254,7 @@ class NotFoundInJar(Exception):
def load_stats(opened_jar):
try:
return json.loads(opened_jar.read(INFER_STATS).decode())
except KeyError as e:
except KeyError:
raise NotFoundInJar
@ -262,14 +262,14 @@ def load_csv_report(opened_jar):
try:
sio = io.StringIO(opened_jar.read(INFER_CSV_REPORT).decode())
return list(utils.locale_csv_reader(sio))
except KeyError as e:
except KeyError:
raise NotFoundInJar
def load_json_report(opened_jar):
try:
return json.loads(opened_jar.read(INFER_JSON_REPORT).decode())
except KeyError as e:
except KeyError:
raise NotFoundInJar
@ -407,9 +407,9 @@ def cleanup(temp_files):
try:
logging.info('Removing %s' % file)
if os.path.isdir(file):
shutil.rmtree(file)
shutil.rmtree(file)
else:
os.unlink(file)
os.unlink(file)
except IOError:
logging.error('Could not remove %s' % file)
@ -499,7 +499,8 @@ class Wrapper:
sys.exit(0)
except subprocess.CalledProcessError as e:
if self.buck_args.keep_going:
print('Buck failed, but continuing analysis because --keep-going was passed')
print('Buck failed, but continuing the analysis '
'because --keep-going was passed')
self._collect_results(start_time)
return os.EX_OK
raise e

@ -5,7 +5,6 @@
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
import os
import logging
from . import util
@ -19,6 +18,7 @@ Analysis examples:
infer -- ant compile'''
LANG = ['java']
def gen_instance(*args):
return AntCapture(*args)

@ -11,7 +11,6 @@ from __future__ import print_function
from __future__ import unicode_literals
import argparse
import json
import logging
import os
import subprocess
@ -35,6 +34,8 @@ def gen_instance(*args):
def string_in_quotes(value):
return value.strip('\'')
# This creates an empty argparser for the module, which provides only
# description/usage information and no arguments.
def create_argparser(group_name=MODULE_NAME):

@ -10,7 +10,7 @@ import subprocess
import traceback
import util
from inferlib import analyze, jwlib
from inferlib import jwlib
MODULE_NAME = __name__
MODULE_DESCRIPTION = '''Run analysis of code built with a command like:

@ -30,6 +30,7 @@ ALIASED_COMMANDS = ['clang', 'clang++', 'cc', 'gcc', 'g++']
BUILD_COMMANDS = ['cmake', 'configure', 'make', 'waf']
SUPPORTED_COMMANDS = ALIASED_COMMANDS + BUILD_COMMANDS
def gen_instance(*args):
return MakeCapture(*args)

@ -15,6 +15,7 @@ MODULE_DESCRIPTION = '''Run analysis of code built with ndk-build
infer -- ndk-build'''
LANG = ['clang']
def gen_instance(*args):
return NdkBuildCapture(*args)

@ -18,7 +18,8 @@ import logging
import subprocess
import traceback
from inferlib import analyze, jwlib, utils
from inferlib import utils
def get_build_output(build_cmd):
# TODO make it return generator to be able to handle large builds
@ -45,7 +46,7 @@ def run_compilation_commands(cmds, clean_cmd):
def run_cmd_ignore_fail(cmd):
try:
return subprocess.check_output(cmd, stderr=subprocess.STDOUT)
except:
except subprocess.CalledProcessError:
return 'calling {cmd} failed\n{trace}'.format(
cmd=' '.join(cmd),
trace=traceback.format_exc())
@ -62,7 +63,7 @@ def base_argparser(description, module_name):
"""This creates an empty argparser for the module, which provides only
description/usage information and no arguments."""
parser = argparse.ArgumentParser(add_help=False)
group = parser.add_argument_group(
parser.add_argument_group(
'{grp} module'.format(grp=group_name),
description=description,
)

@ -63,7 +63,8 @@ class XcodebuildCapture:
def capture(self):
# these settings will instruct xcodebuild on which clang to use
self.cmd += ['CC={wrapper}'.format(wrapper=CLANG_WRAPPER)]
self.cmd += ['CPLUSPLUS={wrapper}'.format(wrapper=CLANGPLUSPLUS_WRAPPER)]
self.cmd += [
'CPLUSPLUS={wrapper}'.format(wrapper=CLANGPLUSPLUS_WRAPPER)]
# skip the ProcessPCH phase to fix the "newer/older" incompatibility
# error for the pch files generated by apple's clang and

@ -35,7 +35,8 @@ BIN_DIRECTORY = os.path.join(INFER_INFER_DIRECTORY, 'bin')
JAVA_LIB_DIRECTORY = os.path.join(LIB_DIRECTORY, 'java')
MODELS_JAR = os.path.join(JAVA_LIB_DIRECTORY, 'models.jar')
ANNOT_PROCESSOR_JAR = os.path.join(JAVA_LIB_DIRECTORY, 'processor.jar')
ANNOT_PROCESSOR_NAMES = 'com.facebook.infer.annotprocess.CollectSuppressWarnings'
ANNOT_PROCESSOR_NAMES = \
'com.facebook.infer.annotprocess.CollectSuppressWarnings'
WRAPPERS_DIRECTORY = os.path.join(LIB_DIRECTORY, 'wrappers')
XCODE_WRAPPERS_DIRECTORY = os.path.join(LIB_DIRECTORY, 'xcode_wrappers')

@ -164,6 +164,7 @@ def clean_json(args, json_report):
utils.dump_json_to_path(rows, temporary_file)
shutil.move(temporary_file, json_report)
def _text_of_infer_loc(loc):
return ' ({}:{}:{}-{}:)'.format(
loc[JSON_INDEX_ISL_FILE],

@ -15,7 +15,6 @@ import argparse
import codecs
import os
import subprocess
import sys
import tempfile
import time
@ -150,9 +149,10 @@ class CompilerCall(object):
if _is_empty_classpath(cp_line):
cp_line = '\n'
else:
cp_line = ':%s\n' % cp_line
args_file_cp.write(
prefix + '-classpath\n' + classpath + cp_line + after_cp)
cp_line = ':{}\n'.format(cp_line)
cp_line = prefix + '-classpath\n' + classpath + cp_line
cp_line += after_cp
args_file_cp.write(cp_line)
at_arg_cp = '@' + args_file_cp.name
self.remaining_args = [
at_arg_cp if arg == at_arg else arg
@ -170,8 +170,10 @@ class CompilerCall(object):
# processors (checking the manifest of the annotation processor
# JAR), so we don't want to use it unless the javac command does
if self.args.processor is not None:
processor = '%s,%s' % (config.ANNOT_PROCESSOR_NAMES,
self.args.processor)
processor = '{infer_processors},{original_processors}'.format(
infer_processors=config.ANNOT_PROCESSOR_NAMES,
original_processors=self.args.processor
)
javac_args += ['-processor', processor]
with tempfile.NamedTemporaryFile(
@ -184,8 +186,8 @@ class CompilerCall(object):
annot_out.write('{}')
self.suppress_warnings_out = annot_out.name
javac_args += ['-A%s=%s' %
(config.SUPRESS_WARNINGS_OUTPUT_FILENAME_OPTION,
self.suppress_warnings_out)]
(config.SUPRESS_WARNINGS_OUTPUT_FILENAME_OPTION,
self.suppress_warnings_out)]
def arg_must_go_on_cli(arg):
# as mandated by javac, argument files must not contain
@ -241,7 +243,7 @@ class AnalyzerWithFrontendWrapper(analyze.AnalyzerWrapper):
self.javac = CompilerCall(javac_cmd, javac_args)
if not self.javac.args.version:
if javac_args is None:
help_exit('No javac command detected')
raise Exception('No javac command detected')
analyze.AnalyzerWrapper.__init__(self, args)
@ -325,7 +327,6 @@ class AnalyzerWithFrontendWrapper(analyze.AnalyzerWrapper):
if self.args.android_harness:
infer_cmd.append('-harness')
return analyze.run_command(
infer_cmd,
self.args.debug,

@ -12,12 +12,13 @@ from __future__ import unicode_literals
import codecs
from . import colorize, config, utils
from . import colorize, config
BASE_INDENT = 2
# how many lines of context around each report
SOURCE_CONTEXT = 2
class Indenter(str):
def __init__(self):
super(Indenter, self).__init__()

@ -20,7 +20,6 @@ import logging
import os
import subprocess
import sys
import tempfile
import time
from . import config
@ -218,7 +217,6 @@ class Timer:
return self._dt
def interact():
"""Start interactive mode. Useful for debugging.
"""

Loading…
Cancel
Save