Skip to content

Commit cb4543b

Browse files
author
Tjaz Erzen
committed
Handle wrong render ranges
1 parent e8134eb commit cb4543b

2 files changed

Lines changed: 85 additions & 5 deletions

File tree

git_utils.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,10 @@ def diff(repo_path: Union[str, os.PathLike], previous_frid: str = None) -> dict:
247247

248248
def _get_commit(repo: Repo, frid: Optional[str]) -> str:
249249
if frid:
250-
return _get_commit_with_frid(repo, frid)
250+
commit_with_frid = _get_commit_with_frid(repo, frid)
251+
if not commit_with_frid:
252+
raise InvalidGitRepositoryError(f"No commit with frid {frid} found.")
253+
return commit_with_frid
251254

252255
base_folder_commit = _get_base_folder_commit(repo)
253256
initial_commit = _get_initial_commit(repo)
@@ -258,10 +261,25 @@ def _get_commit(repo: Repo, frid: Optional[str]) -> str:
258261

259262
def _get_commit_with_frid(repo: Repo, frid: str) -> str:
260263
"""Finds commit with given frid mentioned in the commit message."""
261-
commit = _get_commit_with_message(repo, FUNCTIONAL_REQUIREMENT_FINISHED_COMMIT_MESSAGE.format(frid))
262-
if not commit:
263-
raise InvalidGitRepositoryError(f"No commit with frid {frid} found.")
264-
return commit
264+
return _get_commit_with_message(repo, FUNCTIONAL_REQUIREMENT_FINISHED_COMMIT_MESSAGE.format(frid))
265+
266+
267+
def has_commit_for_frid(repo_path: Union[str, os.PathLike], frid: str) -> bool:
268+
"""
269+
Check if a commit exists for the given FRID in the repository.
270+
271+
Args:
272+
repo_path (str | os.PathLike): Path to the git repository
273+
frid (str): Functional requirement ID to check
274+
275+
Returns:
276+
bool: True if the commit exists, False otherwise
277+
"""
278+
repo = Repo(repo_path)
279+
commit_with_frid = _get_commit_with_frid(repo, frid)
280+
if not commit_with_frid:
281+
return False
282+
return True
265283

266284

267285
def _get_base_folder_commit(repo: Repo) -> str:

module_renderer.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import argparse
22
import os
33

4+
import git_utils
45
import plain_file
56
import plain_modules
67
import plain_spec
@@ -16,6 +17,12 @@
1617
from render_machine.states import States
1718

1819

20+
class MissingPreviousFridCommitsError(Exception):
21+
"""Raised when trying to render from a FRID but previous FRID commits are missing."""
22+
23+
pass
24+
25+
1926
class ModuleRenderer:
2027
def __init__(
2128
self,
@@ -35,6 +42,57 @@ def __init__(
3542
self.run_state = run_state
3643
self.event_bus = event_bus
3744

45+
def _validate_previous_frid_commits_exist(
46+
self, module_name: str, plain_source: dict, render_range: list[str]
47+
) -> None:
48+
"""
49+
Validate that all FRID commits before the render_range exist.
50+
51+
Args:
52+
module_name: Name of the module being rendered
53+
plain_source: The plain source tree
54+
render_range: List of FRIDs to render
55+
56+
Raises:
57+
MissingPreviousFridCommitsError: If any previous FRID commits are missing
58+
"""
59+
# Get all FRIDs from the plain source
60+
all_frids = list(plain_spec.get_frids(plain_source))
61+
first_render_frid = render_range[0]
62+
63+
# Find all FRIDs before the first FRID in render_range
64+
previous_frids = []
65+
for frid in all_frids:
66+
if frid == first_render_frid:
67+
break
68+
previous_frids.append(frid)
69+
70+
# If there are no previous FRIDs, nothing to validate
71+
if not previous_frids:
72+
return
73+
74+
# Check if commits exist for all previous FRIDs
75+
build_folder_path = os.path.join(self.args.build_folder, module_name)
76+
conformance_tests_path = os.path.join(self.args.conformance_tests_folder, module_name)
77+
78+
for prev_frid in previous_frids:
79+
# Check in build folder
80+
if not git_utils.has_commit_for_frid(build_folder_path, prev_frid):
81+
raise MissingPreviousFridCommitsError(
82+
f"Cannot render from FRID {first_render_frid}: "
83+
f"Missing commit for previous FRID {prev_frid} in {build_folder_path}. "
84+
f"Please render all previous FRIDs first."
85+
)
86+
87+
# Check in conformance tests folder (only if conformance tests are enabled)
88+
if self.args.render_conformance_tests:
89+
if not git_utils.has_commit_for_frid(conformance_tests_path, prev_frid):
90+
raise MissingPreviousFridCommitsError(
91+
f"Cannot render from FRID {first_render_frid}: "
92+
f"Missing commit for previous FRID {prev_frid} in {conformance_tests_path}. "
93+
f"Please render all previous FRIDs first."
94+
)
95+
3896
def _build_render_context_for_module(
3997
self,
4098
module_name: str,
@@ -81,6 +139,10 @@ def _render_module(
81139
resources_list = []
82140
plain_spec.collect_linked_resources(plain_source, resources_list, None, True)
83141

142+
# Validate that all previous FRID commits exist before proceeding with render_range
143+
if render_range is not None:
144+
self._validate_previous_frid_commits_exist(module_name, plain_source, render_range)
145+
84146
required_modules = []
85147
has_any_required_module_changed = False
86148
if not self.args.render_machine_graph and required_modules_list:

0 commit comments

Comments
 (0)