def test_run_coala_no_autoapply(self, debug=False): with bear_test_module(): with prepare_file(['#fixme '], None) as (lines, filename): self.assertEqual( 1, len(run_coala( console_printer=ConsolePrinter(), log_printer=LogPrinter(), arg_list=( '-c', os.devnull, '-f', filename, '-b', 'SpaceConsistencyTestBear', '--apply-patches', '-S', 'use_spaces=yeah' ), autoapply=False, debug=debug )[0]['cli']) ) self.assertEqual( 0, len(run_coala( console_printer=ConsolePrinter(), log_printer=LogPrinter(), arg_list=( '-c', os.devnull, '-f', filename, '-b', 'SpaceConsistencyTestBear', '--apply-patches', '-S', 'use_spaces=yeah' ), debug=debug )[0]['cli']) )
def test_run_coala_no_autoapply(self, debug=False): with bear_test_module(), \ prepare_file(['#fixme '], None) as (lines, filename): self.assertEqual( 1, len( run_coala(console_printer=ConsolePrinter(), log_printer=LogPrinter(), arg_list=('-c', os.devnull, '-f', filename, '-b', 'SpaceConsistencyTestBear', '--apply-patches', '-S', 'use_spaces=yeah'), autoapply=False, debug=debug)[0]['cli'])) self.assertEqual( 0, len( run_coala(console_printer=ConsolePrinter(), log_printer=LogPrinter(), arg_list=('-c', os.devnull, '-f', filename, '-b', 'SpaceConsistencyTestBear', '--apply-patches', '-S', 'use_spaces=yeah'), debug=debug)[0]['cli']))
def test_run_coala_bear_run_raises(self): configure_logging() with bear_test_module(), \ prepare_file(['#fixme '], None) as (lines, filename), \ self.assertRaisesRegex( RuntimeError, r"^That's all the RaiseTestBear can do\.$"): run_coala(console_printer=ConsolePrinter(), log_printer=LogPrinter(), arg_list=('-c', os.devnull, '-f', re.escape(filename), '-b', 'RaiseTestBear'), debug=True)
def test_run_coala_bear__init__raises(self): configure_logging() with bear_test_module(), \ prepare_file(['#fixme '], None) as (lines, filename), \ self.assertRaisesRegex( RuntimeError, r'^The bear ErrorTestBear does not fulfill all ' r"requirements. 'I_do_not_exist' is not installed.$"): run_coala(console_printer=ConsolePrinter(), log_printer=LogPrinter(), arg_list=('-c', os.devnull, '-f', re.escape(filename), '-b', 'ErrorTestBear'), debug=True)
def test_run_coala_bear_run_raises(self): configure_logging() with bear_test_module(), \ prepare_file(['#fixme '], None) as (lines, filename), \ self.assertRaisesRegex( RuntimeError, r"^That's all the RaiseTestBear can do\.$"): run_coala( console_printer=ConsolePrinter(), log_printer=LogPrinter(), arg_list=( '-c', os.devnull, '-f', filename, '-b', 'RaiseTestBear' ), debug=True)
def main(): try: console_printer = ConsolePrinter() log_printer = LogPrinter(console_printer) # Note: We parse the args here once to check whether to show bears or # not. args = default_arg_parser().parse_args() if args.show_bears: sections, _ = load_configuration(arg_list=None, log_printer=log_printer) local_bears, global_bears = collect_all_bears_from_sections( sections, log_printer) if args.filter_by_language: local_bears = filter_section_bears_by_languages( local_bears, args.filter_by_language) global_bears = filter_section_bears_by_languages( global_bears, args.filter_by_language) show_bears(local_bears, global_bears, args.show_description or args.show_details, args.show_details, console_printer) return 0 except BaseException as exception: # pylint: disable=broad-except return get_exitcode(exception, log_printer) partial_print_sec_beg = functools.partial(print_section_beginning, console_printer) results, exitcode, _ = run_coala( print_results=print_results, acquire_settings=acquire_settings, print_section_beginning=partial_print_sec_beg, nothing_done=nothing_done) return exitcode
def main(): try: console_printer = ConsolePrinter() log_printer = LogPrinter(console_printer) # Note: We parse the args here once to check whether to show bears or # not. args = default_arg_parser().parse_args() if args.show_bears: local_bears, global_bears = get_filtered_bears(args.filter_by_language, log_printer) show_bears( local_bears, global_bears, args.show_description or args.show_details, args.show_details, console_printer, ) return 0 except BaseException as exception: # pylint: disable=broad-except return get_exitcode(exception, log_printer) partial_print_sec_beg = functools.partial(print_section_beginning, console_printer) results, exitcode, _ = run_coala( print_results=print_results, acquire_settings=acquire_settings, print_section_beginning=partial_print_sec_beg, nothing_done=nothing_done, ) return exitcode
def mode_format(): from coalib.coala_main import run_coala from coalib.output.ConsoleInteraction import print_results_formatted _, exitcode, _ = run_coala( print_results=print_results_formatted) return exitcode
def test_file_cache_proxy_integration(self, debug=False): with bear_test_module(): with prepare_file(['disk-copy\n'], None) as (_, filename): memory_data = 'in-memory\n' proxy = FileProxy(filename, None, memory_data) proxymap = FileProxyMap([proxy]) self.cache.set_proxymap(proxymap) results, exitcode, file_dicts = run_coala( console_printer=ConsolePrinter(), log_printer=LogPrinter(), arg_list=( '-c', os.devnull, '-f', filename, '-b', 'TestBear', ), autoapply=False, debug=debug, cache=self.cache ) self.assertEqual(exitcode, 0) self.assertEqual(len(results), 1) # run_coala() output's name is always lower case self.assertEqual(file_dicts['cli'][filename.lower()], (memory_data,))
def test_file_cache_proxy_integration(self, debug=False): with bear_test_module(), \ prepare_file(['disk-copy\n'], None) as (_, filename): memory_data = 'in-memory\n' proxy = FileProxy(filename, None, memory_data) proxymap = FileProxyMap([proxy]) self.cache.set_proxymap(proxymap) results, exitcode, file_dicts = run_coala( console_printer=ConsolePrinter(), log_printer=LogPrinter(), arg_list=( '-c', os.devnull, '-f', filename, '-b', 'TestBear', ), autoapply=False, debug=debug, cache=self.cache) self.assertEqual(exitcode, 0) self.assertEqual(len(results), 1) # run_coala() output's name is always lower case self.assertEqual(file_dicts['cli'][filename.lower()], (memory_data, ))
def main(): # Note: We parse the args here once to find the log printer to use. # Also, commands like -h (help) and -v (version) are executed here. # The args are again parsed later to find the settings and configs # to use during analysis. arg_parser = default_arg_parser() try: args = arg_parser.parse_args() except BaseException as exception: # Ignore PyLintBear return get_exitcode(exception) log_printer = None if args.text_logs else ListLogPrinter() results, exitcode = run_coala(log_printer=log_printer, autoapply=False) retval = {"results": results} if not args.text_logs: retval["logs"] = log_printer.logs print(json.dumps(retval, cls=JSONEncoder, sort_keys=True, indent=2, separators=(',', ': '))) return exitcode
def mode_format(args, debug=False): from coalib.coala_main import run_coala from coalib.output.ConsoleInteraction import print_results_formatted _, exitcode, _ = run_coala( print_results=print_results_formatted, args=args, debug=debug) return exitcode
def main(): # Note: We parse the args here once to find the log printer to use. # Also, commands like -h (help) and -v (version) are executed here. # The args are again parsed later to find the settings and configs # to use during analysis. arg_parser = default_arg_parser() args = arg_parser.parse_args() log_printer = None if args.text_logs else ListLogPrinter() results, exitcode = run_coala(log_printer=log_printer, autoapply=False) retval = {"results": results} if not args.text_logs: retval["logs"] = log_printer.logs JSONEncoder = create_json_encoder(use_relpath=args.relpath) if args.output: filename = str(args.output) with open(filename, 'w+') as fp: json.dump(retval, fp, cls=JSONEncoder, sort_keys=True, indent=2, separators=(',', ': ')) else: print(json.dumps(retval, cls=JSONEncoder, sort_keys=True, indent=2, separators=(',', ': '))) return exitcode
def test_profiler_dependency(self, debug=False): with bear_test_module(): with prepare_file(['#fixme '], None) as (lines, filename): results = run_coala(console_printer=ConsolePrinter(), log_printer=LogPrinter(), arg_list=( '-c', os.devnull, '-f', filename, '-b', 'DependentBear', '-S', 'use_spaces=yeah', '--profile', 'profiled_bears', ), autoapply=False, debug=debug) cli_result = results[0]['cli'] self.assertEqual(len(cli_result), 1) profiled_files = os.listdir('profiled_bears') self.assertEqual(len(profiled_files), 1) self.assertEqual(profiled_files[0], 'cli_SpaceConsistencyTestBear.prof') shutil.rmtree('profiled_bears')
def mode_normal(console_printer, log_printer, args, debug=False): """ This is the default coala mode. User interaction is allowed in this mode. :param console_printer: Object to print messages on the console. :param log_printer: Deprecated. :param args: Alternative pre-parsed CLI arguments. :param debug: Run in debug mode, bypassing multiprocessing, and not catching any exceptions. """ import functools import logging from coalib.coala_main import run_coala from coalib.output.ConsoleInteraction import (acquire_settings, nothing_done, print_results, print_section_beginning) partial_print_sec_beg = functools.partial(print_section_beginning, console_printer) results, exitcode, _ = run_coala( print_results=print_results, acquire_settings=acquire_settings, print_section_beginning=partial_print_sec_beg, nothing_done=nothing_done, console_printer=console_printer, args=args, debug=debug) if log_printer: logging.warn('log_printer is deprecated. Please do not use it.') return exitcode
def main(): # Note: We parse the args here once to check whether to show bears or not. arg_parser = default_arg_parser() args = arg_parser.parse_args() console_printer = ConsolePrinter() if args.show_bears or args.show_all_bears: log_printer = LogPrinter(console_printer) sections, _ = load_configuration(arg_list=None, log_printer=log_printer) if args.show_all_bears: local_bears, global_bears = collect_all_bears_from_sections( sections, log_printer) else: # We ignore missing settings as it's not important. local_bears, global_bears = fill_settings( sections, acquire_settings=lambda *args, **kwargs: {}, log_printer=log_printer) show_bears(local_bears, global_bears, args.show_all_bears, console_printer) return 0 partial_print_sec_beg = functools.partial( print_section_beginning, console_printer) results, exitcode, _ = run_coala( print_results=print_results, acquire_settings=acquire_settings, print_section_beginning=partial_print_sec_beg, nothing_done=nothing_done) return exitcode
def main(): # Note: We parse the args here once to find the log printer to use. # Also, commands like -h (help) and -v (version) are executed here. # The args are again parsed later to find the settings and configs # to use during analysis. arg_parser = default_arg_parser() try: args = arg_parser.parse_args() except BaseException as exception: # Ignore PyLintBear return get_exitcode(exception) log_printer = None if args.text_logs else ListLogPrinter() results, exitcode = run_coala(log_printer=log_printer, autoapply=False) retval = {"results": results} if not args.text_logs: retval["logs"] = log_printer.logs print( json.dumps(retval, cls=JSONEncoder, sort_keys=True, indent=2, separators=(',', ': '))) return exitcode
def main(): # Note: We parse the args here once to find the log printer to use. # Also, commands like -h (help) and -v (version) are executed here. # The args are again parsed later to find the settings and configs # to use during analysis. arg_parser = default_arg_parser() args = arg_parser.parse_args() log_printer = None if args.text_logs else ListLogPrinter() results, exitcode, _ = run_coala(log_printer=log_printer, autoapply=False) retval = {"results": results} if not args.text_logs: retval["logs"] = log_printer.logs JSONEncoder = create_json_encoder(use_relpath=args.relpath) if args.output: filename = str(args.output[0]) with open(filename, 'w+') as fp: json.dump(retval, fp, cls=JSONEncoder, sort_keys=True, indent=2, separators=(',', ': ')) else: print( json.dumps(retval, cls=JSONEncoder, sort_keys=True, indent=2, separators=(',', ': '))) return exitcode
def mode_normal(console_printer, log_printer, args, debug=False): """ This is the default coala mode. User interaction is allowed in this mode. :param console_printer: Object to print messages on the console. :param log_printer: Deprecated. :param args: Alternative pre-parsed CLI arguments. :param debug: Run in debug mode, bypassing multiprocessing, and not catching any exceptions. """ import functools import logging from coalib.coala_main import run_coala from coalib.output.ConsoleInteraction import ( acquire_settings, nothing_done, print_results, print_section_beginning) partial_print_sec_beg = functools.partial( print_section_beginning, console_printer) results, exitcode, _ = run_coala( print_results=print_results, acquire_settings=acquire_settings, print_section_beginning=partial_print_sec_beg, nothing_done=nothing_done, console_printer=console_printer, args=args, debug=debug) if log_printer: logging.warn('log_printer is deprecated. Please do not use it.') return exitcode
def test_run_coala_bear__init__raises(self): configure_logging() with bear_test_module(), \ prepare_file(['#fixme '], None) as (lines, filename), \ self.assertRaisesRegex( RuntimeError, r'^The bear ErrorTestBear does not fulfill all ' r"requirements. 'I_do_not_exist' is not installed.$"): run_coala( console_printer=ConsolePrinter(), log_printer=LogPrinter(), arg_list=( '-c', os.devnull, '-f', filename, '-b', 'ErrorTestBear' ), debug=True)
def main(): arg_parser = get_args() args = arg_parser.parse_args() dir_path = create_dir(os.path.abspath(args.dir)) if len(list(os.walk(dir_path))) > 0: copy_files(get_file(Constants.COALA_HTML_BASE), dir_path) if not args.noupdate: log_printer = ListLogPrinter() results, exitcode, file_dict = run_coala( log_printer=log_printer, autoapply=False, arg_parser=arg_parser) result_data = {"results": results} result_data["logs"] = log_printer.logs JSONEncoder = create_json_encoder(use_relpath=False) result_file = get_file(Constants.CONFIGS['results_file'], dir_path) file_data = get_file(Constants.CONFIGS['file_data'], dir_path) file_tree_data = get_file(Constants.CONFIGS['files'], dir_path) with open(file_tree_data, 'w') as fp: file_graph = build_file_graph(file_dict, dir_path) json.dump(file_graph, fp, cls=JSONEncoder, sort_keys=True, indent=2, separators=(',', ': ')) with open(result_file, 'w') as fp: json.dump(result_data, fp, cls=JSONEncoder, sort_keys=True, indent=2, separators=(',', ': ')) with open(file_data, 'w') as fp: json.dump(parse_file_dict(file_dict), fp, cls=JSONEncoder, sort_keys=True, indent=2, separators=(',', ': ')) if not args.nolaunch: # Launch server with reference point dir_path os.chdir(dir_path) if not os.path.exists('bower_components'): res = call(['bower', 'install']) if res != 0: print("Bower is required. Install from `http://bower.io/`") sys.exit(1) Handler = http.server.SimpleHTTPRequestHandler httpd = socketserver.TCPServer(("", Constants.PORT), Handler) print("serving at ", Constants.URL) print("Press Ctrl+C to end the coala-html session") httpd.serve_forever() webbrowser.open(Constants.URL, new=2)
def main(): console_printer = ConsolePrinter() partial_print_sec_beg = functools.partial( print_section_beginning, console_printer) results, exitcode = run_coala(autoapply=False, print_results=print_results_no_input, print_section_beginning=partial_print_sec_beg) return exitcode
def main(): console_printer = ConsolePrinter() partial_print_sec_beg = functools.partial( print_section_beginning, console_printer) results, exitcode, _ = run_coala( print_results=print_results_no_input, print_section_beginning=partial_print_sec_beg) return exitcode
def mode_json(args, debug=False): import json from coalib.coala_main import run_coala from coalib.misc.DictUtilities import inverse_dicts from coalib.misc.Exceptions import get_exitcode from coalib.output.Logging import configure_json_logging from coalib.output.JSONEncoder import create_json_encoder if args.log_json: log_stream = configure_json_logging() JSONEncoder = create_json_encoder(use_relpath=args.relpath) results = [] if args.show_bears: try: from coalib.parsing.FilterHelper import FilterHelper local_bears, global_bears = FilterHelper.apply_filter( 'language', args.filter_by_language) bears = inverse_dicts(local_bears, global_bears) for bear, _ in sorted(bears.items(), key=lambda bear_tuple: bear_tuple[0].name): results.append(bear) except BaseException as exception: # pylint: disable=broad-except return get_exitcode(exception) else: results, exitcode, _ = run_coala(args=args, debug=debug) retval = {'bears': results} if args.show_bears else {'results': results} if args.log_json: retval['logs'] = [ json.loads(line) for line in log_stream.getvalue().splitlines() ] if args.output: filename = str(args.output[0]) with open(filename, 'w+') as fp: json.dump(retval, fp, cls=JSONEncoder, sort_keys=True, indent=2, separators=(',', ': ')) else: print( json.dumps(retval, cls=JSONEncoder, sort_keys=True, indent=2, separators=(',', ': '))) return 0 if args.show_bears else exitcode
def main(): configure_logging() try: console_printer = ConsolePrinter() log_printer = LogPrinter(console_printer) # Note: We parse the args here once to check whether to show bears or # not. args = default_arg_parser().parse_args() console_printer = ConsolePrinter(print_colored=not args.no_color) if args.show_bears: from coalib.settings.ConfigurationGathering import ( get_filtered_bears) local_bears, global_bears = get_filtered_bears( args.filter_by_language, log_printer) show_bears(local_bears, global_bears, args.show_description or args.show_details, args.show_details, console_printer) return 0 elif args.show_capabilities: from coalib.collecting.Collectors import ( filter_capabilities_by_languages) from coalib.settings.ConfigurationGathering import ( get_filtered_bears) local_bears, global_bears = get_filtered_bears( args.filter_by_language, log_printer) capabilities = filter_capabilities_by_languages( local_bears, args.show_capabilities) show_language_bears_capabilities(capabilities, console_printer) return 0 except BaseException as exception: # pylint: disable=broad-except return get_exitcode(exception, log_printer) import functools from coalib.coala_main import run_coala partial_print_sec_beg = functools.partial(print_section_beginning, console_printer) results, exitcode, _ = run_coala( print_results=print_results, acquire_settings=acquire_settings, print_section_beginning=partial_print_sec_beg, nothing_done=nothing_done, console_printer=console_printer) return exitcode
def test_logged_error_causes_non_zero_exitcode(self): configure_logging() with bear_test_module(), \ prepare_file(['#fixme '], None) as (lines, filename): _, exitcode, _ = run_coala(console_printer=ConsolePrinter(), log_printer=LogPrinter(), arg_list=('-c', os.devnull, '-f', filename, '-b', 'ErrorTestBear'), autoapply=False) assert exitcode == 1
def main(): args = default_arg_parser().parse_args() console_printer = ConsolePrinter(print_colored=not args.no_color) partial_print_sec_beg = functools.partial(print_section_beginning, console_printer) results, exitcode, _ = run_coala( print_results=print_results_no_input, print_section_beginning=partial_print_sec_beg, force_show_patch=True, console_printer=console_printer) return exitcode
def main(): args = default_arg_parser().parse_args() console_printer = ConsolePrinter(print_colored=not args.no_color) partial_print_sec_beg = functools.partial( print_section_beginning, console_printer) results, exitcode, _ = run_coala( print_results=print_results_no_input, print_section_beginning=partial_print_sec_beg, force_show_patch=True, console_printer=console_printer) return exitcode
def main(): log_printer = ListLogPrinter() results, exitcode = run_coala(log_printer, autoapply=False) retval = {"logs": log_printer.logs, "results": results} print(json.dumps(retval, cls=JSONEncoder, sort_keys=True, indent=2, separators=(',', ': '))) return exitcode
def main(): console_printer = ConsolePrinter() partial_show_bears = functools.partial(show_bears, console_printer=console_printer) partial_print_sec_beg = functools.partial(print_section_beginning, console_printer) results, exitcode = run_coala( show_bears=partial_show_bears, print_results=print_results, acquire_settings=acquire_settings, print_section_beginning=partial_print_sec_beg, nothing_done=nothing_done) return exitcode
def mode_non_interactive(console_printer, args): import functools from coalib.coala_main import run_coala from coalib.output.ConsoleInteraction import print_results_no_input, print_section_beginning partial_print_sec_beg = functools.partial(print_section_beginning, console_printer) results, exitcode, _ = run_coala( print_results=print_results_no_input, print_section_beginning=partial_print_sec_beg, force_show_patch=True, console_printer=console_printer, ) return exitcode
def mode_normal(console_printer, log_printer): import functools from coalib.coala_main import run_coala from coalib.output.ConsoleInteraction import acquire_settings, nothing_done, print_results, print_section_beginning partial_print_sec_beg = functools.partial(print_section_beginning, console_printer) results, exitcode, _ = run_coala( print_results=print_results, acquire_settings=acquire_settings, print_section_beginning=partial_print_sec_beg, nothing_done=nothing_done, console_printer=console_printer, ) return exitcode
def mode_non_interactive(console_printer, args): import functools from coalib.coala_main import run_coala from coalib.output.ConsoleInteraction import (print_results_no_input, print_section_beginning) partial_print_sec_beg = functools.partial(print_section_beginning, console_printer) results, exitcode, _ = run_coala( print_results=print_results_no_input, print_section_beginning=partial_print_sec_beg, force_show_patch=True, console_printer=console_printer) return exitcode
def test_logged_error_causes_non_zero_exitcode(self): configure_logging() with bear_test_module(): with prepare_file(['#fixme '], None) as (lines, filename): _, exitcode, _ = run_coala( console_printer=ConsolePrinter(), log_printer=LogPrinter(), arg_list=( '-c', os.devnull, '-f', filename, '-b', 'ErrorTestBear' ), autoapply=False ) assert exitcode == 1
def main(): console_printer = ConsolePrinter() partial_show_bears = functools.partial( show_bears, console_printer=console_printer) partial_print_sec_beg = functools.partial( print_section_beginning, console_printer) results, exitcode = run_coala( show_bears=partial_show_bears, print_results=print_results, acquire_settings=acquire_settings, print_section_beginning=partial_print_sec_beg, nothing_done=nothing_done) return exitcode
def main(): # Note: We parse the args here once to find the log printer to use. # Also, commands like -h (help) and -v (version) are executed here. # The args are again parsed later to find the settings and configs # to use during analysis. arg_parser = default_arg_parser() args = arg_parser.parse_args() log_printer = None if args.text_logs else ListLogPrinter() JSONEncoder = create_json_encoder(use_relpath=args.relpath) results = [] if args.show_bears: try: local_bears, global_bears = get_filtered_bears( args.filter_by_language, log_printer) bears = inverse_dicts(local_bears, global_bears) for bear, _ in sorted(bears.items(), key=lambda bear_tuple: bear_tuple[0].name): results.append(bear) except BaseException as exception: # pylint: disable=broad-except return get_exitcode(exception, log_printer) else: results, exitcode, _ = run_coala(log_printer=log_printer, autoapply=False) retval = {"bears": results} if args.show_bears else {"results": results} if not args.text_logs: retval["logs"] = log_printer.logs if args.output: filename = str(args.output[0]) with open(filename, 'w+') as fp: json.dump(retval, fp, cls=JSONEncoder, sort_keys=True, indent=2, separators=(',', ': ')) else: print( json.dumps(retval, cls=JSONEncoder, sort_keys=True, indent=2, separators=(',', ': '))) return 0 if args.show_bears else exitcode
def main(): # Note: We parse the args here once to find the log printer to use. # Also, commands like -h (help) and -v (version) are executed here. # The args are again parsed later to find the settings and configs # to use during analysis. arg_parser = default_arg_parser() args = arg_parser.parse_args() log_printer = None if args.text_logs else ListLogPrinter() JSONEncoder = create_json_encoder(use_relpath=args.relpath) results = [] if args.show_bears: try: local_bears, global_bears = get_filtered_bears( args.filter_by_language, log_printer) bears = inverse_dicts(local_bears, global_bears) for bear, _ in sorted(bears.items(), key=lambda bear_tuple: bear_tuple[0].name): results.append(bear) except BaseException as exception: # pylint: disable=broad-except return get_exitcode(exception, log_printer) else: results, exitcode, _ = run_coala( log_printer=log_printer, autoapply=False) retval = {"bears": results} if args.show_bears else {"results": results} if not args.text_logs: retval["logs"] = log_printer.logs if args.output: filename = str(args.output[0]) with open(filename, 'w+') as fp: json.dump(retval, fp, cls=JSONEncoder, sort_keys=True, indent=2, separators=(',', ': ')) else: print(json.dumps(retval, cls=JSONEncoder, sort_keys=True, indent=2, separators=(',', ': '))) return 0 if args.show_bears else exitcode
def mode_json(args): import json from coalib.coala_main import run_coala from coalib.misc.DictUtilities import inverse_dicts from coalib.misc.Exceptions import get_exitcode from coalib.output.JSONEncoder import create_json_encoder from coalib.output.printers.LogPrinter import LogPrinter from coalib.parsing.DefaultArgParser import default_arg_parser from coalib.settings.ConfigurationGathering import get_filtered_bears JSONEncoder = create_json_encoder(use_relpath=args.relpath) results = [] if args.show_bears: try: local_bears, global_bears = get_filtered_bears( args.filter_by_language, LogPrinter()) bears = inverse_dicts(local_bears, global_bears) for bear, _ in sorted(bears.items(), key=lambda bear_tuple: bear_tuple[0].name): results.append(bear) except BaseException as exception: # pylint: disable=broad-except return get_exitcode(exception) else: results, exitcode, _ = run_coala() retval = {'bears': results} if args.show_bears else {'results': results} if args.output: filename = str(args.output[0]) with open(filename, 'w+') as fp: json.dump(retval, fp, cls=JSONEncoder, sort_keys=True, indent=2, separators=(',', ': ')) else: print(json.dumps(retval, cls=JSONEncoder, sort_keys=True, indent=2, separators=(',', ': '))) return 0 if args.show_bears else exitcode
def mode_json(args): import json from coalib.coala_main import run_coala from coalib.misc.DictUtilities import inverse_dicts from coalib.misc.Exceptions import get_exitcode from coalib.output.JSONEncoder import create_json_encoder from coalib.output.printers.LogPrinter import LogPrinter from coalib.settings.ConfigurationGathering import get_filtered_bears JSONEncoder = create_json_encoder(use_relpath=args.relpath) results = [] if args.show_bears: try: local_bears, global_bears = get_filtered_bears( args.filter_by_language, LogPrinter()) bears = inverse_dicts(local_bears, global_bears) for bear, _ in sorted(bears.items(), key=lambda bear_tuple: bear_tuple[0].name): results.append(bear) except BaseException as exception: # pylint: disable=broad-except return get_exitcode(exception) else: results, exitcode, _ = run_coala() retval = {'bears': results} if args.show_bears else {'results': results} if args.output: filename = str(args.output[0]) with open(filename, 'w+') as fp: json.dump(retval, fp, cls=JSONEncoder, sort_keys=True, indent=2, separators=(',', ': ')) else: print( json.dumps(retval, cls=JSONEncoder, sort_keys=True, indent=2, separators=(',', ': '))) return 0 if args.show_bears else exitcode
def mode_normal(console_printer, log_printer): import functools from coalib.coala_main import run_coala from coalib.output.ConsoleInteraction import (acquire_settings, nothing_done, print_results, print_section_beginning) partial_print_sec_beg = functools.partial(print_section_beginning, console_printer) results, exitcode, _ = run_coala( print_results=print_results, acquire_settings=acquire_settings, print_section_beginning=partial_print_sec_beg, nothing_done=nothing_done, console_printer=console_printer) return exitcode
def test_execute_with_filters(self, debug=False): coala_config = ( '[section_one]', 'tags = save', '[section_two]', 'tags = change', ) with bear_test_module(), \ prepare_file(['#fixme'], None) as (_, filename), \ prepare_file(coala_config, None) as (_, configuration): results, retval, _ = run_coala( console_printer=ConsolePrinter(), log_printer=LogPrinter(), arg_list=('-c', configuration, '-f', filename, '-b', 'TestBear', '--filter-by', 'section_tags', 'save'), autoapply=False, debug=debug) self.assertTrue('section_one' in results)
def mode_json(args): import json from coalib.coala_main import run_coala from coalib.misc.DictUtilities import inverse_dicts from coalib.misc.Exceptions import get_exitcode from coalib.output.Logging import configure_json_logging from coalib.output.JSONEncoder import create_json_encoder from coalib.output.printers.LogPrinter import LogPrinter from coalib.settings.ConfigurationGathering import get_filtered_bears if args.log_json: log_stream = configure_json_logging() JSONEncoder = create_json_encoder(use_relpath=args.relpath) results = [] if args.show_bears: try: local_bears, global_bears = get_filtered_bears(args.filter_by_language, LogPrinter()) bears = inverse_dicts(local_bears, global_bears) for bear, _ in sorted(bears.items(), key=lambda bear_tuple: bear_tuple[0].name): results.append(bear) except BaseException as exception: # pylint: disable=broad-except return get_exitcode(exception) else: results, exitcode, _ = run_coala() retval = {"bears": results} if args.show_bears else {"results": results} if args.log_json: retval["logs"] = [json.loads(line) for line in log_stream.getvalue().splitlines()] if args.output: filename = str(args.output[0]) with open(filename, "w+") as fp: json.dump(retval, fp, cls=JSONEncoder, sort_keys=True, indent=2, separators=(",", ": ")) else: print(json.dumps(retval, cls=JSONEncoder, sort_keys=True, indent=2, separators=(",", ": "))) return 0 if args.show_bears else exitcode
def mode_json(args, debug=False): import json from coalib.coala_main import run_coala from coalib.output.Logging import configure_json_logging from coalib.output.JSONEncoder import create_json_encoder if args.log_json: log_stream = configure_json_logging() JSONEncoder = create_json_encoder(use_relpath=args.relpath) results, exitcode, _ = run_coala(args=args, debug=debug) retval = {'results': results} if args.log_json: retval['logs'] = [ json.loads(line) for line in log_stream.getvalue().splitlines() ] if args.output: filename = str(args.output[0]) with open(filename, 'w') as fp: json.dump(retval, fp, cls=JSONEncoder, sort_keys=True, indent=2, separators=(',', ': ')) else: print( json.dumps(retval, cls=JSONEncoder, sort_keys=True, indent=2, separators=(',', ': '))) return 0 if args.show_bears else exitcode
def main(): try: console_printer = ConsolePrinter() log_printer = LogPrinter(console_printer) # Note: We parse the args here once to check whether to show bears or # not. args = default_arg_parser().parse_args() if args.show_bears: local_bears, global_bears = get_filtered_bears( args.filter_by_language, log_printer) show_bears(local_bears, global_bears, args.show_description or args.show_details, args.show_details, console_printer) return 0 elif args.show_capabilities: local_bears, global_bears = get_filtered_bears( args.filter_by_language, log_printer) capabilities = filter_capabilities_by_languages( local_bears, args.show_capabilities) show_language_bears_capabilities(capabilities, console_printer) return 0 except BaseException as exception: # pylint: disable=broad-except return get_exitcode(exception, log_printer) partial_print_sec_beg = functools.partial(print_section_beginning, console_printer) results, exitcode, _ = run_coala( print_results=print_results, acquire_settings=acquire_settings, print_section_beginning=partial_print_sec_beg, nothing_done=nothing_done) return exitcode
def test_execute_with_filters(self, debug=False): coala_config = ('[section_one]', 'tags = save', '[section_two]', 'tags = change',) with bear_test_module(): with prepare_file(['#fixme'], None) as (_, filename): with prepare_file(coala_config, None) as (_, configuration): results, retval, _ = run_coala( console_printer=ConsolePrinter(), log_printer=LogPrinter(), arg_list=( '-c', configuration, '-f', filename, '-b', 'TestBear', '--filter-by', 'section_tags', 'save' ), autoapply=False, debug=debug) self.assertTrue('section_one' in results)
def mode_json(args, debug=False): import json from coalib.coala_main import run_coala from coalib.output.Logging import configure_json_logging from coalib.output.JSONEncoder import create_json_encoder if args.log_json: log_stream = configure_json_logging() JSONEncoder = create_json_encoder(use_relpath=args.relpath) results, exitcode, _ = run_coala(args=args, debug=debug) retval = {'results': results} if args.log_json: retval['logs'] = [json.loads(line) for line in log_stream.getvalue().splitlines()] if args.output: filename = str(args.output[0]) with open(filename, 'w') as fp: json.dump(retval, fp, cls=JSONEncoder, sort_keys=True, indent=2, separators=(',', ': ')) else: print(json.dumps(retval, cls=JSONEncoder, sort_keys=True, indent=2, separators=(',', ': '))) return 0 if args.show_bears else exitcode
def main(): results, exitcode = run_coala(autoapply=False, print_results=print_results_no_input) return exitcode
def setUp(self): log_printer = ListLogPrinter() file_dict = run_coala(log_printer=log_printer, autoapply=False)[2] self.FL = list(parse_file_dict(file_dict).keys())
def main(): arg_parser = get_args() args = arg_parser.parse_args() dir_path = create_dir(os.path.abspath(args.dir)) main_package = gen_file_set(get_file(Constants.COALA_HTML_BASE)) local_package = gen_file_set(dir_path) if not main_package.issubset(local_package): # pragma: no cover copy_files(get_file(Constants.COALA_HTML_BASE), dir_path) if not args.noupdate: log_printer = ListLogPrinter() results, exitcode, file_dict = run_coala(log_printer=log_printer, arg_parser=arg_parser) result_data = {"results": results} result_data["logs"] = log_printer.logs JSONEncoder = create_json_encoder(use_relpath=False) result_file = get_file(Constants.CONFIGS['results_file'], dir_path) file_data = get_file(Constants.CONFIGS['file_data'], dir_path) file_tree_data = get_file(Constants.CONFIGS['files'], dir_path) with open(file_tree_data, 'w') as fp: file_graph = build_file_graph(file_dict, dir_path) json.dump(file_graph, fp, cls=JSONEncoder, sort_keys=True, indent=2, separators=(',', ': ')) with open(result_file, 'w') as fp: json.dump(result_data, fp, cls=JSONEncoder, sort_keys=True, indent=2, separators=(',', ': ')) with open(file_data, 'w') as fp: json.dump(parse_file_dict(file_dict), fp, cls=JSONEncoder, sort_keys=True, indent=2, separators=(',', ': ')) if not args.nolaunch: # Launch server with reference point dir_path os.chdir(dir_path) if not os.path.exists('bower_components'): res = call(['bower', 'install']) if res != 0: # pragma: no cover print("Bower is required. Install from `http://bower.io/`") sys.exit(1) Handler = http.server.SimpleHTTPRequestHandler socketserver.TCPServer.allow_reuse_address = True httpd = socketserver.TCPServer(("", Constants.PORT), Handler) print("serving at ", Constants.URL) print("Press Ctrl+C to end the coala-html session") webbrowser.open(Constants.URL, new=2) try: httpd.serve_forever() except KeyboardInterrupt: httpd.server_close()
def main(): results, exitcode = run_coala(print_results=print_results_formatted) return exitcode
def main(): results, exitcode = run_coala(autoapply=False) return exitcode
def main(): results, exitcode = run_coala() return exitcode