minor cleanups

Summary:public
- s/"/'/ in python strings
- kill `utils.error()` in favour of the new, identical `utils.stderr()`
- one more `print(utils.encode())` to `utils.stderr()` conversion

Reviewed By: jeremydubreil

Differential Revision: D2976710

fb-gh-sync-id: 6c0fdfa
shipit-source-id: 6c0fdfa
master
Jules Villard 9 years ago committed by Facebook Github Bot 8
parent 379d185d74
commit 1952f54d8c

@ -60,7 +60,7 @@ base_parser.add_argument('--html',
def show_error_and_exit(err, show_help):
print(utils.encode(err))
utils.stderr(err)
if show_help:
print('')
base_parser.print_help()

@ -28,7 +28,7 @@ from . import config, issues, utils
# Increase the limit of the CSV parser to sys.maxlimit
csv.field_size_limit(sys.maxsize)
INFER_ANALYZE_BINARY = "InferAnalyze"
INFER_ANALYZE_BINARY = 'InferAnalyze'
def get_infer_version():

@ -41,7 +41,7 @@ def create_argparser(group_name=MODULE_NAME):
top-level module"""
parser = argparse.ArgumentParser(add_help=False)
group = parser.add_argument_group(
"{grp} module".format(grp=MODULE_NAME),
'{grp} module'.format(grp=MODULE_NAME),
description=MODULE_DESCRIPTION,
)
group.add_argument('--print-harness', action='store_true',

@ -43,7 +43,7 @@ class GradleCapture:
config.JAVAC_FILELISTS_FILENAME)
if not os.path.exists(path):
os.mkdir(path)
logging.info("Running with:\n" + version_str)
logging.info('Running with:\n' + version_str)
def get_infer_commands(self, verbose_output):
argument_start_pattern = ' Compiler arguments: '
@ -74,9 +74,9 @@ class GradleCapture:
dir=os.path.join(self.args.infer_out,
config.JAVAC_FILELISTS_FILENAME),
delete=False) as sources:
sources.write("\n".join(java_files))
sources.write('\n'.join(java_files))
sources.flush()
java_args.append("@" + sources.name)
java_args.append('@' + sources.name)
capture = jwlib.create_infer_command(self.args,
java_args)
calls.append(capture)

@ -54,7 +54,7 @@ def run_cmd_ignore_fail(cmd):
def log_java_version():
java_version = run_cmd_ignore_fail(['java', '-version'])
javac_version = run_cmd_ignore_fail(['javac', '-version'])
logging.info("java versions:\n%s%s", java_version, javac_version)
logging.info('java versions:\n%s%s', java_version, javac_version)
def base_argparser(description, module_name):
@ -63,7 +63,7 @@ def base_argparser(description, module_name):
description/usage information and no arguments."""
parser = argparse.ArgumentParser(add_help=False)
group = parser.add_argument_group(
"{grp} module".format(grp=group_name),
'{grp} module'.format(grp=group_name),
description=description,
)
return parser
@ -76,7 +76,7 @@ def clang_frontend_argparser(description, module_name):
clang for their capture phase, thus InferClang and clang wrappers"""
parser = argparse.ArgumentParser(add_help=False)
group = parser.add_argument_group(
"{grp} module".format(grp=group_name),
'{grp} module'.format(grp=group_name),
description=description,
)
group.add_argument(

@ -159,7 +159,7 @@ class CompilerCall(object):
+ 'EOF\n"""\n'
failing_cmd = filter(lambda arg: arg != '-verbose',
javac_cmd)
utils.error(error_msg.format(failing_cmd))
utils.stderr(error_msg.format(failing_cmd))
subprocess.check_call(failing_cmd)
return os.EX_OK

@ -31,7 +31,7 @@ DEBUG_FORMAT = '[%(levelname)s:%(filename)s:%(lineno)03d] %(message)s'
# Monkey patching subprocess (I'm so sorry!).
if "check_output" not in dir(subprocess):
if 'check_output' not in dir(subprocess):
def f(*popenargs, **kwargs):
if 'stdout' in kwargs:
raise ValueError('stdout not supported')
@ -42,7 +42,7 @@ if "check_output" not in dir(subprocess):
output, unused_err = process.communicate()
retcode = process.poll()
if retcode:
cmd = kwargs.get("args")
cmd = kwargs.get('args')
if cmd is None:
cmd = popenargs[0]
raise subprocess.CalledProcessError(retcode, cmd)
@ -63,7 +63,7 @@ def configure_logging(args):
be called before any logging is done.
"""
logging.TIMING = logging.ERROR + 5
logging.addLevelName(logging.TIMING, "TIMING")
logging.addLevelName(logging.TIMING, 'TIMING')
def timing(msg, *args, **kwargs):
logging.log(logging.TIMING, msg, *args, **kwargs)
@ -83,10 +83,6 @@ def elapsed_time(start_time):
return time.time() - start_time
def error(msg):
print(encode(msg), file=sys.stderr)
def get_cmd_in_bin_dir(binary_name):
return os.path.join(config.BIN_DIRECTORY, binary_name)
@ -229,7 +225,7 @@ def search_files(root_dir, extension):
if not os.path.isabs(root_dir):
root_dir = os.path.abspath(root_dir)
for dirpath, _, filenames in os.walk(root_dir):
for filename in fnmatch.filter(filenames, "*" + extension):
for filename in fnmatch.filter(filenames, '*' + extension):
files.append(os.path.join(dirpath, filename))
return files
@ -290,19 +286,19 @@ def get_plural(_str, count):
return '%d %s' % (count, plural_str)
def decode(s, errors="replace"):
def decode(s, errors='replace'):
return s.decode(encoding=config.LOCALE, errors=errors)
def encode(u, errors="replace"):
def encode(u, errors='replace'):
return u.encode(encoding=config.LOCALE, errors=errors)
def stdout(s, errors="replace"):
def stdout(s, errors='replace'):
print(encode(s, errors=errors))
def stderr(s, errors="replace"):
def stderr(s, errors='replace'):
print(encode(s, errors=errors), file=sys.stderr)

@ -210,5 +210,5 @@ class BuildIntegrationTest(unittest.TestCase):
assert True
if __name__ == "__main__":
if __name__ == '__main__':
unittest.main() # run all the tests

Loading…
Cancel
Save