codeplain 0.4.1.dev51__py3-none-any.whl → 0.4.2.dev53__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: codeplain
3
- Version: 0.4.1.dev51
3
+ Version: 0.4.2.dev53
4
4
  Summary: Transform plain language specifications into working code
5
5
  License-File: LICENSE
6
6
  Classifier: Environment :: Console
@@ -25,7 +25,7 @@ Requires-Dist: black==26.10.1; extra == 'dev'
25
25
  Requires-Dist: flake8==7.4.1; extra == 'dev'
26
26
  Requires-Dist: isort==9.0.2; extra == 'dev'
27
27
  Requires-Dist: mypy==2.4.0; extra == 'dev'
28
- Requires-Dist: pytest==9.1.1; extra == 'dev'
28
+ Requires-Dist: pytest==9.2.0; extra == 'dev'
29
29
  Description-Content-Type: text/markdown
30
30
 
31
31
  # *codeplain renderer
@@ -15,14 +15,14 @@ path_resolution.py,sha256=0tMqU0a1g4DYhTOp7QjLVSEkv_cgasb4NI1mK809dUM,2233
15
15
  plain2code.py,sha256=HYhUaZK37kMUHRX2LnuJfBDDLgTZWo0t7lOXzu5Yui4,23814
16
16
  plain2code_arguments.py,sha256=3PvJg1otzH5GtQGkaP4LQD6xzsCAFtq2-Ohv82hOz3Q,20515
17
17
  plain2code_console.py,sha256=YGBONkQtwZUkrjxTKhqcBoRzW0EmSfYHPH8P4_FM60I,6040
18
- plain2code_events.py,sha256=rgDF5PDtNr_lEPvJmd1tIQXZrzwgzZW5b-_pykugqe4,1587
18
+ plain2code_events.py,sha256=QnugBgO1baTe4kj2V3LUnkMDzhmksKwPDFuOKfH9g5o,1738
19
19
  plain2code_exceptions.py,sha256=zlszHIhaPWPN4fvYQibMIDM7f1xsW5J8sEWTOosIUGc,2068
20
20
  plain2code_logger.py,sha256=YQ-ENYBHKXROVv6Q52xh7eXrFkj_3Lex__N9zfxlw9Y,5729
21
21
  plain2code_nodes.py,sha256=QCC9RYBBfHycahvYovcN414sRlGL-dqRV3Baeu7KPkw,140
22
22
  plain2code_read_config.py,sha256=D5CxnmTRjddupecWvstcUm0kIJWWzq5-Zmk6sU0wbIg,2235
23
23
  plain2code_state.py,sha256=jIo4knKI99C1xkX1E_OaD3pdS9pczI2h9wofDjifMvE,3348
24
24
  plain2code_telemetry.py,sha256=NO8zw1i3ucM6Z9xQoSCeWqC5Hr-9Oql58YtgEOhBnaQ,4683
25
- plain2code_utils.py,sha256=GKAUA0sGfYsMAge81hJotPLsfB2akCVN70Bpw_0qrH0,1615
25
+ plain2code_utils.py,sha256=luhiWaE0bXPQvjNDj-VYwxcGBq9vhvuqQCL_xgpq814,2093
26
26
  plain_file.py,sha256=50CevjRihjddXbc3WzKKJF_kaVcMHUJ1FH2HJUZawT8,138
27
27
  plain_modules.py,sha256=3xc6tYbWB17YWIG9SfZ_SKYX3hnoC5y_n5RyaN9Lec0,28903
28
28
  plain_spec.py,sha256=AhDbw4GSQ95wC8fkFSPG66MsCu-37Kcz8Skcj66fQhA,1262
@@ -41,7 +41,7 @@ render_machine/agent_tools.py,sha256=Kp2g9GphV7oA9MbOHctKp0UJJJUOgcfCz2SeW9NL6jg
41
41
  render_machine/code_renderer.py,sha256=ZmisVQHVtI1rBN1qdywW-H_hNeUzVELkHUdApGReYjY,3795
42
42
  render_machine/conformance_tests.py,sha256=PNTCnJNd_xNIhpTPPS8vlx8qws3cTgQSTLdADRab2YM,9617
43
43
  render_machine/implementation_code_helpers.py,sha256=Fxm-IInoZjAIZn41_-WXWj7VIYczpW4yH44Gt8CYMAQ,2378
