rbx.cp 0.5.52__py3-none-any.whl → 0.5.53__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.
@@ -0,0 +1,18 @@
1
+ import pathlib
2
+
3
+ import mkdocs_gen_files
4
+
5
+ from rbx.box.contest.schema import Contest
6
+ from rbx.box.environment import Environment
7
+ from rbx.box.package import Package
8
+ from rbx.box.presets.lock_schema import PresetLock
9
+ from rbx.box.presets.schema import Preset
10
+ from rbx.box.statements.schema import Statement
11
+ from rbx.utils import dump_schema_str
12
+
13
+ models = [Package, Environment, Contest, Preset, PresetLock, Statement]
14
+
15
+ for model in models:
16
+ path = pathlib.Path('schemas') / f'{model.__name__}.json'
17
+ with mkdocs_gen_files.open(str(path), 'w') as f:
18
+ f.write(dump_schema_str(model))
@@ -250,6 +250,24 @@ def _get_statement_blocks(statement: Statement) -> StatementBlocks:
250
250
  )
251
251
 
252
252
 
253
+ def _get_explanations(explanations: Dict[int, str]) -> str:
254
+ entries = []
255
+ for i in sorted(explanations):
256
+ explanation = explanations[i]
257
+ entries.append(f'\\textbf{{Explanation for example {i + 1}}}\n\n{explanation}')
258
+ return '\n\n'.join(entries)
259
+
260
+
261
+ def _get_notes_with_explanations(blocks: StatementBlocks) -> Optional[str]:
262
+ notes = blocks.blocks.get('notes')
263
+ explanations = blocks.explanations
264
+ if notes is None and not explanations:
265
+ return None
266
+ if notes is None:
267
+ return _get_explanations(blocks.explanations)
268
+ return notes + '\n\n' + _get_explanations(blocks.explanations)
269
+
270
+
253
271
  def _upload_statement_resources(problem: api.Problem, statement: Statement):
254
272
  assets = get_relative_assets(statement.path, statement.assets)
255
273
  for asset, relative_asset in assets:
@@ -293,7 +311,7 @@ def _upload_statement(problem: api.Problem):
293
311
  input=blocks.blocks.get('input'),
294
312
  output=blocks.blocks.get('output'),
295
313
  interaction=blocks.blocks.get('interaction'),
296
- notes=blocks.blocks.get('notes'),
314
+ notes=_get_notes_with_explanations(blocks),
297
315
  )
