Beispiel #1
0
 def wrap_analysis_main(argv=None):
     """
     Actual main function for analysis code, deals with parsers and
     logging
     """
     if argv is None:
         argv = sys.argv[1:]
     cmd_args = {}
     parser = argparse.ArgumentParser(
         description=cmd_description,
         argument_default=argparse.SUPPRESS,
     )
     parser.add_argument(
         '--version', action='version',
         version='%(prog)s ' + skw_version
     )
     parser.add_argument(
         "-r", "--runs", action="append", nargs=2,
         metavar=("soln_file", "soln_range"), dest="soln_pairs",
     )
     logging_options(parser)
     cmd_parser = cmd_parser_func(parser)
     args = vars(cmd_parser.parse_args(argv))
     for name, func in cmd_parser_splitters.items():
         cmd_args[name] = func(args)
     with log_handler(args):
         with redirected_warnings(), redirected_logging():
             return cmd(args["soln_pairs"], **cmd_args)
Beispiel #2
0
 def wrap_analysis_main(argv=None):
     """
     Actual main function for analysis code, deals with parsers and
     logging
     """
     if argv is None:
         argv = sys.argv[1:]
     cmd_args = {}
     parser = argparse.ArgumentParser(
         description=cmd_description,
         argument_default=argparse.SUPPRESS,
     )
     parser.add_argument(
         '--version', action='version',
         version='%(prog)s ' + skw_version
     )
     parser.add_argument("soln_file")
     logging_options(parser)
     cmd_parser = cmd_parser_func(parser)
     args = vars(cmd_parser.parse_args(argv))
     for name, func in cmd_parser_splitters.items():
         cmd_args[name] = func(args)
     with log_handler(args):
         with redirected_warnings(), redirected_logging():
             with h5open(args["soln_file"], registries) as soln_file:
                 solutions = soln_file["run"].solutions.values()
                 return cmd(
                     *solutions, **cmd_args
                 )
Beispiel #3
0
 def test_warning_redirections(self):
     from logbook.compat import redirected_warnings
     handler = logbook.TestHandler()
     with handler:
         with redirected_warnings():
             from warnings import warn
             warn(DeprecationWarning('Testing'))
     self.assertEqual(len(handler.records), 1)
     self.assertEqual('[WARNING] DeprecationWarning: Testing',
                      handler.formatted_records[0])
     self.assert_('test_logbook.py' in handler.records[0].filename)
Beispiel #4
0
 def test_warning_redirections(self):
     from logbook.compat import redirected_warnings
     handler = logbook.TestHandler()
     with handler:
         with redirected_warnings():
             from warnings import warn
             warn(RuntimeWarning('Testing'))
     self.assertEqual(len(handler.records), 1)
     self.assertEqual('[WARNING] RuntimeWarning: Testing',
                      handler.formatted_records[0])
     self.assert_(test_file in handler.records[0].filename)
Beispiel #5
0
def stats_main(argv, parser):
    """
    Main entry point for ds-stats
    """
    parser.add_argument("--file", default='-')
    parser.add_argument("--with-stdin", action='store_true', default=False)
    parser.add_argument("solution_files", nargs='*')
    args = parser.parse_args(argv)
    with log_handler(args), redirected_warnings(), redirected_logging():
        return write_stats(get_all_solutions(get_all_files(args)),
                           output_file=args.file)
Beispiel #6
0
def reduce_koala_data_main(argv=None):
    """
    Main entry point for reduce-koala-data
    """
    if argv is None:
        argv = sys.argv[1:]

    args = parse_reduce_koala_data_cli(argv)

    with log_handler(args), redirected_warnings(), redirected_logging():
        config = parse_reduce_koala_data_config(args)

        reduce_koala_data(config)
def test_warning_redirections():
    from logbook.compat import redirected_warnings
    with logbook.TestHandler() as handler:
        redirector = redirected_warnings()
        redirector.start()
        try:
            from warnings import warn
            warn(RuntimeWarning('Testing'))
        finally:
            redirector.end()

    assert len(handler.records) == 1
    assert '[WARNING] RuntimeWarning: Testing' == handler.formatted_records[0]
    assert __file_without_pyc__ in handler.records[0].filename
