def from_dict(cls, dic): return Metadata( problem=Problem.from_dict(dic["problem"]), code_filename=dic["code_filename"], sample_in_pattern=dic["sample_in_pattern"], sample_out_pattern=dic["sample_out_pattern"], lang=Language.from_name(dic["lang"]), )
def __init__(self, indent_type: str = INDENT_TYPE_SPACE, indent_width: int = 4, code_generator_file: Optional[str] = None, template_file: Optional[str] = None, workspace_dir: Optional[str] = None, lang: str = "cpp", ): from atcodertools.common.language import Language, LanguageNotFoundError, ALL_LANGUAGE_NAMES code_generator_file = normalize_path(code_generator_file) template_file = normalize_path(template_file) try: lang = Language.from_name(lang) except LanguageNotFoundError: raise CodeStyleConfigInitError( "language must be one of {}".format(ALL_LANGUAGE_NAMES)) if indent_type not in [INDENT_TYPE_SPACE, INDENT_TYPE_TAB]: raise CodeStyleConfigInitError( "indent_type must be 'space' or 'tab'") if indent_width < 0: raise CodeStyleConfigInitError( "indent_width must be a positive integer") if code_generator_file is not None and not os.path.exists(code_generator_file): raise CodeStyleConfigInitError( "Module file {} is not found".format(code_generator_file)) if template_file is not None and not os.path.exists(template_file): raise CodeStyleConfigInitError( "The specified template file '{}' is not found".format( template_file) ) self.indent_type = indent_type self.indent_width = indent_width if code_generator_file is not None: try: module = imm.SourceFileLoader( 'code_generator', code_generator_file).load_module() self.code_generator = getattr(module, 'main') except AttributeError as e: raise CodeStyleConfigInitError(e, "Error while loading {}".format( code_generator_file)) else: self.code_generator = lang.default_code_generator self.template_file = normalize_path( template_file or lang.default_template_path) self.workspace_dir = normalize_path( workspace_dir or DEFAULT_WORKSPACE_DIR_PATH) self.lang = lang
def main(prog, args): if len(args) == 0: print("Usage: atcoder tools set [options]") return parser = argparse.ArgumentParser( prog=prog, formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('--judge-type', '-j', help='error type' ' must be one of [{}]'.format( ', '.join(USER_FACING_JUDGE_TYPE_LIST)), type=str, default=None) parser.add_argument('--error-value', '-v', help='error value for decimal number judge:' ' [Default] ' + str(DEFAULT_EPS), type=float, default=None) parser.add_argument("--lang", help="Programming language of your template code, {}.\n".format( " or ".join([lang.name for lang in ALL_LANGUAGES])), default=None) parser.add_argument("--dir", '-d', help="Target directory to test. [Default] Current directory", default=".") args = parser.parse_args(args) metadata = Metadata.load_from(args.dir + "/metadata.json") new_judge_type = args.judge_type if new_judge_type in ["decimal", "absolute", "relative", "absolute_or_relative"]: new_judge_type = "decimal" if args.judge_type == "decimal": args.judge_type = "absolute_or_relative" old_judge_type = metadata.judge_method.judge_type.value if new_judge_type is not None and new_judge_type != old_judge_type: if new_judge_type == JudgeType.Normal.value: metadata.judge_method = NormalJudge() elif new_judge_type == JudgeType.Decimal.value: metadata.judge_method = DecimalJudge() elif new_judge_type == JudgeType.MultiSolution.value: metadata.judge_method = MultiSolutionJudge() elif new_judge_type == JudgeType.Interactive.value: metadata.judge_method = InteractiveJudge() else: raise NoJudgeTypeException() if new_judge_type == JudgeType.Decimal.value: if args.error_value is not None: metadata.judge_method.diff = args.error_value else: print("Warning: error-value is not specified default value is set. ") metadata.judge_method.error_type = ErrorType(args.judge_type) elif new_judge_type == JudgeType.MultiSolution.value: if not os.path.exists("./judge.cpp"): print("touch ./judge.cpp (multi sotlution)") judge_template_path = get_default_judge_template_path('cpp') shutil.copy(judge_template_path, "./judge.cpp") else: print("Judge Code exists") elif new_judge_type == JudgeType.Interactive.value: if not os.path.exists("/judge.cpp"): print("touch ./judge.cpp (interactive)") judge_template_path = get_default_judge_template_path('cpp') shutil.copy(judge_template_path, "./judge.cpp") else: print("Judge Code exists") if args.lang is not None: if args.lang != metadata.lang.name: metadata.lang = Language.from_name(args.lang) metadata.code_filename = metadata.lang.get_code_filename('main') url = "https://atcoder.jp/contests/{}/tasks/{}".format( metadata.problem.contest.contest_id, metadata.problem.problem_id) if not os.path.exists(metadata.code_filename): codegen_main("", ["--lang", metadata.lang.name, url], open(metadata.code_filename, 'w')) else: print("file exists: ", metadata.code_filename) else: print("already set to {}".format(args.lang)) metadata.save_to(args.dir + "/metadata.json") return metadata
def __init__( self, indent_type: str = INDENT_TYPE_SPACE, indent_width: Optional[int] = None, code_generator_file: Optional[str] = None, template_file: Optional[str] = None, workspace_dir: Optional[str] = None, compile_command: Optional[str] = None, lang: str = "cpp", ): from atcodertools.common.language import Language, LanguageNotFoundError, ALL_LANGUAGE_NAMES code_generator_file = normalize_path(code_generator_file) template_file = normalize_path(template_file) try: lang = Language.from_name(lang) except LanguageNotFoundError: raise CodeStyleConfigInitError( "language must be one of {}".format(ALL_LANGUAGE_NAMES)) if indent_type not in [INDENT_TYPE_SPACE, INDENT_TYPE_TAB]: raise CodeStyleConfigInitError( "indent_type must be 'space' or 'tab'") if indent_width is not None and indent_width < 0: raise CodeStyleConfigInitError( "indent_width must be a positive integer") if code_generator_file is not None and not os.path.exists( code_generator_file): raise CodeStyleConfigInitError( "Module file {} is not found".format(code_generator_file)) if template_file is not None and not os.path.exists(template_file): raise CodeStyleConfigInitError( "The specified template file '{}' is not found".format( template_file)) if compile_command is not None: lang.compile_command = compile_command self.indent_type = indent_type if indent_width is not None: self.indent_width = indent_width elif lang.default_code_style is not None and lang.default_code_style.indent_width is not None: self.indent_width = lang.default_code_style.indent_width else: self.indent_width = 4 if code_generator_file is not None: try: module = imm.SourceFileLoader( 'code_generator', code_generator_file).load_module() self.code_generator = getattr(module, 'main') except AttributeError as e: raise CodeStyleConfigInitError( e, "Error while loading {}".format(code_generator_file)) else: self.code_generator = lang.default_code_generator self.template_file = normalize_path(template_file or lang.default_template_path) self.workspace_dir = normalize_path(workspace_dir or DEFAULT_WORKSPACE_DIR_PATH) self.lang = lang
def __init__(self, judge_code_lang="cpp"): self.judge_type = JudgeType.Interactive self.judge_code_filename, self.judge_exec_filename = get_judge_filename( ) from atcodertools.common.language import Language self.judge_code_lang = Language.from_name(judge_code_lang)