Skip to content

Commit 590e411

Browse files
committed
Cleanup
1 parent f1812f8 commit 590e411

8 files changed

Lines changed: 51 additions & 36 deletions

File tree

git_utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def init_git_repo(
6464
path_to_repo: Union[str, os.PathLike],
6565
module_name: Optional[str] = None,
6666
render_id: Optional[str] = None,
67-
additional_files: Optional[dict[str, str]] = None,
67+
initial_files: Optional[dict[str, str]] = None,
6868
) -> Repo:
6969
"""
7070
Initializes a new git repository in the given path.
@@ -79,8 +79,8 @@ def init_git_repo(
7979
repo = Repo.init(path_to_repo)
8080
_ensure_git_config(repo)
8181

82-
if additional_files:
83-
file_utils.store_response_files(path_to_repo, additional_files, [])
82+
if initial_files:
83+
file_utils.store_response_files(path_to_repo, initial_files, [])
8484
repo.git.add(".")
8585

8686
repo.git.commit(
@@ -95,12 +95,12 @@ def clone_repo(
9595
new_repo_path: str,
9696
module_name: Optional[str] = None,
9797
render_id: Optional[str] = None,
98-
additional_files: Optional[dict[str, str]] = None,
98+
initial_files: Optional[dict[str, str]] = None,
9999
) -> Repo:
100100
repo = Repo.clone_from(source_repo_path, new_repo_path)
101101

102-
if additional_files:
103-
file_utils.store_response_files(new_repo_path, additional_files, [])
102+
if initial_files:
103+
file_utils.store_response_files(new_repo_path, initial_files, [])
104104
repo.git.add(".")
105105

106106
repo.git.commit(

partial_rendering.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def module_comes_before(
8080
if module.module_name == module2.module_name:
8181
return False
8282

83-
raise Exception(f"Module {module1.module_name} and {module2.module_name} not found in {all_required_modules}")
83+
raise ValueError(f"Module {module1.module_name} and {module2.module_name} not found in {all_required_modules}")
8484

8585

8686
def detect_partial_rendering(plain_module: PlainModule) -> PartialRender | None:

plain_modules.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import json
44
import os
5+
from functools import cached_property
56

67
from git.exc import NoSuchPathError
78

@@ -45,7 +46,7 @@ def __init__(self, filename: str, build_folder: str, conformance_tests_folder: s
4546
for module_name in required_modules_names
4647
]
4748

48-
@property
49+
@cached_property
4950
def all_required_modules(self) -> list[PlainModule]:
5051
all_required_modules = []
5152
for required_module in self.required_modules:
@@ -67,7 +68,7 @@ def module_build_folder(self):
6768
def get_codeplain_folder(self):
6869
return os.path.join(self.module_build_folder, CODEPLAIN_METADATA_FOLDER)
6970

70-
def get_last_rendered_frid(self) -> tuple[str, str | None]:
71+
def get_last_rendered_frid(self) -> tuple[str | None, str | None]:
7172
if len(self.required_modules) == 0:
7273
return git_utils.get_last_finished_frid(self.module_build_folder)
7374

@@ -174,7 +175,7 @@ def save_module_metadata(self, only_hashes: bool = False):
174175
json.dump(module_metadata, f, indent=4)
175176
return
176177

177-
module_metadata[MODULE_FUNCTIONALITIES] = (self._get_module_functional_requirements(),)
178+
module_metadata[MODULE_FUNCTIONALITIES] = self._get_module_functional_requirements()
178179

179180
required_modules_functionalities = {}
180181
for required_module in self.required_modules:
@@ -186,7 +187,7 @@ def save_module_metadata(self, only_hashes: bool = False):
186187
with open(metadata_path, "w", encoding="utf-8") as f:
187188
json.dump(module_metadata, f, indent=4)
188189

189-
def _ensure_module_folders_exist(self, first_render_frid: str, render_conformance_tests: bool) -> tuple[str, str]:
190+
def _ensure_module_folders_exist(self, first_render_frid: str, render_conformance_tests: bool):
190191
"""
191192
Ensure that build and conformance test folders exist for the module.
192193
@@ -286,12 +287,16 @@ def get_module_by_name(self, module_name: str) -> PlainModule:
286287

287288
raise ModuleDoesNotExistError(f"Module {module_name} does not exist")
288289

289-
def get_next_module(self, module_name: str) -> PlainModule | None:
290-
for idx, module in enumerate(self.all_required_modules):
291-
if module.module_name == module_name and idx < len(self.all_required_modules) - 1:
292-
return self.all_required_modules[idx + 1]
290+
def get_next_module(self, module_name: str) -> PlainModule:
291+
all_modules = self.all_required_modules + [self]
292+
for idx, module in enumerate(all_modules):
293+
if module.module_name == module_name and idx < len(all_modules) - 1:
294+
return all_modules[idx + 1]
295+
296+
if module_name == self.module_name:
297+
return self
293298

294-
return self
299+
raise ModuleDoesNotExistError(f"Module {module_name} does not exist")
295300

296301
def get_next_frid(self, frid: str, module_name: str) -> tuple[str, PlainModule]:
297302
module = self.get_module_by_name(module_name)

