rbx.cp 0.5.32__py3-none-any.whl → 0.5.34__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/code.py CHANGED
@@ -186,15 +186,14 @@ def _check_stack_limit():
186
186
  if hard != resource.RLIM_INFINITY:
187
187
  target_text = min(hard, TARGET)
188
188
  console.console.print(
189
- """
189
+ f"""
190
190
  ```
191
- export RBX_BIN_PATH=`which rbx`
192
- function rbx() {
193
- ulimit -s %s && $RBX_BIN_PATH $@
194
- }
191
+ function rbx() {{
192
+ local rbx_bin=`bash -c "type -P rbx"`
193
+ ulimit -s {target_text // 1024} && $rbx_bin $@
194
+ }}
195
195
  ```
196
- """
197
- % target_text
196
+ """
198
197
  )
199
198
  console.console.print()
200
199
  console.console.print(
@@ -22,6 +22,7 @@ from rbx.box.statements.builders import (
22
22
  StatementBuilderContest,
23
23
  StatementBuilderContext,
24
24
  StatementBuilderProblem,
25
+ StatementSample,
25
26
  prepare_assets,
26
27
  )
27
28
  from rbx.box.statements.joiners import (
@@ -51,7 +52,7 @@ class ExtractedProblem:
51
52
  return StatementBuilderProblem(
52
53
  package=self.package,
53
54
  statement=self.statement,
54
- samples=self.samples,
55
+ samples=StatementSample.from_testcases(self.samples),
55
56
  io_path=self.built_statement,
56
57
  short_name=self.problem.short_name,
57
58
  )
@@ -124,7 +125,7 @@ def get_builder_problems(
124
125
  StatementBuilderProblem(
125
126
  package=ex.package,
126
127
  statement=ex.statement,
127
- samples=ex.samples,
128
+ samples=StatementSample.from_testcases(ex.samples),
128
129
  )
129
130
  for ex in extracted_problems
130
131
  ]
rbx/box/main.py CHANGED
@@ -760,8 +760,3 @@ def clear():
760
760
  console.console.print('Cleaning cache and build directories...')
761
761
  shutil.rmtree('.box', ignore_errors=True)
762
762
  shutil.rmtree('build', ignore_errors=True)
763
-
764
-
765
- @app.callback()
766
- def callback():
767
- pass
rbx/box/package.py CHANGED
@@ -364,6 +364,13 @@ def get_compilation_files(code: CodeItem) -> List[Tuple[pathlib.Path, pathlib.Pa
364
364
  return res
365
365
 
366
366
 
367
+ @functools.cache
368
+ def get_empty_sentinel_path(root: pathlib.Path = pathlib.Path()) -> pathlib.Path:
369
+ path = get_problem_cache_dir(root) / '.empty'
370
+ path.write_text('')
371
+ return path
372
+
373
+
367
374
  def clear_package_cache():
368
375
  pkgs = [sys.modules[__name__]]
369
376
 
rbx/box/solutions.py CHANGED
@@ -911,38 +911,81 @@ class TimingSummary:
911
911
  if self.fastest_slow is None or time < self.fastest_slow:
912
912
  self.fastest_slow = time
913
913
 
914
+ def print(self, console: rich.console.Console, tl: Optional[int] = None):
915
+ if self.slowest_good is not None:
916
+ console.print(
917
+ f'Slowest [success]OK[/success] solution: {self.slowest_good} ms'
918
+ )
919
+ if self.fastest_slow is not None:
920
+ fastest_slow = self.fastest_slow
921
+ if tl is not None and self.fastest_slow > tl:
922
+ fastest_slow = f'>{tl}'
923
+ console.print(f'Fastest [error]slow[/error] solution: {fastest_slow} ms')
924
+
914
925
 
915
926
  async def _print_timing(
916
927
  console: rich.console.Console,
917
928
  skeleton: SolutionReportSkeleton,
918
929
  evaluations: StructuredEvaluation,
930
+ verification: VerificationLevel,
919
931
  ):
932
+ pkg = package.find_problem_package_or_die()
920
933
  summary = TimingSummary()
921
- sumamry_per_language = collections.defaultdict(TimingSummary)
934
+ summary_per_language = collections.defaultdict(TimingSummary)
935
+ tls_per_language = {}
936
+ all_tls = set()
922
937
  for solution in skeleton.solutions:
923
- all_evals = []
938
+ all_evals: List[Evaluation] = []
924
939
  for evals in evaluations[str(solution.path)].values():
925
940
  all_evals.extend([await eval() for eval in evals if eval is not None])
941
+ if not all_evals:
942
+ continue
943
+
944
+ # Get solution TL.
926
945
  solution_time = _get_evals_time_in_ms(all_evals)
946
+ solution_tls = [
947
+ eval.log.metadata.timeLimit
948
+ for eval in all_evals
949
+ if eval.log.metadata is not None and eval.log.metadata.timeLimit is not None
950
+ ]
951
+ solution_tl = 0
952
+ if solution_tls:
953
+ solution_tl = min(solution_tls)
954
+ else:
955
+ solution_tl = pkg.timelimit_for_language(solution.language)
956
+ if verification.value >= VerificationLevel.FULL.value:
957
+ solution_tl = solution_tl * 2
958
+ all_tls.add(solution_tl)
959
+ for eval in all_evals:
960
+ if eval.log.get_run_language() is not None:
961
+ tls_per_language[eval.log.get_run_language()] = solution_tl
962
+
963
+ # Get solution timings.
927
964
  if solution.outcome.match(Outcome.ACCEPTED):
928
965
  summary.add_good(solution_time)
929
- sumamry_per_language[solution.language].add_good(solution_time)
966
+ summary_per_language[solution.language].add_good(solution_time)
930
967
  if solution.outcome.is_slow():
931
968
  summary.add_slow(solution_time)
932
- sumamry_per_language[solution.language].add_slow(solution_time)
969
+ summary_per_language[solution.language].add_slow(solution_time)
933
970
 
934
971
  if summary.slowest_good is None and summary.fastest_slow is None:
935
972
  return
936
973
 
974
+ all_languages = set(summary_per_language)
975
+ all_tl = min(all_tls) if all_tls else None
937
976
  console.print('[status]Timing summary:[/status]')
938
- if summary.slowest_good is not None:
939
- console.print(
940
- f'Slowest [success]OK[/success] solution: {summary.slowest_good} ms'
941
- )
942
- if summary.fastest_slow is not None:
943
- console.print(
944
- f'Fastest [error]slow[/error] solution: {summary.fastest_slow} ms'
977
+
978
+ if len(all_languages) <= 1 or len(all_tls) <= 1:
979
+ summary.print(console, tl=all_tl)
980
+ return
981
+
982
+ # Otherwise, print per language.
983
+ for lang in sorted(all_languages):
984
+ console.print(f'[status]{lang}[/status]')
985
+ summary_per_language[lang].print(
986
+ console, tl=tls_per_language.get(lang) or all_tl
945
987
  )
988
+ console.print()
946
989
 
947
990
 
948
991
  def _length_markup(markup: str) -> int:
@@ -1109,7 +1152,9 @@ async def _print_detailed_run_report(
1109
1152
  console.print()
1110
1153
 
1111
1154
  if timing:
1112
- await _print_timing(console, result.skeleton, structured_evaluations)
1155
+ await _print_timing(
1156
+ console, result.skeleton, structured_evaluations, verification=verification
1157
+ )
1113
1158
  return ok
1114
1159
 
1115
1160
 
@@ -1193,7 +1238,9 @@ async def print_run_report(
1193
1238
  ok = ok and cur_ok
1194
1239
  console.print()
1195
1240
 
1196
- await _print_timing(console, result.skeleton, structured_evaluations)
1241
+ await _print_timing(
1242
+ console, result.skeleton, structured_evaluations, verification=verification
1243
+ )
1197
1244
 
1198
1245
  return ok
1199
1246
 
@@ -15,6 +15,7 @@ from rbx.box.statements.builders import (
15
15
  StatementBuilderContext,
16
16
  StatementBuilderProblem,
17
17
  StatementCodeLanguage,
18
+ StatementSample,
18
19
  prepare_assets,
19
20
  )
20
21
  from rbx.box.statements.schema import (
@@ -263,7 +264,9 @@ def build_statement_bytes(
263
264
  item=StatementBuilderProblem(
264
265
  package=pkg,
265
266
  statement=statement,
266
- samples=get_samples() if use_samples else [],
267
+ samples=StatementSample.from_testcases(
268
+ get_samples() if use_samples else []
269
+ ),
267
270
  short_name=short_name,
268
271
  ),
269
272
  verbose=False,
@@ -7,8 +7,9 @@ from abc import ABC, abstractmethod
7
7
  from typing import Any, Dict, List, Optional, Tuple
8
8
 
9
9
  import typer
10
+ from pydantic import BaseModel
10
11
 
11
- from rbx import console
12
+ from rbx import console, utils
12
13
  from rbx.box.schema import Package, Primitive, Testcase
13
14
  from rbx.box.statements.latex import (
14
15
  MAX_PDFLATEX_RUNS,
@@ -64,7 +65,25 @@ class StatementBuilderItem(ABC):
64
65
  pass
65
66
 
66
67
 
67
- class StatementSample(Testcase):
68
+ class StatementSample(BaseModel):
69
+ inputPath: pathlib.Path
70
+ outputPath: pathlib.Path
71
+ hasOutput: bool = True
72
+
73
+ @staticmethod
74
+ def from_testcase(testcase: Testcase) -> 'StatementSample':
75
+ return StatementSample(
76
+ inputPath=testcase.inputPath,
77
+ outputPath=testcase.outputPath or utils.get_empty_sentinel_path(),
78
+ hasOutput=testcase.outputPath is not None,
79
+ )
80
+
81
+ @staticmethod
82
+ def from_testcases(testcases: List[Testcase]) -> List['StatementSample']:
83
+ return [StatementSample.from_testcase(testcase) for testcase in testcases]
84
+
85
+
86
+ class ExplainedStatementSample(StatementSample):
68
87
  explanation: Optional[str] = None
69
88
 
70
89
 
@@ -72,7 +91,7 @@ class StatementSample(Testcase):
72
91
  class StatementBuilderProblem(StatementBuilderItem):
73
92
  package: Package
74
93
  statement: Statement
75
- samples: List[Testcase] = dataclasses.field(default_factory=list)
94
+ samples: List[StatementSample] = dataclasses.field(default_factory=list)
76
95
  short_name: Optional[str] = None
77
96
 
78
97
  # Will only be filled by contests.
@@ -301,8 +320,8 @@ class rbxTeXBuilder(StatementBuilder):
301
320
  problem_kwargs['problem']['blocks'] = blocks
302
321
  if statement_blocks.explanations is not None:
303
322
  problem_kwargs['problem']['samples'] = [
304
- StatementSample(
305
- **typing.cast(Testcase, sample).model_dump(),
323
+ ExplainedStatementSample(
324
+ **typing.cast(StatementSample, sample).model_dump(),
306
325
  explanation=statement_blocks.explanations.get(i),
307
326
  )
308
327
  for i, sample in enumerate(problem_kwargs['problem']['samples'])
rbx/box/validators.py CHANGED
@@ -273,6 +273,11 @@ def print_validation_report(infos: List[TestcaseValidationInfo]):
273
273
  if _is_hit_bound_good(v) and k != 'samples'
274
274
  }
275
275
 
276
+ all_groups = set(info.group for info in infos)
277
+ if len(all_groups) == 1 and 'samples' in all_groups:
278
+ # If there's only the samples group, do not check for hit bounds.
279
+ hit_bounds_per_group = {}
280
+
276
281
  if not hit_bounds_per_group:
277
282
  console.console.print('[info]No validation issues found.[/info]')
278
283
  return
rbx/utils.py CHANGED
@@ -1,5 +1,6 @@
1
1
  import contextlib
2
2
  import fcntl
3
+ import functools
3
4
  import json
4
5
  import os
5
6
  import pathlib
@@ -98,6 +99,13 @@ def save_ruyaml(path: pathlib.Path, yml: ruyaml.YAML, data: ruyaml.Any):
98
99
  yml.dump(data, f)
99
100
 
100
101
 
102
+ @functools.cache
103
+ def get_empty_sentinel_path() -> pathlib.Path:
104
+ path = get_app_path() / '.empty'
105
+ path.write_text('')
106
+ return path
107
+
108
+
101
109
  @contextlib.contextmanager
102
110
  def no_progress(status: Optional[rich.status.Status]):
103
111
  if status:
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: rbx.cp
3
- Version: 0.5.32
3
+ Version: 0.5.34
4
4
  Summary:
5
5
  Author: Roberto Sales
6
6
  Requires-Python: >=3.9,<4.0
@@ -9,6 +9,7 @@ Classifier: Programming Language :: Python :: 3.9
9
9
  Classifier: Programming Language :: Python :: 3.10
10
10
  Classifier: Programming Language :: Python :: 3.11
11
11
  Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
12
13
  Requires-Dist: chardet (>=5.2.0,<6.0.0)
13
14
  Requires-Dist: fastapi (>=0.115.8,<0.116.0)
14
15
  Requires-Dist: filelock (>=3.14.0,<4.0.0)
@@ -5,11 +5,11 @@ rbx/box/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  rbx/box/builder.py,sha256=eynVPyRdpYtSNmr8MP7-8jspNH74lj-DclwtiIcJrvM,3280
6
6
  rbx/box/cd.py,sha256=9a_SOnzoJBXxxffp4Wbf3UKXIwKuN3Hvj7K6SocALwE,1194
7
7
  rbx/box/checkers.py,sha256=VpgDzevOK7hrffG2zJGxquNiu-a9Fl3wquLn7xadcK0,6285
8
- rbx/box/code.py,sha256=AeR6yn_Z1euT1cRNniOPYuAYJSCf8TfhTW80AWLG9tE,13419
8
+ rbx/box/code.py,sha256=UFy7jOeTvxtIu9pdVUDv2-D6IW-beJGPC3uCanIKZh0,13412
9
9
  rbx/box/compile.py,sha256=OJLthDQ921w9vyoE6Gk1Df54i5RwtRJ2YG-8XEfefcs,2489
10
10
  rbx/box/conftest.py,sha256=sEmciXSeDC-wmrZ1JSxbsUenKNP_VWW32mrCun2pY3I,1070
11
11
  rbx/box/contest/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
- rbx/box/contest/build_contest_statements.py,sha256=OvKTE2O1UchiBRPzbU94KdIn0whT00VUbyPzUDlJRJg,11290
12
+ rbx/box/contest/build_contest_statements.py,sha256=FjkO-TaT9YqkWySyQEaa69_ZwwyrsNvEBT5hE4qSFgk,11375
13
13
  rbx/box/contest/contest_package.py,sha256=OaUbpBtkhkgOPzJ1ccI_Vq4FMSaJvZm3gMOKfVY8oy4,3032
14
14
  rbx/box/contest/contest_utils.py,sha256=TDE7I6YQJlu4dQd68wzOp019bNgqiT0RlM-LMQMjL9w,301
15
15
  rbx/box/contest/main.py,sha256=fFYeZn8KTLt9j-OFFkcBeQWw8RsTLUauFV6drM2hT48,7404
@@ -23,8 +23,8 @@ rbx/box/extensions.py,sha256=Von8kIeXvNFTkGlMRMTvL2HIHPwlkuiMswr-ydbGV1w,519
23
23
  rbx/box/formatting.py,sha256=3phFRHzqVXj4Ok1yDhCq6Clbw6KlqwJNpMhs--oTWFI,405
24
24
  rbx/box/generators.py,sha256=XJsWXNjtQXUDX2huAUsl-q7OWFyIPc42CyS557jLYxk,20594
25
25
  rbx/box/generators_test.py,sha256=BqWf-A0u0ifZJZlvrMuOHOHQPfMox2Jy6540GmnTnkc,1753
26
- rbx/box/main.py,sha256=qSHoXBsG7nW9cXmnOm9afnGavIOZqvknu691YFACTxQ,23765
27
- rbx/box/package.py,sha256=SSckCXo7Zh412_qjYhSNwConjhR0Sk8911qGJU34Hac,11851
26
+ rbx/box/main.py,sha256=9G21yVefrVLwM9NERozTe-w2xeEZROD2tDL82Gpc-AE,23722
27
+ rbx/box/package.py,sha256=Z_voytvhDknhRKiLf1UsomvdRxlDxdXANNbUzL1HcD8,12042
28
28
  rbx/box/packaging/boca/extension.py,sha256=hQhcbocNfW2ESv5RalS1wf6uvOoOfOnR_gHvbXUbSzY,852
29
29
  rbx/box/packaging/boca/packager.py,sha256=FOhSRg5K5Y4qNB0WyTR3DKgrpObf9I0JbyGpJHOtxpo,10673
30
30
  rbx/box/packaging/contest_main.py,sha256=Hbxh7geNqrePs5tWhPgdg5W2qhaW5yoreK_VP0Sm19k,2727
@@ -41,12 +41,12 @@ rbx/box/retries.py,sha256=z7cIh1QmLVUsTr3Attt_28dbwNg6KWTwpulcWCFwMPo,4667
41
41
  rbx/box/sanitizers/warning_stack.py,sha256=RI97_GJgdjTKIXY_r0EKp5h0qQQSDSdNDh5K7zINrqs,2861
42
42
  rbx/box/schema.py,sha256=iu6S2A2d_7SAQNFd34galQHxFAI2CQrIgXnSBlKgBCk,14307
43
43
  rbx/box/setter_config.py,sha256=ZM7_G2tbaixaFr0NvRaXkowwfxSWF2Gb4XHBsr2Prpc,4279
44
- rbx/box/solutions.py,sha256=A-VVxjTrQ2OuBk_2WynoK0kS5BtsEjkRWzBcx92N6Mk,42266
44
+ rbx/box/solutions.py,sha256=oSlKeublgwSeaz_qt79d9OQqKuK6MINxa4kkiavutZo,43974
45
45
  rbx/box/solutions_test.py,sha256=Cx7Goon_0sz_PaUcD8qa8gmjgzOVub6VHss3CB0GaA0,1524
46
46
  rbx/box/state.py,sha256=yTpjfASpnSXkRB3JiDNvCg5b9JNnNxuYT4uMcbdr59s,109
47
47
  rbx/box/statements/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
48
- rbx/box/statements/build_statements.py,sha256=upsMT-cAnSvbmKgtijdFc0OxPcyeBxRG92hY6dN-ZOk,11920
49
- rbx/box/statements/builders.py,sha256=W3VkmtjfzrT5MkIVXgfR9fM-OWK007ihm5hfzvp9cfc,10474
48
+ rbx/box/statements/build_statements.py,sha256=GyCI_aiQpWSqz_ihDq5XCYXVOiWFRLXqhOesSRlmU1E,12019
49
+ rbx/box/statements/builders.py,sha256=pKevMe3GwiXN_k0L2l155sY1rSLneSs0DLJ5T7WhxKQ,11152
50
50
  rbx/box/statements/joiners.py,sha256=ZbxomnMjEFT8yf5WSWUB4tBa3DL3AhjGEuh8uqHyDdg,2837
51
51
  rbx/box/statements/latex.py,sha256=LkcHwXjMFxbw--Gj9T1VkFKQFsXhY9dN7xZHpZycNW8,1346
52
52
  rbx/box/statements/latex_jinja.py,sha256=7WBfn1h8DpqCAmSE6Av64HfURMnJ2AO4QX1CD72sz5E,7096
@@ -61,7 +61,7 @@ rbx/box/ui/captured_log.py,sha256=ptICDPViVnz-_2NfrcB0SSBXNW5L74zI-vAZNN7kSok,11
61
61
  rbx/box/ui/css/app.tcss,sha256=apd5PkPEvl5jK3kE2qrxPyVED1VnvSsj08QQwzUPwEA,786
62
62
  rbx/box/ui/main.py,sha256=b0rHcBF42W4AOCv7WhtiGf_rUnY0yxpqO5oj3wfR4R4,984
63
63
  rbx/box/ui/run.py,sha256=wMEXrEFdQvMHz2hRKAFIithTnTtaL0kNQZu0jKmb8jI,7060
64
- rbx/box/validators.py,sha256=SNOzOk2lJdxnU3e6TFPaqaBwz-qisYLR44vbiH1F4Hc,8806
64
+ rbx/box/validators.py,sha256=f6595hPsNSCxp8Q9IiGwWTrSNOBiJlQw63NVo0v1cRQ,9023
65
65
  rbx/box/validators_test.py,sha256=hriR6rD32Ouu64eKYYTPLZVvqMxXj7Q2h1l_JAefL7U,344
66
66
  rbx/checker.py,sha256=pj1jO3my48ru-qugbER5onccANCjoR0-PaFe3H3VGEY,4118
67
67
  rbx/clone.py,sha256=wpHyED0_7ST7LD3vj7HjXhzqEzlwh6dRQvKQVDYhGeU,6744
@@ -164,9 +164,9 @@ rbx/testdata/box1/wa.sol.cpp,sha256=qsHmvtLJOFI_sdvUT6ITqk7FJYqhrRTCmEIRdy4gSGE,
164
164
  rbx/testdata/caching/executable.py,sha256=WKRHNf_fprFJd1Fq1ubmQtR3mZzTYVNwKPLWuZ4HrWg,10
165
165
  rbx/testdata/compatible,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
166
166
  rbx/testing_utils.py,sha256=ZZLKMUHlZ4HwsuNY50jqSBJ9HhpnFdba7opjDsvXE1U,2084
167
- rbx/utils.py,sha256=q1ZmfVCD6rdKVVZFBqwVetldSgGAbIh_KLHseBTUSiQ,4511
168
- rbx_cp-0.5.32.dist-info/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
169
- rbx_cp-0.5.32.dist-info/METADATA,sha256=5pM2-oIeGiW-fSBJ7fO6XoYzokFQPixO6Lun8ifiwMA,3212
170
- rbx_cp-0.5.32.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
171
- rbx_cp-0.5.32.dist-info/entry_points.txt,sha256=qBTLBOeifT1F00LWaEewRRE_jQPgvH7BUdJfZ-dYsFU,57
172
- rbx_cp-0.5.32.dist-info/RECORD,,
167
+ rbx/utils.py,sha256=AITbkWpWtSp-x3Xept_aObfj_jPL7XL0JJoz5-F9Fp8,4671
168
+ rbx_cp-0.5.34.dist-info/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
169
+ rbx_cp-0.5.34.dist-info/METADATA,sha256=iLu8QtrjNShKSOL-kXyqAys7nYVTJDSKH6NY9EyZpJE,3263
170
+ rbx_cp-0.5.34.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
171
+ rbx_cp-0.5.34.dist-info/entry_points.txt,sha256=qBTLBOeifT1F00LWaEewRRE_jQPgvH7BUdJfZ-dYsFU,57
172
+ rbx_cp-0.5.34.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.9.0
2
+ Generator: poetry-core 2.1.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any