44
- render_machine/render_context.py,sha256=lDhDb7trL8_WeWXznxpNr2SFxAzfk9oo9f_AE7Get10,28690
44
+ render_machine/render_context.py,sha256=-0Ma2DtBQRe4OwsoKi67ERfa_75fexI__vAnUy3_s2g,29133
45
45
  render_machine/render_types.py,sha256=JFROBuTxxDfoSzZpGbucJUYQWa_55HsaOoWIZuZSJ3k,11413
46
46
  render_machine/render_utils.py,sha256=yA3X15E_Lebk_-MxkSz9rM_qy-Pes8EQ9Ye-smkHCDw,9320
47
47
  render_machine/state_machine_config.py,sha256=0pL4PyrZ5F2UumvHLMRfhyh64M4pDvf-9zEs-5OAEU8,27866
@@ -61,7 +61,7 @@ render_machine/actions/prepare_repositories.py,sha256=HyZ1R6E3H5V-G4WDSGfhxl_ars
61
61
  render_machine/actions/prepare_testing_environment.py,sha256=kIsXgV6-jOlqp-04cimPgTQoHPrVIu0zW-H_Jj-jowE,2106
62
62
  render_machine/actions/refactor_code.py,sha256=G2GSJ-xg8ducbcy2wlAKzxyJ-2vAq8rRftRQksjJLZY,2792
63
63
  render_machine/actions/render_conformance_tests.py,sha256=XHJLZrqU-mf2rbMCqHtBTnkcXLIkHJ6Eztnk1X3K7ws,10819
64
- render_machine/actions/render_functional_requirement.py,sha256=DXmwfelfQsq_AY5gudzm9T55wzneb1zP4nG40acmD_s,5304
64
+ render_machine/actions/render_functional_requirement.py,sha256=Kyi2CD7pp4Y7Albys5gFfXW3BGden8W3cvFyr-wHIBU,5660
65
65
  render_machine/actions/run_conformance_tests.py,sha256=hjIkqySveY50Xo3Kdb4zchyqxFdKyuMSHsEH9yLZj9E,3764
66
66
  render_machine/actions/run_unit_tests.py,sha256=j0qsHMLy49I_DX5QLlH0OdPT6bPMc0icmVg2N5MYm9U,2711
67
67
  render_machine/actions/summarize_conformance_tests.py,sha256=4ldc5JAjQXvxEVBshw07ZOboE3SIWb_DjPFKgfyzuZc,1765
@@ -87,6 +87,7 @@ tests/test_fix_unit_tests_action.py,sha256=sNLpg1T586TSPyvhjJcTe-4C9P8iHEkt8zx5z
87
87
  tests/test_fix_unit_tests_conformance_context.py,sha256=G6-_YMhN5BY1sJ7cAx3BDnf_McgFcRpyP0iP6mwJ1eA,13154
88
88
  tests/test_folder_path_resolution.py,sha256=K9v684xkPE0HOAsovg8uDixpZmaIk7ho-Wd3rTjKLF0,6560
89
89
  tests/test_frid_arguments.py,sha256=zIEU2HGgJU4YOY2DXkjO9MmTlIUk4Iu5dfEU9OwKbak,1264
90
+ tests/test_functionality_position.py,sha256=QQdhIqZhRC8-30xKZPyOye6dm8kSkJnja4PB53iZkeE,3540
90
91
  tests/test_functionality_without_scenarios.py,sha256=kFBqu9UQ7JdIJCs6z5Hu0xsv9YskBXhkEKBKcdN0tvI,2832
91
92
  tests/test_git_preflight.py,sha256=6aQqInDzpk03pS-6UfkGQWjErrIXTEdHs5oeq3ZYzTw,3186
92
93
  tests/test_git_utils.py,sha256=hvNzIYNSFXF4nWpN6HIo4h21zLDCUx8ZmrFp1GR_S70,15721
@@ -123,11 +124,11 @@ tui/models.py,sha256=KMjlWubmPD41GA-BjgiqkaV9v7tLJ0fuWKBDPmZj4JA,1493
123
124
  tui/plain2code_tui.py,sha256=b6FOEXt_dcVhpfOrAHvg-Rvn0bSH18moy5zmUaz3NS4,17552