Beispiel #8
0
def test_warning_redirections():
    from logbook.compat import redirected_warnings
    with logbook.TestHandler() as handler:
        redirector = redirected_warnings()
        redirector.start()
        try:
            from warnings import warn
            warn(RuntimeWarning('Testing'))
        finally:
            redirector.end()

    assert len(handler.records) == 1
    assert '[WARNING] RuntimeWarning: Testing' == handler.formatted_records[0]
    assert __file_without_pyc__ in handler.records[0].filename
Beispiel #9
0
 def wrap_analysis_main(argv, parser):
     """
     Actual main function for analysis code, deals with parsers and
     logging
     """
     cmd_args = {}
     parser.add_argument(
         "-r", "--runs", action="append", nargs=2,
         metavar=("soln_file", "soln_range"), dest="soln_pairs",
     )
     cmd_parser = cmd_parser_func(parser)
     args = vars(cmd_parser.parse_args(argv))
     for name, func in cmd_parser_splitters.items():
         cmd_args[name] = func(args)
     with log_handler(args):
         with redirected_warnings(), redirected_logging():
             return cmd(args["soln_pairs"], **cmd_args)
Beispiel #10
0
 def test_warning_redirections(self):
     from logbook.compat import redirected_warnings
     handler = logbook.TestHandler()
     handler.push_thread()
     try:
         redirector = redirected_warnings()
         redirector.start()
         try:
             from warnings import warn
             warn(RuntimeWarning('Testing'))
         finally:
             redirector.end()
     finally:
         handler.pop_thread()
     self.assertEqual(len(handler.records), 1)
     self.assertEqual('[WARNING] RuntimeWarning: Testing',
                      handler.formatted_records[0])
     self.assert_(test_file in handler.records[0].filename)
Beispiel #11
0
 def wrap_analysis_main(argv, parser):
     """
     Actual main function for analysis code, deals with parsers and
     logging
     """
     cmd_args = {}
     parser.add_argument("soln_file")
     parser.add_argument("soln_range")
     cmd_parser = cmd_parser_func(parser)
     args = vars(cmd_parser.parse_args(argv))
     for name, func in cmd_parser_splitters.items():
         cmd_args[name] = func(args)
     with log_handler(args):
         with redirected_warnings(), redirected_logging():
             return cmd(
                 args["soln_file"],
                 soln_range=args["soln_range"],
                 **cmd_args
             )
Beispiel #12
0
def main(argv, parser):
    """
    Entry point for ds-resoln
    """
    add_solver_arguments(parser)
    parser.add_argument("soln_filename", type=expanded_path)
    parser.add_argument("soln_range")

    args = parser.parse_args(argv)

    overrides = validate_overrides(args.override)

    with log_handler(args), redirected_warnings(), redirected_logging():
        filename, succeeded = resolve(
            soln_filename=args.soln_filename, soln_range=args.soln_range,
            output_file=args.output_file, sonic_method=args.sonic_method,
            output_dir=args.output_dir, store_internal=args.store_internal,
            overrides=overrides,
        )
        print(filename)
        return int(not succeeded)
Beispiel #13
0
 def wrap_analysis_main(argv, parser):
     """
     Actual main function for analysis code, deals with parsers and
     logging
     """
     cmd_args = {}
     parser.add_argument("soln_file")
     cmd_parser = cmd_parser_func(parser)
     args = vars(cmd_parser.parse_args(argv))
     for name, func in cmd_parser_splitters.items():
         cmd_args[name] = func(args)
     with log_handler(args):
         with redirected_warnings(), redirected_logging():
             with h5open(
                 args["soln_file"], registries, mode='r'
             ) as soln_file:
                 solutions = sorted(
                     soln_file["run"].solutions.items(),
                     key=lambda x: int(x[0])
                 )
                 return cmd(
                     solutions, **cmd_args
                 )
Beispiel #14
0
def main():
    """
    Entry point for skw-full-soln
    """
    parser = argparse.ArgumentParser(description='Solver for skw_full_code')
    add_solver_arguments(parser)
    parser.add_argument("config_file")

    args = vars(parser.parse_args())

    config_file = expanded_path(args["config_file"])
    output_dir = expanded_path(args["output_dir"])
    output_file = args.get("output_file", None)
    overrides = validate_overrides(args.get("override", []))

    with log_handler(args), redirected_warnings(), redirected_logging():
        print(
            solve(
                output_file=output_file,
                config_file=config_file,
                output_dir=output_dir,
                overrides=overrides,
            ))