Skip to content
Closed
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
25 changes: 17 additions & 8 deletions codeflash/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,22 @@ def get_code_block_splitter(file_path: Path) -> str:
return f"# file: {file_path.as_posix()}"


@lru_cache(maxsize=4096)
def _normalize_path_for_comparison_cached(path_str: str) -> str:
"""Normalize a path for cross-platform comparison.

Resolves the path to an absolute path and handles Windows case-insensitivity.
"""
path = Path(path_str)
try:
resolved = str(path.resolve())
except (OSError, RuntimeError):
# If resolve fails (e.g., file doesn't exist), use absolute path
resolved = str(path.absolute())
# Only lowercase on Windows where filesystem is case-insensitive
return resolved.lower() if sys.platform == "win32" else resolved


markdown_pattern = re.compile(r"```python:([^\n]+)\n(.*?)\n```", re.DOTALL)


Expand Down Expand Up @@ -412,19 +428,12 @@ def get_test_type_by_original_file_path(self, file_path: Path) -> TestType | Non
)

@staticmethod
@lru_cache(maxsize=4096)
def _normalize_path_for_comparison(path: Path) -> str:
"""Normalize a path for cross-platform comparison.

Resolves the path to an absolute path and handles Windows case-insensitivity.
"""
try:
resolved = str(path.resolve())
except (OSError, RuntimeError):
# If resolve fails (e.g., file doesn't exist), use absolute path
resolved = str(path.absolute())
# Only lowercase on Windows where filesystem is case-insensitive
return resolved.lower() if sys.platform == "win32" else resolved
return _normalize_path_for_comparison_cached(str(path))

def __iter__(self) -> Iterator[TestFile]:
return iter(self.test_files)
Expand Down
Loading