124
125
  tui/plain_module_render_choice_tui.py,sha256=dWmgpEEKlKijTDK-WQ3ks4EgZqICyQ73_BWDTASzEBk,12116
125
126
  tui/spinner.py,sha256=Ro6Gd9Przf-whuHqPRY6HwI0T57yJjyNPbhDbigZKZE,2471
126
- tui/state_handlers.py,sha256=SCAcBXLgGhpVFBLrTL76g7Z507q4fLgSwYkGiwAMLRc,16067
127
+ tui/state_handlers.py,sha256=5FkF13mCLYAOgpYnzR932U3tYxSnMkCu5jybMFEBVe4,16264
127
128
  tui/styles.css,sha256=kiC7Og_2G1E7owoiZgV95-3_dSeQnsNj3qzaY04xkDg,6727
128
129
  tui/widget_helpers.py,sha256=jitm2WHiKj-NVFL-hULxWzckPreRbUTl9OIZLN31-ek,6997
129
- codeplain-0.4.1.dev51.dist-info/METADATA,sha256=Kw3pmQM7IlBMHR62kyIb06EwGATOYzqDDEojYmloErY,7260
130
- codeplain-0.4.1.dev51.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
131
- codeplain-0.4.1.dev51.dist-info/entry_points.txt,sha256=oDZkBqu9WhtZApb_K6ia8-fn9aojwmAsgnKELceX5T4,46
132
- codeplain-0.4.1.dev51.dist-info/licenses/LICENSE,sha256=pCeKgQ1mXE5OmNUuKOfOZh1T1vqkeCUxghE7N8qgnzc,11345
133
- codeplain-0.4.1.dev51.dist-info/RECORD,,
130
+ codeplain-0.4.2.dev53.dist-info/METADATA,sha256=XQI0qh1lTUvm9jIMBkpISPZbLGoRK8M3C58_q5OUD2c,7260
131
+ codeplain-0.4.2.dev53.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
132
+ codeplain-0.4.2.dev53.dist-info/entry_points.txt,sha256=oDZkBqu9WhtZApb_K6ia8-fn9aojwmAsgnKELceX5T4,46
133
+ codeplain-0.4.2.dev53.dist-info/licenses/LICENSE,sha256=pCeKgQ1mXE5OmNUuKOfOZh1T1vqkeCUxghE7N8qgnzc,11345
134
+ codeplain-0.4.2.dev53.dist-info/RECORD,,
plain2code_events.py CHANGED
@@ -22,6 +22,8 @@ class RenderContextSnapshot:
22
22
  unit_tests_running_context: Optional[UnitTestsRunningContext]
23
23
  script_execution_history: Optional[ScriptExecutionHistory]
24
24
  module_name: str
25
+ # Where the functionality stands among those of its module, as "3/12". None before one is picked.
26
+ functionality_position: Optional[str] = None
25
27
 
26
28
 
27
29
  @dataclass
plain2code_utils.py CHANGED
@@ -31,6 +31,18 @@ AMBIGUITY_CAUSES = {
31
31
  }
32
32
 
33
33
 
34
+ def functionality_position(frids: list[str], frid: Optional[str]) -> Optional[str]:
35
+ """Where a functionality stands among the functionalities of its module, as "3/12".
36
+
37
+ The count is over every functionality of the module, not over a render range, so the number
38
+ says where the render is in the specification whatever part of it was asked for.
39
+ """
40
+ if frid is None or frid not in frids:
41
+ return None
42
+
43
+ return f"{frids.index(frid) + 1}/{len(frids)}"
44
+
45
+
34
46
  def qualified_frid(module_name: Optional[str], frid: Optional[str]) -> Optional[str]:
