rbx.cp 0.5.39__py3-none-any.whl → 0.5.42__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rbx/box/builder.py +6 -6
- rbx/box/checkers.py +105 -26
- rbx/box/cli.py +860 -0
- rbx/box/code.py +199 -84
- rbx/box/contest/statements.py +4 -2
- rbx/box/generators.py +55 -49
- rbx/box/generators_test.py +7 -7
- rbx/box/main.py +1 -852
- rbx/box/package.py +42 -1
- rbx/box/packaging/boca/packager.py +2 -1
- rbx/box/packaging/main.py +24 -7
- rbx/box/packaging/moj/packager.py +164 -0
- rbx/box/retries.py +5 -5
- rbx/box/schema.py +86 -4
- rbx/box/solutions.py +46 -108
- rbx/box/solutions_test.py +5 -6
- rbx/box/statements/build_statements.py +4 -2
- rbx/box/stresses.py +23 -12
- rbx/box/tasks.py +258 -0
- rbx/box/testcase_extractors.py +21 -21
- rbx/box/testcases/main.py +19 -14
- rbx/box/unit.py +116 -0
- rbx/box/validators.py +27 -18
- rbx/box/validators_test.py +3 -3
- rbx/grading/judge/sandbox.py +8 -0
- rbx/grading/judge/sandboxes/stupid_sandbox.py +12 -7
- rbx/grading/judge/sandboxes/timeit.py +8 -2
- rbx/grading/steps.py +76 -2
- rbx/grading/steps_with_caching.py +45 -3
- rbx/grading/steps_with_caching_run_test.py +51 -49
- rbx/resources/packagers/moj/scripts/compare.sh +101 -0
- rbx/test.py +6 -4
- rbx/testdata/interactive/checker.cpp +21 -0
- rbx/testdata/interactive/gen.cpp +11 -0
- rbx/testdata/interactive/interactor.cpp +63 -0
- rbx/testdata/interactive/problem.rbx.yml +40 -0
- rbx/testdata/interactive/sols/af_ac_pe.cpp +75 -0
- rbx/testdata/interactive/sols/af_ac_re.cpp +76 -0
- rbx/testdata/interactive/sols/af_ac_too_many_iter.cpp +72 -0
- rbx/testdata/interactive/sols/af_inf_cout_with_flush.cpp +79 -0
- rbx/testdata/interactive/sols/af_inf_cout_without_flush.cpp +78 -0
- rbx/testdata/interactive/sols/af_ml.cpp +78 -0
- rbx/testdata/interactive/sols/af_tl_after_ans.cpp +74 -0
- rbx/testdata/interactive/sols/af_wa.cpp +74 -0
- rbx/testdata/interactive/sols/interactive-binary-search_mm_naive_cin.cpp +17 -0
- rbx/testdata/interactive/sols/main.cpp +26 -0
- rbx/testdata/interactive/testplan.txt +6 -0
- rbx/testdata/interactive/validator.cpp +16 -0
- {rbx_cp-0.5.39.dist-info → rbx_cp-0.5.42.dist-info}/METADATA +2 -1
- {rbx_cp-0.5.39.dist-info → rbx_cp-0.5.42.dist-info}/RECORD +53 -32
- {rbx_cp-0.5.39.dist-info → rbx_cp-0.5.42.dist-info}/LICENSE +0 -0
- {rbx_cp-0.5.39.dist-info → rbx_cp-0.5.42.dist-info}/WHEEL +0 -0
- {rbx_cp-0.5.39.dist-info → rbx_cp-0.5.42.dist-info}/entry_points.txt +0 -0
rbx/box/main.py
CHANGED
@@ -3,855 +3,4 @@ from gevent import monkey
|
|
3
3
|
|
4
4
|
monkey.patch_all()
|
5
5
|
|
6
|
-
import
|
7
|
-
import tempfile
|
8
|
-
import shlex
|
9
|
-
import sys
|
10
|
-
|
11
|
-
from rbx.box.schema import CodeItem, ExpectedOutcome, TestcaseGroup
|
12
|
-
|
13
|
-
|
14
|
-
import pathlib
|
15
|
-
import shutil
|
16
|
-
from typing import Annotated, List, Optional
|
17
|
-
|
18
|
-
import rich
|
19
|
-
import rich.prompt
|
20
|
-
import typer
|
21
|
-
|
22
|
-
from rbx import annotations, config, console, utils
|
23
|
-
from rbx.box import (
|
24
|
-
cd,
|
25
|
-
setter_config,
|
26
|
-
state,
|
27
|
-
creation,
|
28
|
-
download,
|
29
|
-
environment,
|
30
|
-
generators,
|
31
|
-
package,
|
32
|
-
compile,
|
33
|
-
presets,
|
34
|
-
validators,
|
35
|
-
)
|
36
|
-
from rbx.box.contest import main as contest
|
37
|
-
from rbx.box.contest.contest_package import find_contest_yaml
|
38
|
-
from rbx.box.environment import VerificationLevel, get_environment_path
|
39
|
-
from rbx.box.packaging import main as packaging
|
40
|
-
from rbx.box.testcases import main as testcases
|
41
|
-
from rbx.box.solutions import (
|
42
|
-
estimate_time_limit,
|
43
|
-
get_exact_matching_solutions,
|
44
|
-
get_matching_solutions,
|
45
|
-
pick_solutions,
|
46
|
-
print_run_report,
|
47
|
-
run_and_print_interactive_solutions,
|
48
|
-
run_solutions,
|
49
|
-
)
|
50
|
-
from rbx.box.statements import build_statements
|
51
|
-
from rbx.box.testcase_utils import TestcaseEntry
|
52
|
-
|
53
|
-
app = typer.Typer(no_args_is_help=True, cls=annotations.AliasGroup)
|
54
|
-
app.add_typer(
|
55
|
-
setter_config.app,
|
56
|
-
name='config, cfg',
|
57
|
-
cls=annotations.AliasGroup,
|
58
|
-
help='Manage setter configuration (sub-command).',
|
59
|
-
rich_help_panel='Configuration',
|
60
|
-
)
|
61
|
-
app.add_typer(
|
62
|
-
build_statements.app,
|
63
|
-
name='statements, st',
|
64
|
-
cls=annotations.AliasGroup,
|
65
|
-
help='Manage statements (sub-command).',
|
66
|
-
rich_help_panel='Deploying',
|
67
|
-
)
|
68
|
-
app.add_typer(
|
69
|
-
download.app,
|
70
|
-
name='download',
|
71
|
-
cls=annotations.AliasGroup,
|
72
|
-
help='Download an asset from supported repositories (sub-command).',
|
73
|
-
rich_help_panel='Management',
|
74
|
-
)
|
75
|
-
app.add_typer(
|
76
|
-
presets.app,
|
77
|
-
name='presets',
|
78
|
-
cls=annotations.AliasGroup,
|
79
|
-
help='Manage presets (sub-command).',
|
80
|
-
rich_help_panel='Configuration',
|
81
|
-
)
|
82
|
-
app.add_typer(
|
83
|
-
packaging.app,
|
84
|
-
name='package, pkg',
|
85
|
-
cls=annotations.AliasGroup,
|
86
|
-
help='Build problem packages (sub-command).',
|
87
|
-
rich_help_panel='Deploying',
|
88
|
-
)
|
89
|
-
app.add_typer(
|
90
|
-
contest.app,
|
91
|
-
name='contest',
|
92
|
-
cls=annotations.AliasGroup,
|
93
|
-
help='Manage contests (sub-command).',
|
94
|
-
rich_help_panel='Management',
|
95
|
-
)
|
96
|
-
app.add_typer(
|
97
|
-
testcases.app,
|
98
|
-
name='testcases, tc, t',
|
99
|
-
cls=annotations.AliasGroup,
|
100
|
-
help='Manage testcases (sub-command).',
|
101
|
-
rich_help_panel='Management',
|
102
|
-
)
|
103
|
-
|
104
|
-
|
105
|
-
@app.callback()
|
106
|
-
def main(
|
107
|
-
sanitized: bool = typer.Option(
|
108
|
-
False,
|
109
|
-
'--sanitized',
|
110
|
-
'-s',
|
111
|
-
help='Whether to compile and run testlib components with sanitizers enabled. '
|
112
|
-
'If you want to run the solutions with sanitizers enabled, use the "-s" flag in the corresponding run command.',
|
113
|
-
),
|
114
|
-
):
|
115
|
-
state.STATE.run_through_cli = True
|
116
|
-
state.STATE.sanitized = sanitized
|
117
|
-
if sanitized:
|
118
|
-
console.console.print(
|
119
|
-
'[warning]Sanitizers are running just for testlib components.\n'
|
120
|
-
'If you want to run the solutions with sanitizers enabled, use the [item]-s[/item] flag in the corresponding run command.[/warning]'
|
121
|
-
)
|
122
|
-
|
123
|
-
|
124
|
-
# @app.command('ui', hidden=True)
|
125
|
-
# @package.within_problem
|
126
|
-
# def ui():
|
127
|
-
# ui_pkg.start()
|
128
|
-
|
129
|
-
|
130
|
-
@app.command(
|
131
|
-
'edit, e',
|
132
|
-
rich_help_panel='Configuration',
|
133
|
-
help='Open problem.rbx.yml in your default editor.',
|
134
|
-
)
|
135
|
-
@package.within_problem
|
136
|
-
def edit():
|
137
|
-
console.console.print('Opening problem definition in editor...')
|
138
|
-
# Call this function just to raise exception in case we're no in
|
139
|
-
# a problem package.
|
140
|
-
package.find_problem()
|
141
|
-
config.open_editor(package.find_problem_yaml() or pathlib.Path())
|
142
|
-
|
143
|
-
|
144
|
-
@app.command(
|
145
|
-
'build, b', rich_help_panel='Deploying', help='Build all tests for the problem.'
|
146
|
-
)
|
147
|
-
@package.within_problem
|
148
|
-
def build(verification: environment.VerificationParam):
|
149
|
-
from rbx.box import builder
|
150
|
-
|
151
|
-
builder.build(verification=verification)
|
152
|
-
|
153
|
-
|
154
|
-
@app.command(
|
155
|
-
'run, r',
|
156
|
-
rich_help_panel='Testing',
|
157
|
-
help='Build and run solution(s).',
|
158
|
-
)
|
159
|
-
@package.within_problem
|
160
|
-
def run(
|
161
|
-
verification: environment.VerificationParam,
|
162
|
-
solution: Annotated[
|
163
|
-
Optional[str],
|
164
|
-
typer.Argument(
|
165
|
-
help='Path to solution to run. If not specified, will run all solutions.'
|
166
|
-
),
|
167
|
-
] = None,
|
168
|
-
outcome: Optional[str] = typer.Option(
|
169
|
-
None,
|
170
|
-
'--outcome',
|
171
|
-
'-o',
|
172
|
-
help='Include only solutions whose expected outcomes intersect with this.',
|
173
|
-
),
|
174
|
-
check: bool = typer.Option(
|
175
|
-
True,
|
176
|
-
'--nocheck',
|
177
|
-
flag_value=False,
|
178
|
-
help='Whether to not build outputs for tests and run checker.',
|
179
|
-
),
|
180
|
-
detailed: bool = typer.Option(
|
181
|
-
False,
|
182
|
-
'--detailed',
|
183
|
-
'-d',
|
184
|
-
help='Whether to print a detailed view of the tests using tables.',
|
185
|
-
),
|
186
|
-
timeit: bool = typer.Option(
|
187
|
-
False,
|
188
|
-
'--time',
|
189
|
-
'-t',
|
190
|
-
help='Whether to use estimate a time limit based on accepted solutions.',
|
191
|
-
),
|
192
|
-
sanitized: bool = typer.Option(
|
193
|
-
False,
|
194
|
-
'--sanitized',
|
195
|
-
'-s',
|
196
|
-
help='Whether to compile the solutions with sanitizers enabled.',
|
197
|
-
),
|
198
|
-
choice: bool = typer.Option(
|
199
|
-
False,
|
200
|
-
'--choice',
|
201
|
-
'--choose',
|
202
|
-
'-c',
|
203
|
-
help='Whether to pick solutions interactively.',
|
204
|
-
),
|
205
|
-
):
|
206
|
-
main_solution = package.get_main_solution()
|
207
|
-
if check and main_solution is None:
|
208
|
-
console.console.print(
|
209
|
-
'[warning]No main solution found, running without checkers.[/warning]'
|
210
|
-
)
|
211
|
-
check = False
|
212
|
-
|
213
|
-
tracked_solutions = None
|
214
|
-
if outcome is not None:
|
215
|
-
tracked_solutions = {
|
216
|
-
str(solution.path)
|
217
|
-
for solution in get_matching_solutions(ExpectedOutcome(outcome))
|
218
|
-
}
|
219
|
-
if solution:
|
220
|
-
tracked_solutions = {solution}
|
221
|
-
|
222
|
-
if choice:
|
223
|
-
tracked_solutions = set(pick_solutions(tracked_solutions))
|
224
|
-
if not tracked_solutions:
|
225
|
-
console.console.print('[error]No solutions selected. Exiting.[/error]')
|
226
|
-
raise typer.Exit(1)
|
227
|
-
|
228
|
-
from rbx.box import builder
|
229
|
-
|
230
|
-
if not builder.build(verification=verification, output=check):
|
231
|
-
return
|
232
|
-
|
233
|
-
if verification <= VerificationLevel.VALIDATE.value:
|
234
|
-
console.console.print(
|
235
|
-
'[warning]Verification level is set to [item]validate (-v1)[/item], so rbx only build tests and validated them.[/warning]'
|
236
|
-
)
|
237
|
-
return
|
238
|
-
|
239
|
-
override_tl = None
|
240
|
-
if timeit:
|
241
|
-
if sanitized:
|
242
|
-
console.console.print(
|
243
|
-
'[error]Sanitizers are known to be time-hungry, so they cannot be used for time estimation.\n'
|
244
|
-
'Remove either the [item]-s[/item] flag or the [item]-t[/item] flag to run solutions without sanitizers.[/error]'
|
245
|
-
)
|
246
|
-
raise typer.Exit(1)
|
247
|
-
|
248
|
-
# Never use sanitizers for time estimation.
|
249
|
-
override_tl = _time_impl(check=check, detailed=False)
|
250
|
-
if override_tl is None:
|
251
|
-
raise typer.Exit(1)
|
252
|
-
|
253
|
-
if sanitized:
|
254
|
-
console.console.print(
|
255
|
-
'[warning]Sanitizers are running, so the time limit for the problem will be dropped, '
|
256
|
-
'and the environment default time limit will be used instead.[/warning]'
|
257
|
-
)
|
258
|
-
|
259
|
-
if sanitized and tracked_solutions is None:
|
260
|
-
console.console.print(
|
261
|
-
'[warning]Sanitizers are running, and no solutions were specified to run. Will only run [item]ACCEPTED[/item] solutions.'
|
262
|
-
)
|
263
|
-
tracked_solutions = {
|
264
|
-
str(solution.path)
|
265
|
-
for solution in get_exact_matching_solutions(ExpectedOutcome.ACCEPTED)
|
266
|
-
}
|
267
|
-
|
268
|
-
with utils.StatusProgress('Running solutions...') as s:
|
269
|
-
solution_result = run_solutions(
|
270
|
-
progress=s,
|
271
|
-
tracked_solutions=tracked_solutions,
|
272
|
-
check=check,
|
273
|
-
verification=VerificationLevel(verification),
|
274
|
-
timelimit_override=override_tl,
|
275
|
-
sanitized=sanitized,
|
276
|
-
)
|
277
|
-
|
278
|
-
console.console.print()
|
279
|
-
console.console.rule('[status]Run report[/status]', style='status')
|
280
|
-
asyncio.run(
|
281
|
-
print_run_report(
|
282
|
-
solution_result,
|
283
|
-
console.console,
|
284
|
-
VerificationLevel(verification),
|
285
|
-
detailed=detailed,
|
286
|
-
skip_printing_limits=sanitized,
|
287
|
-
)
|
288
|
-
)
|
289
|
-
|
290
|
-
|
291
|
-
def _time_impl(check: bool, detailed: bool) -> Optional[int]:
|
292
|
-
if package.get_main_solution() is None:
|
293
|
-
console.console.print(
|
294
|
-
'[warning]No main solution found, so cannot estimate a time limit.[/warning]'
|
295
|
-
)
|
296
|
-
return None
|
297
|
-
|
298
|
-
verification = VerificationLevel.ALL_SOLUTIONS.value
|
299
|
-
|
300
|
-
with utils.StatusProgress('Running ACCEPTED solutions...') as s:
|
301
|
-
tracked_solutions = {
|
302
|
-
str(solution.path)
|
303
|
-
for solution in get_exact_matching_solutions(ExpectedOutcome.ACCEPTED)
|
304
|
-
}
|
305
|
-
solution_result = run_solutions(
|
306
|
-
progress=s,
|
307
|
-
tracked_solutions=tracked_solutions,
|
308
|
-
check=check,
|
309
|
-
verification=VerificationLevel(verification),
|
310
|
-
timelimit_override=600, # 10 minute time limit for estimation
|
311
|
-
)
|
312
|
-
|
313
|
-
console.console.print()
|
314
|
-
console.console.rule(
|
315
|
-
'[status]Run report (for time estimation)[/status]', style='status'
|
316
|
-
)
|
317
|
-
ok = asyncio.run(
|
318
|
-
print_run_report(
|
319
|
-
solution_result,
|
320
|
-
console.console,
|
321
|
-
VerificationLevel(verification),
|
322
|
-
detailed=detailed,
|
323
|
-
skip_printing_limits=True,
|
324
|
-
)
|
325
|
-
)
|
326
|
-
|
327
|
-
if not ok:
|
328
|
-
console.console.print(
|
329
|
-
'[error]Failed to run ACCEPTED solutions, so cannot estimate a reliable time limit.[/error]'
|
330
|
-
)
|
331
|
-
return None
|
332
|
-
|
333
|
-
console.console.print()
|
334
|
-
return asyncio.run(estimate_time_limit(console.console, solution_result))
|
335
|
-
|
336
|
-
|
337
|
-
@app.command(
|
338
|
-
'time, t',
|
339
|
-
rich_help_panel='Testing',
|
340
|
-
help='Estimate a time limit for the problem based on a time limit formula and timings of accepted solutions.',
|
341
|
-
)
|
342
|
-
@package.within_problem
|
343
|
-
def time(
|
344
|
-
check: bool = typer.Option(
|
345
|
-
True,
|
346
|
-
'--nocheck',
|
347
|
-
flag_value=False,
|
348
|
-
help='Whether to not build outputs for tests and run checker.',
|
349
|
-
),
|
350
|
-
detailed: bool = typer.Option(
|
351
|
-
False,
|
352
|
-
'--detailed',
|
353
|
-
'-d',
|
354
|
-
help='Whether to print a detailed view of the tests using tables.',
|
355
|
-
),
|
356
|
-
):
|
357
|
-
main_solution = package.get_main_solution()
|
358
|
-
if check and main_solution is None:
|
359
|
-
console.console.print(
|
360
|
-
'[warning]No main solution found, running without checkers.[/warning]'
|
361
|
-
)
|
362
|
-
check = False
|
363
|
-
|
364
|
-
from rbx.box import builder
|
365
|
-
|
366
|
-
verification = VerificationLevel.ALL_SOLUTIONS.value
|
367
|
-
if not builder.build(verification=verification, output=check):
|
368
|
-
return None
|
369
|
-
|
370
|
-
_time_impl(check, detailed)
|
371
|
-
|
372
|
-
|
373
|
-
@app.command(
|
374
|
-
'irun, ir',
|
375
|
-
rich_help_panel='Testing',
|
376
|
-
help='Build and run solution(s) by passing testcases in the CLI.',
|
377
|
-
)
|
378
|
-
@package.within_problem
|
379
|
-
def irun(
|
380
|
-
verification: environment.VerificationParam,
|
381
|
-
solution: Annotated[
|
382
|
-
Optional[str],
|
383
|
-
typer.Argument(
|
384
|
-
help='Path to solution to run. If not specified, will run all solutions.'
|
385
|
-
),
|
386
|
-
] = None,
|
387
|
-
outcome: Optional[str] = typer.Option(
|
388
|
-
None,
|
389
|
-
'--outcome',
|
390
|
-
'-o',
|
391
|
-
help='Include only solutions whose expected outcomes intersect with this.',
|
392
|
-
),
|
393
|
-
check: bool = typer.Option(
|
394
|
-
True,
|
395
|
-
'--nocheck',
|
396
|
-
flag_value=False,
|
397
|
-
help='Whether to not build outputs for tests and run checker.',
|
398
|
-
),
|
399
|
-
generator: Optional[str] = typer.Option(
|
400
|
-
None,
|
401
|
-
'--generator',
|
402
|
-
'-g',
|
403
|
-
help='Generator call to use to generate a single test for execution.',
|
404
|
-
),
|
405
|
-
testcase: Optional[str] = typer.Option(
|
406
|
-
None,
|
407
|
-
'--testcase',
|
408
|
-
'--test',
|
409
|
-
'-tc',
|
410
|
-
'-t',
|
411
|
-
help='Testcase to run, in the format "[group]/[index]". If not specified, will run interactively.',
|
412
|
-
),
|
413
|
-
output: bool = typer.Option(
|
414
|
-
False,
|
415
|
-
'--output',
|
416
|
-
'-o',
|
417
|
-
help='Whether to ask user for custom output.',
|
418
|
-
),
|
419
|
-
print: bool = typer.Option(
|
420
|
-
False, '--print', '-p', help='Whether to print outputs to terminal.'
|
421
|
-
),
|
422
|
-
sanitized: bool = typer.Option(
|
423
|
-
False,
|
424
|
-
'--sanitized',
|
425
|
-
'-s',
|
426
|
-
help='Whether to compile the solutions with sanitizers enabled.',
|
427
|
-
),
|
428
|
-
choice: bool = typer.Option(
|
429
|
-
False,
|
430
|
-
'--choice',
|
431
|
-
'--choose',
|
432
|
-
'-c',
|
433
|
-
help='Whether to pick solutions interactively.',
|
434
|
-
),
|
435
|
-
):
|
436
|
-
if not print:
|
437
|
-
console.console.print(
|
438
|
-
'[warning]Outputs will be written to files. If you wish to print them to the terminal, use the "-p" parameter.'
|
439
|
-
)
|
440
|
-
if verification < VerificationLevel.ALL_SOLUTIONS.value:
|
441
|
-
console.console.print(
|
442
|
-
'[warning]Verification level should be at least [item]all solutions (-v4)[/item] to run solutions interactively.'
|
443
|
-
)
|
444
|
-
return
|
445
|
-
|
446
|
-
tracked_solutions = None
|
447
|
-
if outcome is not None:
|
448
|
-
tracked_solutions = {
|
449
|
-
str(solution.path)
|
450
|
-
for solution in get_matching_solutions(ExpectedOutcome(outcome))
|
451
|
-
}
|
452
|
-
if solution:
|
453
|
-
tracked_solutions = {solution}
|
454
|
-
|
455
|
-
if choice:
|
456
|
-
tracked_solutions = set(pick_solutions(tracked_solutions))
|
457
|
-
if not tracked_solutions:
|
458
|
-
console.console.print('[error]No solutions selected. Exiting.[/error]')
|
459
|
-
raise typer.Exit(1)
|
460
|
-
|
461
|
-
if sanitized and tracked_solutions is None:
|
462
|
-
console.console.print(
|
463
|
-
'[warning]Sanitizers are running, and no solutions were specified to run. Will only run [item]ACCEPTED[/item] solutions.'
|
464
|
-
)
|
465
|
-
tracked_solutions = {
|
466
|
-
str(solution.path)
|
467
|
-
for solution in get_exact_matching_solutions(ExpectedOutcome.ACCEPTED)
|
468
|
-
}
|
469
|
-
|
470
|
-
with utils.StatusProgress('Running solutions...') as s:
|
471
|
-
asyncio.run(
|
472
|
-
run_and_print_interactive_solutions(
|
473
|
-
progress=s,
|
474
|
-
tracked_solutions=tracked_solutions,
|
475
|
-
check=check,
|
476
|
-
verification=VerificationLevel(verification),
|
477
|
-
generator=generators.get_call_from_string(generator)
|
478
|
-
if generator is not None
|
479
|
-
else None,
|
480
|
-
testcase_entry=TestcaseEntry.parse(testcase) if testcase else None,
|
481
|
-
custom_output=output,
|
482
|
-
print=print,
|
483
|
-
sanitized=sanitized,
|
484
|
-
)
|
485
|
-
)
|
486
|
-
|
487
|
-
|
488
|
-
@app.command(
|
489
|
-
'create, c',
|
490
|
-
rich_help_panel='Management',
|
491
|
-
help='Create a new problem package.',
|
492
|
-
)
|
493
|
-
def create(
|
494
|
-
name: str,
|
495
|
-
preset: Annotated[
|
496
|
-
Optional[str], typer.Option(help='Preset to use when creating the problem.')
|
497
|
-
] = None,
|
498
|
-
):
|
499
|
-
if find_contest_yaml() is not None:
|
500
|
-
console.console.print(
|
501
|
-
'[error]Cannot [item]rbx create[/item] a problem inside a contest.[/error]'
|
502
|
-
)
|
503
|
-
console.console.print(
|
504
|
-
'[error]Instead, use [item]rbx contest add[/item] to add a problem to a contest.[/error]'
|
505
|
-
)
|
506
|
-
raise typer.Exit(1)
|
507
|
-
|
508
|
-
if preset is not None:
|
509
|
-
creation.create(name, preset=preset)
|
510
|
-
return
|
511
|
-
creation.create(name)
|
512
|
-
|
513
|
-
|
514
|
-
@app.command(
|
515
|
-
'stress',
|
516
|
-
rich_help_panel='Testing',
|
517
|
-
help='Run a stress test.',
|
518
|
-
)
|
519
|
-
@package.within_problem
|
520
|
-
def stress(
|
521
|
-
name: Annotated[
|
522
|
-
str,
|
523
|
-
typer.Argument(
|
524
|
-
help='Name of the stress test to run (specified in problem.rbx.yml), '
|
525
|
-
'or the generator to run, in case -g is specified.'
|
526
|
-
),
|
527
|
-
],
|
528
|
-
generator_args: Annotated[
|
529
|
-
Optional[str],
|
530
|
-
typer.Option(
|
531
|
-
'--generator',
|
532
|
-
'-g',
|
533
|
-
help='Run generator [name] with these args.',
|
534
|
-
),
|
535
|
-
] = None,
|
536
|
-
finder: Annotated[
|
537
|
-
Optional[str],
|
538
|
-
typer.Option(
|
539
|
-
'--finder',
|
540
|
-
'-f',
|
541
|
-
help='Run a stress with this finder expression.',
|
542
|
-
),
|
543
|
-
] = None,
|
544
|
-
timeout: Annotated[
|
545
|
-
int,
|
546
|
-
typer.Option(
|
547
|
-
'--timeout',
|
548
|
-
'--time',
|
549
|
-
'-t',
|
550
|
-
help='For how many seconds to run the stress test.',
|
551
|
-
),
|
552
|
-
] = 10,
|
553
|
-
findings: Annotated[
|
554
|
-
int,
|
555
|
-
typer.Option('--findings', '-n', help='How many breaking tests to look for.'),
|
556
|
-
] = 1,
|
557
|
-
verbose: bool = typer.Option(
|
558
|
-
False,
|
559
|
-
'-v',
|
560
|
-
'--verbose',
|
561
|
-
help='Whether to print verbose output for checkers and finders.',
|
562
|
-
),
|
563
|
-
sanitized: bool = typer.Option(
|
564
|
-
False,
|
565
|
-
'--sanitized',
|
566
|
-
'-s',
|
567
|
-
help='Whether to compile the solutions with sanitizers enabled.',
|
568
|
-
),
|
569
|
-
):
|
570
|
-
if finder and not generator_args or generator_args and not finder:
|
571
|
-
console.console.print(
|
572
|
-
'[error]Options --generator/-g and --finder/-f should be specified together.'
|
573
|
-
)
|
574
|
-
raise typer.Exit(1)
|
575
|
-
|
576
|
-
from rbx.box import stresses
|
577
|
-
|
578
|
-
with utils.StatusProgress('Running stress...') as s:
|
579
|
-
report = stresses.run_stress(
|
580
|
-
name,
|
581
|
-
timeout,
|
582
|
-
args=generator_args,
|
583
|
-
finder=finder,
|
584
|
-
findingsLimit=findings,
|
585
|
-
progress=s,
|
586
|
-
verbose=verbose,
|
587
|
-
sanitized=sanitized,
|
588
|
-
)
|
589
|
-
|
590
|
-
stresses.print_stress_report(report)
|
591
|
-
|
592
|
-
if not report.findings:
|
593
|
-
return
|
594
|
-
|
595
|
-
# Add found tests.
|
596
|
-
res = rich.prompt.Confirm.ask(
|
597
|
-
'Do you want to add the tests that were found to a test group?',
|
598
|
-
console=console.console,
|
599
|
-
)
|
600
|
-
if not res:
|
601
|
-
return
|
602
|
-
testgroup = None
|
603
|
-
while testgroup is None or testgroup:
|
604
|
-
groups_by_name = {
|
605
|
-
name: group
|
606
|
-
for name, group in package.get_test_groups_by_name().items()
|
607
|
-
if group.generatorScript is not None
|
608
|
-
and group.generatorScript.path.suffix == '.txt'
|
609
|
-
}
|
610
|
-
|
611
|
-
import questionary
|
612
|
-
|
613
|
-
testgroup = questionary.select(
|
614
|
-
'Choose the testgroup to add the tests to.\nOnly test groups that have a .txt generatorScript are shown below: ',
|
615
|
-
choices=list(groups_by_name) + ['(create new script)', '(skip)'],
|
616
|
-
).ask()
|
617
|
-
|
618
|
-
if testgroup == '(create new script)':
|
619
|
-
new_script_name = questionary.text(
|
620
|
-
'Enter the name of the new .txt generatorScript file: '
|
621
|
-
).ask()
|
622
|
-
new_script_path = pathlib.Path(new_script_name).with_suffix('.txt')
|
623
|
-
new_script_path.parent.mkdir(parents=True, exist_ok=True)
|
624
|
-
new_script_path.touch()
|
625
|
-
|
626
|
-
# Temporarily create a new testgroup with the new script.
|
627
|
-
testgroup = new_script_path.stem
|
628
|
-
groups_by_name[testgroup] = TestcaseGroup(
|
629
|
-
name=testgroup, generatorScript=CodeItem(path=new_script_path)
|
630
|
-
)
|
631
|
-
ru, problem_yml = package.get_ruyaml()
|
632
|
-
if 'testcases' not in problem_yml:
|
633
|
-
problem_yml['testcases'] = []
|
634
|
-
problem_yml['testcases'].append(
|
635
|
-
{
|
636
|
-
'name': testgroup,
|
637
|
-
'generatorScript': new_script_path.name,
|
638
|
-
}
|
639
|
-
)
|
640
|
-
dest = package.find_problem_yaml()
|
641
|
-
assert dest is not None
|
642
|
-
utils.save_ruyaml(dest, ru, problem_yml)
|
643
|
-
package.clear_package_cache()
|
644
|
-
|
645
|
-
if testgroup not in groups_by_name:
|
646
|
-
break
|
647
|
-
try:
|
648
|
-
subgroup = groups_by_name[testgroup]
|
649
|
-
assert subgroup.generatorScript is not None
|
650
|
-
generator_script = pathlib.Path(subgroup.generatorScript.path)
|
651
|
-
|
652
|
-
finding_lines = []
|
653
|
-
for finding in report.findings:
|
654
|
-
line = finding.generator.name
|
655
|
-
if finding.generator.args is not None:
|
656
|
-
line = f'{line} {finding.generator.args}'
|
657
|
-
finding_lines.append(line)
|
658
|
-
|
659
|
-
with generator_script.open('a') as f:
|
660
|
-
stress_text = f'# Obtained by running `rbx {shlex.join(sys.argv[1:])}`'
|
661
|
-
finding_text = '\n'.join(finding_lines)
|
662
|
-
f.write(f'\n{stress_text}\n{finding_text}\n')
|
663
|
-
|
664
|
-
console.console.print(
|
665
|
-
f"Added [item]{len(report.findings)}[/item] tests to test group [item]{testgroup}[/item]'s generatorScript at [item]{subgroup.generatorScript.path}[/item]"
|
666
|
-
)
|
667
|
-
except typer.Exit:
|
668
|
-
continue
|
669
|
-
break
|
670
|
-
|
671
|
-
|
672
|
-
@app.command(
|
673
|
-
'compile',
|
674
|
-
rich_help_panel='Testing',
|
675
|
-
help='Compile an asset given its path.',
|
676
|
-
)
|
677
|
-
@package.within_problem
|
678
|
-
def compile_command(
|
679
|
-
path: Annotated[
|
680
|
-
Optional[str],
|
681
|
-
typer.Argument(help='Path to the asset to compile.'),
|
682
|
-
] = None,
|
683
|
-
sanitized: bool = typer.Option(
|
684
|
-
False,
|
685
|
-
'--sanitized',
|
686
|
-
'-s',
|
687
|
-
help='Whether to compile the asset with sanitizers enabled.',
|
688
|
-
),
|
689
|
-
warnings: bool = typer.Option(
|
690
|
-
False,
|
691
|
-
'--warnings',
|
692
|
-
'-w',
|
693
|
-
help='Whether to compile the asset with warnings enabled.',
|
694
|
-
),
|
695
|
-
):
|
696
|
-
if path is None:
|
697
|
-
import questionary
|
698
|
-
|
699
|
-
path = questionary.path("What's the path to your asset?").ask()
|
700
|
-
if path is None:
|
701
|
-
console.console.print('[error]No path specified.[/error]')
|
702
|
-
raise typer.Exit(1)
|
703
|
-
|
704
|
-
compile.any(path, sanitized, warnings)
|
705
|
-
|
706
|
-
|
707
|
-
@app.command(
|
708
|
-
'validate',
|
709
|
-
rich_help_panel='Testing',
|
710
|
-
help='Run the validator in a one-off fashion, interactively.',
|
711
|
-
)
|
712
|
-
@package.within_problem
|
713
|
-
def validate(
|
714
|
-
path: Annotated[
|
715
|
-
Optional[str],
|
716
|
-
typer.Option('--path', '-p', help='Path to the testcase to validate.'),
|
717
|
-
] = None,
|
718
|
-
):
|
719
|
-
validator_tuple = validators.compile_main_validator()
|
720
|
-
if validator_tuple is None:
|
721
|
-
console.console.print('[error]No validator found for this problem.[/error]')
|
722
|
-
raise typer.Exit(1)
|
723
|
-
|
724
|
-
validator, validator_digest = validator_tuple
|
725
|
-
|
726
|
-
input = console.multiline_prompt('Testcase input')
|
727
|
-
|
728
|
-
if path is None:
|
729
|
-
with tempfile.TemporaryDirectory() as tmpdir:
|
730
|
-
tmppath = pathlib.Path(tmpdir) / '000.in'
|
731
|
-
tmppath.write_text(input)
|
732
|
-
|
733
|
-
info = validators.validate_one_off(
|
734
|
-
pathlib.Path(tmppath), validator, validator_digest
|
735
|
-
)
|
736
|
-
else:
|
737
|
-
info = validators.validate_one_off(
|
738
|
-
pathlib.Path(path), validator, validator_digest
|
739
|
-
)
|
740
|
-
|
741
|
-
validators.print_validation_report([info])
|
742
|
-
|
743
|
-
|
744
|
-
@app.command(
|
745
|
-
'environment, env',
|
746
|
-
rich_help_panel='Configuration',
|
747
|
-
help='Set or show the current box environment.',
|
748
|
-
)
|
749
|
-
def environment_command(
|
750
|
-
env: Annotated[Optional[str], typer.Argument()] = None,
|
751
|
-
install_from: Annotated[
|
752
|
-
Optional[str],
|
753
|
-
typer.Option(
|
754
|
-
'--install',
|
755
|
-
'-i',
|
756
|
-
help='Whether to install this environment from the given file.',
|
757
|
-
),
|
758
|
-
] = None,
|
759
|
-
):
|
760
|
-
if env is None:
|
761
|
-
cfg = config.get_config()
|
762
|
-
console.console.print(f'Current environment: [item]{cfg.boxEnvironment}[/item]')
|
763
|
-
console.console.print(
|
764
|
-
f'Location: {environment.get_environment_path(cfg.boxEnvironment)}'
|
765
|
-
)
|
766
|
-
return
|
767
|
-
if install_from is not None:
|
768
|
-
environment.install_environment(env, pathlib.Path(install_from))
|
769
|
-
if not get_environment_path(env).is_file():
|
770
|
-
console.console.print(
|
771
|
-
f'[error]Environment [item]{env}[/item] does not exist.[/error]'
|
772
|
-
)
|
773
|
-
raise typer.Exit(1)
|
774
|
-
|
775
|
-
cfg = config.get_config()
|
776
|
-
if env == cfg.boxEnvironment:
|
777
|
-
console.console.print(
|
778
|
-
f'Environment is already set to [item]{env}[/item].',
|
779
|
-
)
|
780
|
-
return
|
781
|
-
console.console.print(
|
782
|
-
f'Changing box environment from [item]{cfg.boxEnvironment}[/item] to [item]{env}[/item]...'
|
783
|
-
)
|
784
|
-
cfg.boxEnvironment = env
|
785
|
-
config.save_config(cfg)
|
786
|
-
|
787
|
-
# Also clear cache when changing environments.
|
788
|
-
clear()
|
789
|
-
|
790
|
-
|
791
|
-
@app.command(
|
792
|
-
'activate',
|
793
|
-
rich_help_panel='Configuration',
|
794
|
-
help='Activate the environment of the current preset used by the package.',
|
795
|
-
)
|
796
|
-
@cd.within_closest_package
|
797
|
-
def activate():
|
798
|
-
preset_lock = presets.get_preset_lock()
|
799
|
-
if preset_lock is None:
|
800
|
-
console.console.print(
|
801
|
-
'[warning]No configured preset to be activated for this package.[/warning]'
|
802
|
-
)
|
803
|
-
raise typer.Exit(1)
|
804
|
-
|
805
|
-
preset = presets.get_installed_preset_or_null(preset_lock.preset_name)
|
806
|
-
if preset is None:
|
807
|
-
if preset_lock.uri is None:
|
808
|
-
console.console.print(
|
809
|
-
'[error]Preset is not installed. Install it manually, or specify a URI in [item].preset-lock.yml[/item].[/error]'
|
810
|
-
)
|
811
|
-
raise typer.Exit(1)
|
812
|
-
presets.install(preset_lock.uri)
|
813
|
-
|
814
|
-
preset = presets.get_installed_preset(preset_lock.preset_name)
|
815
|
-
|
816
|
-
# Install the environment from the preset if it's not already installed.
|
817
|
-
presets.optionally_install_environment_from_preset(
|
818
|
-
preset, root=presets.get_preset_installation_path(preset_lock.name)
|
819
|
-
)
|
820
|
-
|
821
|
-
# Activate the environment.
|
822
|
-
if preset.env is not None:
|
823
|
-
environment_command(preset.name)
|
824
|
-
|
825
|
-
console.console.print(f'[success]Preset [item]{preset.name}[/item] is activated.')
|
826
|
-
|
827
|
-
|
828
|
-
@app.command(
|
829
|
-
'languages',
|
830
|
-
rich_help_panel='Configuration',
|
831
|
-
help='List the languages available in this environment',
|
832
|
-
)
|
833
|
-
def languages():
|
834
|
-
env = environment.get_environment()
|
835
|
-
|
836
|
-
console.console.print(
|
837
|
-
f'[success]There are [item]{len(env.languages)}[/item] language(s) available.'
|
838
|
-
)
|
839
|
-
|
840
|
-
for language in env.languages:
|
841
|
-
console.console.print(
|
842
|
-
f'[item]{language.name}[/item], aka [item]{language.readable_name or language.name}[/item]:'
|
843
|
-
)
|
844
|
-
console.console.print(language)
|
845
|
-
console.console.print()
|
846
|
-
|
847
|
-
|
848
|
-
@app.command(
|
849
|
-
'clear, clean',
|
850
|
-
rich_help_panel='Management',
|
851
|
-
help='Clears cache and build directories.',
|
852
|
-
)
|
853
|
-
@cd.within_closest_package
|
854
|
-
def clear():
|
855
|
-
console.console.print('Cleaning cache and build directories...')
|
856
|
-
shutil.rmtree('.box', ignore_errors=True)
|
857
|
-
shutil.rmtree('build', ignore_errors=True)
|
6
|
+
from rbx.box.cli import app
|