298
316
  problem.save_statement(
299
317
  lang=code_to_langs([language])[0], problem_statement=polygon_statement
@@ -311,8 +329,8 @@ async def upload_problem(name: str):
311
329
  name = _normalize_problem_name(name)
312
330
  problem = _find_or_create_problem(name)
313
331
  _update_problem_info(problem)
314
- _update_checker(problem)
315
332
  _update_rbx_header(problem)
333
+ _update_checker(problem)
316
334
 
317
335
  if (
318
336
  pkg.type == TaskType.COMMUNICATION
rbx/utils.py CHANGED
@@ -57,21 +57,32 @@ def get_app_path() -> pathlib.Path:
57
57
  return pathlib.Path(app_dir)
58
58
 
59
59
 
60
- def ensure_schema(model: Type[BaseModel]) -> pathlib.Path:
61
- path = get_app_path() / 'schemas' / f'{model.__name__}.json'
60
+ def dump_schema_str(model: Type[BaseModel]) -> str:
61
+ return json.dumps(model.model_json_schema(), indent=4)
62
+
63
+
64
+ def dump_schema(model: Type[BaseModel], path: pathlib.Path):
62
65
  path.parent.mkdir(parents=True, exist_ok=True)
63
- schema = json.dumps(model.model_json_schema(), indent=4)
66
+ schema = dump_schema_str(model)
64
67
  path.write_text(schema)
68
+
69
+
70
+ def ensure_schema(model: Type[BaseModel]) -> pathlib.Path:
71
+ path = get_app_path() / 'schemas' / f'{model.__name__}.json'
72
+ dump_schema(model, path)
65
73
  return path.resolve()
66
74
 
67
75
 
68
76
  def model_json(model: BaseModel) -> str:
69
- ensure_schema(model.__class__)
70
77
  return model.model_dump_json(indent=4, exclude_unset=True, exclude_none=True)
71
78
 
72
79
 
80
+ def uploaded_schema_path(model: Type[BaseModel]) -> str:
81
+ return f'https://rsalesc.github.io/rbx/schemas/{model.__name__}.json'
82
+
83
+
73
84
  def model_to_yaml(model: BaseModel) -> str:
74
- path = ensure_schema(model.__class__)
85
+ path = uploaded_schema_path(model.__class__)
75
86
  return f'# yaml-language-server: $schema={path}\n\n' + yaml.dump(
76
87
  model.model_dump(mode='json', exclude_unset=True, exclude_none=True),
77
88
  sort_keys=False,
@@ -80,7 +91,6 @@ def model_to_yaml(model: BaseModel) -> str:
80
91
 
81
92
 
82
93
  def model_from_yaml(model: Type[T], s: str) -> T:
83
- ensure_schema(model)
84
94
  return model(**yaml.safe_load(s))
85
95
 
86
96
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: rbx.cp
3
- Version: 0.5.52
3
+ Version: 0.5.53
4
4
  Summary:
5
5
  Author: Roberto Sales
6
6
  Requires-Python: >=3.9,<4.0
@@ -19,6 +19,7 @@ rbx/box/contest/statements.py,sha256=Or8gFb6P_oViGdeiVgepXsvd_W84mA7LRaVmiAXWWSg
19
19
  rbx/box/creation.py,sha256=Evz7K6JoarD-4JJQsZsgoxU9FgCF9Z7-LfuroG4Cqls,2444
20
20
  rbx/box/deferred.py,sha256=II3X9e87JCOZtmspnHh-n4PFqh-FsH_oc0XJHZ9ZYVQ,691
21
21
  rbx/box/download.py,sha256=DxAiAk4lDYWEz1C9UTvZzHTq6hgm4fxGezApm2IkCTM,2601
22
+ rbx/box/dump_schemas.py,sha256=3j5t47_vJmXj0BCczxDX6ByOcsfolGEDNCBXlPpk86w,593
22
23
  rbx/box/environment.py,sha256=fZnNQCdpG3xzKne0FY7gkuaopy6fdYvVFAXeHmC1ZOo,11498
23
24
  rbx/box/extensions.py,sha256=Von8kIeXvNFTkGlMRMTvL2HIHPwlkuiMswr-ydbGV1w,519
24
25
  rbx/box/formatting.py,sha256=3phFRHzqVXj4Ok1yDhCq6Clbw6KlqwJNpMhs--oTWFI,405
@@ -39,7 +40,7 @@ rbx/box/packaging/packager.py,sha256=da2haC1L9cG30myneMrRIAdGubtid0Xmy38BHKPCZZ4
39
40
  rbx/box/packaging/polygon/packager.py,sha256=GfZ-Dc2TDKkb3QNnfOy8yxldho2L401Ao06oWg--Gcs,11714
40
41
  rbx/box/packaging/polygon/polygon_api.py,sha256=mPKEqiwANJ1nr-JhOgzGMaDhnbljsAgzzPHW6kkf7R4,41016
41
42
  rbx/box/packaging/polygon/test.py,sha256=bgEju5PwudgyfwxXJagm8fM6CJVlWM6l_-2q1V-oKaQ,3069
42
- rbx/box/packaging/polygon/upload.py,sha256=2WyEXlfprLUDbq-9AMB5hXOQVvvmsT1-stO60MHrEo0,11182
43
+ rbx/box/packaging/polygon/upload.py,sha256=woaqf2vcWmvCyBXtAesBUOaMcVUns3hkuzXqzcgAjyo,11826
43
44
  rbx/box/packaging/polygon/xml_schema.py,sha256=ZgcLyvxggMUccbTNdzflue5G-FTN2_ZmOGGF7FD0Y5A,2851
44
45
  rbx/box/presets/__init__.py,sha256=BwmjBw8wF8yiZFjCYBjMk-HGMZaRwhlfszbWAj3B0vw,18689
45
46
  rbx/box/presets/fetch.py,sha256=F-BCOlvEBEyDqtOhiDuGPn4EDtA4Bwm-fqHJ7zZGlW8,1975
@@ -191,9 +192,9 @@ rbx/test.py,sha256=tZyTrXDK8MLR-1TyCRxiOiNz-PhlXVpshfUGphakkT4,11830
191
192
  rbx/testcase.py,sha256=yKOq3CAJZ1YTmInvnoIs0u1iJnRj_X85XiWbLI-p9d8,1951
192
193
  rbx/testcase_rendering.py,sha256=nfmv6dSEqd4aR3TsaODwkKGK6AXty_DDKtWf_ejiQpI,2084
193
194
  rbx/testing_utils.py,sha256=x_PqD8Zd2PkN91NxVHUnSTs044-1WK5KKtttKQBXpFs,2083
194
- rbx/utils.py,sha256=6e1eXRzNE-52D0UVtqclePxqR4Haiqt8qWCrSVjnGuE,4585
195
- rbx_cp-0.5.52.dist-info/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
196
- rbx_cp-0.5.52.dist-info/METADATA,sha256=zA9fGYWC651-X-bxyI87ll66EM9GqMSn7FF28UIcAkE,3348
197
- rbx_cp-0.5.52.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
198
- rbx_cp-0.5.52.dist-info/entry_points.txt,sha256=qBTLBOeifT1F00LWaEewRRE_jQPgvH7BUdJfZ-dYsFU,57
199
- rbx_cp-0.5.52.dist-info/RECORD,,
195
+ rbx/utils.py,sha256=SfR844_i0ebRDMkmS_w1YdZiWPc6h2RGADygewlWRbA,4845
196
+ rbx_cp-0.5.53.dist-info/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
197
+ rbx_cp-0.5.53.dist-info/METADATA,sha256=Gy6mjUs1yQKV0576ZRyBp5g3mjvxbU2L4t2xFf1u39s,3348
198
+ rbx_cp-0.5.53.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
199
+ rbx_cp-0.5.53.dist-info/entry_points.txt,sha256=qBTLBOeifT1F00LWaEewRRE_jQPgvH7BUdJfZ-dYsFU,57
200
+ rbx_cp-0.5.53.dist-info/RECORD,,