35
47
  """A functionality named as `<module>:<func-id>`.
36
48
 
@@ -19,6 +19,21 @@ class RenderFunctionalRequirement(BaseAction):
19
19
  FUNCTIONAL_REQUIREMENT_TOO_COMPLEX_OUTCOME = "functional_requirement_too_complex"
20
20
  ITERATION_LIMIT_EXCEEDED_OUTCOME = "frid_iteration_limit_exceeded"
21
21
 
22
+ @staticmethod
23
+ def functionality_heading(render_context) -> str:
24
+ """The block logged when a functionality starts: its module, its ID, and where it stands."""
25
+ msg = "-------------------------------------\n"
26
+ msg += f"Module: {render_context.module_name}\n"
27
+ msg += f"Rendering functionality {render_context.frid_context.frid}"
28
+ position = render_context.current_functionality_position()
29
+ if position:
30
+ msg += f" ({position})"
31
+ if render_context.frid_context.functional_requirement_render_attempts > 1:
32
+ msg += f", attempt number {render_context.frid_context.functional_requirement_render_attempts}/{MAX_CODE_GENERATION_RETRIES}"
33
+ msg += f":\n{render_context.frid_context.functional_requirement_text}\n"
34
+ msg += "-------------------------------------"
35
+ return msg
36
+
22
37
  def execute(self, render_context: RenderContext, _previous_action_payload: Any | None):
23
38
  if render_context.frid_context.functional_requirement_render_attempts >= MAX_CODE_GENERATION_RETRIES:
24
39
  # A render attempt is only restarted once its unit tests used up every fix round.
@@ -49,14 +64,7 @@ class RenderFunctionalRequirement(BaseAction):
49
64
  )
50
65
  _, memory_files_content = MemoryManager.fetch_memory_files(render_context.memory_manager.memory_folder)
51
66
 
52
- msg = "-------------------------------------\n"
53
- msg += f"Module: {render_context.module_name}\n"
54
- msg += f"Rendering functionality {render_context.frid_context.frid}"
55
- if render_context.frid_context.functional_requirement_render_attempts > 1:
56
- msg += f", attempt number {render_context.frid_context.functional_requirement_render_attempts}/{MAX_CODE_GENERATION_RETRIES}"
57
- msg += f":\n{render_context.frid_context.functional_requirement_text}\n"
58
- msg += "-------------------------------------"
59
- console.info(msg)
67
+ console.info(self.functionality_heading(render_context))
60
68
 
61
69
  try:
62
70
  render_utils.print_inputs(render_context, existing_files_content, "Files sent as input to code generation:")
@@ -10,7 +10,7 @@ from event_bus import EventBus
10
10
  from plain2code_console import RETRY_COLOR, console
11
11
  from plain2code_events import RenderContextSnapshot
12
12
  from plain2code_state import RunState
13
- from plain2code_utils import qualified_frid
13
+ from plain2code_utils import functionality_position, qualified_frid
14
14
  from plain_modules import PlainModule
15
15
  from render_machine import triggers
16
16
  from render_machine.conformance_tests import CONFORMANCE_TESTS_DEFINITION_FILE_NAME, ConformanceTests
@@ -122,6 +122,13 @@ class RenderContext:
122
122
  self.last_error_message = error_message
123
123
  self.machine.dispatch(triggers.HANDLE_ERROR)
124
124
 
125
+ def current_functionality_position(self) -> Optional[str]:
126
+ """Where the functionality being implemented stands among those of its module, as "3/12"."""
127
+ return functionality_position(
128
+ list(plain_spec.get_frids(self.plain_source_tree)),
129
+ self.frid_context.frid if self.frid_context else None,
130
+ )
131
+
125
132
  def create_snapshot(self) -> RenderContextSnapshot:
126
133
  return RenderContextSnapshot(
127
134
  frid_context=deepcopy(self.frid_context) if self.frid_context else None,
@@ -133,6 +140,7 @@ class RenderContext:
133
140
  ),
134
141
  script_execution_history=deepcopy(self.script_execution_history),
135
142
  module_name=self.module_name,
143
+ functionality_position=self.current_functionality_position(),
136
144
  )
137
145
 
138
146
  def get_required_modules_functionalities(self):
@@ -0,0 +1,90 @@
1
+ """The TUI names the functionality being implemented and where it stands in its module.
2
+
3
+ The func-id says which functionality it is. It does not say how far the module has come, which the
4
+ number before the renderer took func-ids used to say.
5
+ """
6
+
7
+ from types import SimpleNamespace
8
+ from unittest.mock import MagicMock, patch
9
+
10
+ import pytest
11
+
12
+ import file_utils # noqa: F401 # imported before plain_modules, which it imports back from
13
+ from plain2code_events import RenderContextSnapshot
14
+ from plain2code_utils import functionality_position
15
+ from render_machine.actions.render_functional_requirement import RenderFunctionalRequirement
16
+ from tui.state_handlers import FridReadyHandler
17
+
18
+ FRIDS = ["add-login-button", "add-logout-button", "remember-the-session"]
19
+
20
+
21
+ class TestFunctionalityPosition:
22
+ def test_the_first_functionality(self):
23
+ assert functionality_position(FRIDS, "add-login-button") == "1/3"
24
+
25
+ def test_the_last_functionality(self):
26
+ assert functionality_position(FRIDS, "remember-the-session") == "3/3"
27
+
28
+ @pytest.mark.parametrize("frid", [None, "no-such-functionality"], ids=["none", "unknown"])
29
+ def test_nothing_to_place(self, frid):
30
+ assert functionality_position(FRIDS, frid) is None
31
+
32
+ def test_a_module_with_one_functionality(self):
33
+ assert functionality_position(["only-one"], "only-one") == "1/1"
34
+
35
+
36
+ def _snapshot(position):
37
+ return RenderContextSnapshot(
38
+ frid_context=SimpleNamespace(frid="add-login-button", functional_requirement_text="Add a login button."),
39
+ conformance_tests_running_context=None,
40
+ unit_tests_running_context=None,
41
+ script_execution_history=None,
42
+ module_name="",
43
+ functionality_position=position,
44
+ )
45
+
46
+
47
+ def _functionality_line(position):
48
+ handler = FridReadyHandler(MagicMock(), unittests_script=None, conformance_tests_script=None)
49
+ with (
50
+ patch("tui.state_handlers.get_frid_progress") as get_progress,
51
+ patch("tui.state_handlers.update_progress_item_status"),
52
+ ):
53
+ handler.handle([], _snapshot(position), [])
54
+ return get_progress.return_value.update_functionality_text.call_args.args[0]
55
+
56
+
57
+ def test_the_tui_line_carries_the_position():
58
+ assert _functionality_line("3/12") == "Functionality add-login-button (3/12): Add a login button."
59
+
60
+
61
+ def test_the_tui_line_without_a_position_reads_as_before():
62
+ assert _functionality_line(None) == "Functionality add-login-button: Add a login button."
63
+
64
+
65
+ def _log_heading(frids, frid, attempts=1):
66
+ """The heading the renderer logs when it starts a functionality."""
67
+ render_context = SimpleNamespace(
68
+ module_name="shop",
69
+ frid_context=SimpleNamespace(
70
+ frid=frid,
71
+ functional_requirement_text="Add a login button.",
72
+ functional_requirement_render_attempts=attempts,
73
+ ),
74
+ current_functionality_position=lambda: functionality_position(frids, frid),
75
+ )
76
+ return RenderFunctionalRequirement.functionality_heading(render_context)
77
+
78
+
79
+ def test_the_log_heading_carries_the_position():
80
+ assert "Rendering functionality add-login-button (1/3):" in _log_heading(FRIDS, "add-login-button")
81
+
82
+
83
+ def test_the_log_heading_keeps_the_attempt_after_the_position():
84
+ heading = _log_heading(FRIDS, "add-login-button", attempts=2)
85
+
86
+ assert "Rendering functionality add-login-button (1/3), attempt number 2/" in heading
87
+
88
+
89
+ def test_the_log_heading_without_a_position_reads_as_before():
90
+ assert "Rendering functionality add-login-button:" in _log_heading([], "add-login-button")
tui/state_handlers.py CHANGED
@@ -62,8 +62,10 @@ class FridReadyHandler(StateHandler):
62
62
  # Update FRID text
63
63
 
64
64
  functionality = qualified_frid(snapshot.module_name, snapshot.frid_context.frid)
65
+ # The position says how far the module has come; the func-id alone does not.
66
+ position = f" ({snapshot.functionality_position})" if snapshot.functionality_position else ""
65
67
  rendering_functionality_text = (
66
- f"{tui_components.FRIDProgress.RENDERING_FUNCTIONALITY_TEXT}{functionality}: "
68
+ f"{tui_components.FRIDProgress.RENDERING_FUNCTIONALITY_TEXT}{functionality}{position}: "
67
69
  f"{snapshot.frid_context.functional_requirement_text}"
68
70
  )
69
71
  get_frid_progress(self.tui).update_functionality_text(rendering_functionality_text)