21
21
from atcodertools .constprediction .constants_prediction import predict_constants
22
22
from atcodertools .fileutils .create_contest_file import create_examples , \
23
23
create_code
24
+ from atcodertools .fmtprediction .models .format_prediction_result import FormatPredictionResult
24
25
from atcodertools .fmtprediction .predict_format import NoPredictionResultError , \
25
26
MultiplePredictionResultsError , predict_format
26
27
from atcodertools .tools .models .metadata import Metadata
@@ -70,7 +71,6 @@ def prepare_procedure(atcoder_client: AtCoderClient,
70
71
problem : Problem ,
71
72
workspace_root_path : str ,
72
73
template_code_path : str ,
73
- replacement_code_path : str ,
74
74
lang : str ,
75
75
config : Config ):
76
76
pid = problem .get_alphabet ()
@@ -129,40 +129,30 @@ def emit_info(text):
129
129
new_path ))
130
130
131
131
try :
132
-
133
- with open (template_code_path , "r" ) as f :
134
- template = f .read ()
135
-
136
- result = predict_format (content )
137
- constants = predict_constants (content .original_html )
138
-
139
- code_generator = _decide_code_generator (config , lang )
140
- create_code (code_generator (
141
- CodeGenArgs (
142
- template ,
143
- result .format ,
144
- constants ,
145
- config .code_style_config
146
- )),
147
- code_file_path
148
- )
149
- emit_info (
150
- "{} -- Saved auto-generated code to '{}'" .format (
151
- with_color ("Prediction succeeded" , Fore .LIGHTGREEN_EX ),
152
- code_file_path ))
132
+ prediction_result = predict_format (content )
133
+ emit_info (with_color ("Format prediction succeeded" , Fore .LIGHTGREEN_EX ))
153
134
except (NoPredictionResultError , MultiplePredictionResultsError ) as e :
135
+ prediction_result = FormatPredictionResult .empty_result ()
154
136
if isinstance (e , NoPredictionResultError ):
155
137
msg = "No prediction -- Failed to understand the input format"
156
138
else :
157
139
msg = "Too many prediction -- Failed to understand the input format"
158
-
159
- os .makedirs (os .path .dirname (code_file_path ), exist_ok = True )
160
- shutil .copy (replacement_code_path , code_file_path )
161
- emit_warning (
162
- "{} -- Copied {} to {}" .format (
163
- with_color (msg , Fore .LIGHTRED_EX ),
164
- replacement_code_path ,
165
- code_file_path ))
140
+ emit_warning (with_color (msg , Fore .LIGHTRED_EX ))
141
+
142
+ constants = predict_constants (content .original_html )
143
+ code_generator = _decide_code_generator (config , lang )
144
+ with open (template_code_path , "r" ) as f :
145
+ template = f .read ()
146
+
147
+ create_code (code_generator (
148
+ CodeGenArgs (
149
+ template ,
150
+ prediction_result .format ,
151
+ constants ,
152
+ config .code_style_config
153
+ )),
154
+ code_file_path )
155
+ emit_info ("Saved code to {}" .format (code_file_path ))
166
156
167
157
# Save metadata
168
158
metadata_path = os .path .join (problem_dir_path , "metadata.json" )
@@ -183,18 +173,17 @@ def emit_info(text):
183
173
output_splitter ()
184
174
185
175
186
- def func (argv : Tuple [AtCoderClient , Problem , str , str , str , str , Config ]):
187
- atcoder_client , problem , workspace_root_path , template_code_path , replacement_code_path , lang , config = argv
176
+ def func (argv : Tuple [AtCoderClient , Problem , str , str , str , Config ]):
177
+ atcoder_client , problem , workspace_root_path , template_code_path , lang , config = argv
188
178
prepare_procedure (
189
179
atcoder_client , problem , workspace_root_path , template_code_path ,
190
- replacement_code_path , lang , config )
180
+ lang , config )
191
181
192
182
193
183
def prepare_contest (atcoder_client : AtCoderClient ,
194
184
contest_id : str ,
195
185
workspace_root_path : str ,
196
186
template_code_path : str ,
197
- replacement_code_path : str ,
198
187
lang : str ,
199
188
parallel : bool ,
200
189
config : Config ,
@@ -209,7 +198,7 @@ def prepare_contest(atcoder_client: AtCoderClient,
209
198
logging .warning (
210
199
"Failed to fetch. Will retry in {} seconds" .format (retry_duration ))
211
200
212
- tasks = [(atcoder_client , problem , workspace_root_path , template_code_path , replacement_code_path , lang , config ) for
201
+ tasks = [(atcoder_client , problem , workspace_root_path , template_code_path , lang , config ) for
213
202
problem in problem_list ]
214
203
215
204
output_splitter ()
@@ -242,11 +231,7 @@ def prepare_contest(atcoder_client: AtCoderClient,
242
231
243
232
244
233
def get_default_template_path (lang ):
245
- return os .path .abspath (os .path .join (DEFAULT_TEMPLATE_DIR_PATH , "{lang}/template_success.{lang}" .format (lang = lang )))
246
-
247
-
248
- def get_default_replacement_path (lang ):
249
- return os .path .abspath (os .path .join (DEFAULT_TEMPLATE_DIR_PATH , "{lang}/template_failure.{lang}" ).format (lang = lang ))
234
+ return os .path .abspath (os .path .join (DEFAULT_TEMPLATE_DIR_PATH , "{lang}/default_template.{lang}" .format (lang = lang )))
250
235
251
236
252
237
def decide_template_path (lang : str , config : Config , cmd_template_path : str ):
@@ -290,6 +275,10 @@ def _load(path: str) -> Config:
290
275
return _load (DEFAULT_CONFIG_PATH )
291
276
292
277
278
+ class DeletedFunctionalityError (Exception ):
279
+ pass
280
+
281
+
293
282
def main (prog , args ):
294
283
parser = argparse .ArgumentParser (
295
284
prog = prog ,
@@ -322,13 +311,8 @@ def main(prog, args):
322
311
get_default_template_path ('java' )))
323
312
)
324
313
325
- parser .add_argument ("--replacement" ,
326
- help = "File path to your config file\n {0}{1}" .format (
327
- "[Default (C++)] {}\n " .format (
328
- get_default_replacement_path ('cpp' )),
329
- "[Default (Java)] {}" .format (
330
- get_default_replacement_path ('java' )))
331
- )
314
+ # Deleted functionality
315
+ parser .add_argument ('--replacement' , help = argparse .SUPPRESS )
332
316
333
317
parser .add_argument ("--parallel" ,
334
318
action = "store_true" ,
@@ -349,6 +333,12 @@ def main(prog, args):
349
333
350
334
args = parser .parse_args (args )
351
335
336
+ if args .replacement is not None :
337
+ logging .error (with_color ("Sorry! --replacement argument no longer exists"
338
+ " and you can only use --template."
339
+ " See the official document for details." , Fore .LIGHTRED_EX ))
340
+ raise DeletedFunctionalityError
341
+
352
342
try :
353
343
import AccountInformation # noqa
354
344
raise BannedFileDetectedError (
@@ -373,8 +363,6 @@ def main(prog, args):
373
363
args .contest_id ,
374
364
args .workspace ,
375
365
decide_template_path (args .lang , config , args .template ),
376
- args .replacement if args .replacement is not None else get_default_replacement_path (
377
- args .lang ),
378
366
args .lang ,
379
367
args .parallel ,
380
368
config
0 commit comments