render_machine/actions/prepare_repositories.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def execute(self, render_context: RenderContext, _previous_action_payload: Any |
3535

3636
else:
3737
module_hashes = render_context.plain_module.get_hashes()
38-
additional_files = {
38+
initial_files = {
3939
render_context.plain_module.module_metadata_path(for_git_repo=True): json.dumps(module_hashes)
4040
}
4141

@@ -50,7 +50,7 @@ def execute(self, render_context: RenderContext, _previous_action_payload: Any |
5050
render_context.build_folder,
5151
render_context.module_name,
5252
render_context.run_state.render_id,
53-
additional_files,
53+
initial_files,
5454
)
5555
else:
5656
if render_context.verbose:
@@ -60,7 +60,7 @@ def execute(self, render_context: RenderContext, _previous_action_payload: Any |
6060
render_context.build_folder,
6161
render_context.module_name,
6262
render_context.run_state.render_id,
63-
additional_files,
63+
initial_files,
6464
)
6565

6666
if render_context.base_folder:
@@ -78,7 +78,7 @@ def execute(self, render_context: RenderContext, _previous_action_payload: Any |
7878
render_context.conformance_tests.get_module_conformance_tests_folder(render_context.module_name),
7979
render_context.module_name,
8080
render_context.run_state.render_id,
81-
additional_files,
81+
initial_files,
8282
)
8383

8484
return self.SUCCESSFUL_OUTCOME, None

render_machine/render_context.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ def create_snapshot(self) -> RenderContextSnapshot:
128128
)
129129

130130
def get_required_modules_functionalities(self):
131-
print(f"Getting required modules functionalities for {self.module_name}...")
132131
required_modules_functionalities = {}
133132
if self.required_modules is not None and len(self.required_modules) > 0:
134133
for required_module in self.required_modules:

tests/test_plain_modules.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,20 +183,17 @@ def test_get_next_module_returns_next_in_sequence(root_module):
183183
assert nxt.module_name == "pr_middle"
184184

185185

186-
def test_get_next_module_returns_self_when_at_last(root_module):
186+
def test_get_next_module_returns_self_when_at_last_required_module(root_module):
187187
"""When the given module is the last required module, ``get_next_module``
188-
falls back to the top-level module itself — callers then progress to the
189-
root's first FRID."""
188+
returns the top-level module — callers then progress to the root's first FRID."""
190189
nxt = root_module.get_next_module("pr_middle")
191190
assert nxt is root_module
192191

193192

194-
def test_get_next_module_returns_self_when_module_not_found(root_module):
195-
"""Unknown module names no longer raise — they return the top-level
196-
module. This is a pre-existing behaviour that callers rely on when the
197-
tree has been fully traversed."""
198-
nxt = root_module.get_next_module("unknown")
199-
assert nxt is root_module
193+
def test_get_next_module_raises_when_module_not_found(root_module):
194+
"""Unknown module names raise ``ModuleDoesNotExistError``."""
195+
with pytest.raises(ModuleDoesNotExistError, match="unknown"):
196+
root_module.get_next_module("unknown")
200197

201198

202199
# --------------------------------------------------------------------------

tui/partial_render_tui.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
class PartialRenderTUI(App):
1414
BINDINGS = [
1515
Binding("ctrl+o", "toggle_expand", "Expand/Collapse", show=False),
16-
Binding("ctrl+c", "quit", "Quit", show=False),
16+
Binding("ctrl+c", "copy_selection", "Copy", show=False),
1717
Binding("ctrl+d", "quit", "Quit", show=False),
1818
]
1919

@@ -61,9 +61,8 @@ def on_mount(self) -> None:
6161
info_box.mount(Label("Module fully rendered", classes="rendering-info-row"))
6262
else:
6363
frid = pr.last_render_frid
64-
functionality = pr.last_render_module.plain_source[plain_spec.FUNCTIONAL_REQUIREMENTS][int(frid) - 1][
65-
"markdown"
66-
]
64+
specifications, _ = plain_spec.get_specifications_for_frid(pr.last_render_module.plain_source, frid)
65+
functionality = specifications[plain_spec.FUNCTIONAL_REQUIREMENTS][-1]
6766
label = Label("", classes="rendering-info-row")
6867
info_box.mount(label)
6968
self._register_expandable(label, f"Functionality {frid}:", functionality)
@@ -167,6 +166,21 @@ def action_toggle_expand(self) -> None:
167166

168167
@on(ListView.Selected)
169168
def on_choice_selected(self, event: ListView.Selected) -> None:
170-
key = event.item.id.split("-", 1)[1]
169+
item_id = event.item.id
170+
if not item_id or not item_id.startswith("choice-"):
171+
raise ValueError(f"Invalid item ID: {item_id}")
172+
key = item_id.split("-", 1)[1]
171173
self.selected_choice = self.choices[key]
172174
self.exit(self.selected_choice)
175+
176+
async def action_copy_selection(self) -> None:
177+
"""Handle ctrl+c: copy selected text if any.
178+
179+
- If text is selected -> copy it to clipboard
180+
- If no text is selected -> do nothing
181+
"""
182+
selected_text = self.screen.get_selected_text()
183+
if selected_text:
184+
self.copy_to_clipboard(selected_text)
185+
self.screen.clear_selection()
186+
self.notify("Copied to clipboard", timeout=2)

tui/styles.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,4 +460,4 @@ ListItem.-highlight {
460460
#choice-list {
461461
margin: 0 1;
462462
height: auto;
463-
}
463+
}

0 commit comments

Comments
 (0)