Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion codeflash/api/aiservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,8 @@ def generate_regression_tests( # noqa: D417
response_json["instrumented_perf_tests"],
)
try:
error = response.json()["error"]
response_json = response.json()
error = response_json["error"]
logger.error(f"Error generating tests: {response.status_code} - {error}")
ph("cli-testgen-error-response", {"response_status_code": response.status_code, "error": error})
return None # noqa: TRY300
Expand Down
21 changes: 16 additions & 5 deletions codeflash/code_utils/code_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,18 +300,24 @@ def get_qualified_name(module_name: str, full_qualified_name: str) -> str:


def module_name_from_file_path(file_path: Path, project_root_path: Path, *, traverse_up: bool = False) -> str:
file_path_resolved = _resolved_path(file_path)
project_root_path_resolved = _resolved_path(project_root_path)
try:
relative_path = file_path.resolve().relative_to(project_root_path.resolve())
relative_path = file_path_resolved.relative_to(project_root_path_resolved)
return relative_path.with_suffix("").as_posix().replace("/", ".")
except ValueError:
if traverse_up:
parent = file_path.parent
while parent not in (project_root_path, parent.parent):
# Build the ancestor list once, working upward
ancestors = list(file_path_resolved.parents)
# Stop at the first equal-to project_root_path or filesystem root; match original behavior
for parent in ancestors:
if parent in (project_root_path_resolved, parent.parent):
break
try:
relative_path = file_path.resolve().relative_to(parent.resolve())
relative_path = file_path_resolved.relative_to(parent)
return relative_path.with_suffix("").as_posix().replace("/", ".")
except ValueError:
parent = parent.parent
continue
msg = f"File {file_path} is not within the project root {project_root_path}."
raise ValueError(msg) # noqa: B904

Expand Down Expand Up @@ -489,3 +495,8 @@ def validate_relative_directory_path(path: str) -> tuple[bool, str]:
if error_msg:
return False, error_msg
return True, ""


@lru_cache(maxsize=128)
def _resolved_path(path: Path) -> Path:
return path.resolve()
Loading