From e4ca67cead25951c697227b19797131ea2361024 Mon Sep 17 00:00:00 2001 From: Aseem Saxena Date: Thu, 9 Oct 2025 16:42:44 -0700 Subject: [PATCH 1/2] cache results for future calls --- codeflash/code_utils/config_parser.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/codeflash/code_utils/config_parser.py b/codeflash/code_utils/config_parser.py index b3f3495d6..f75541d09 100644 --- a/codeflash/code_utils/config_parser.py +++ b/codeflash/code_utils/config_parser.py @@ -1,11 +1,13 @@ from __future__ import annotations +from functools import cache from pathlib import Path from typing import Any import tomlkit +@cache def find_pyproject_toml(config_file: Path | None = None) -> Path: # Find the pyproject.toml file on the root of the project @@ -31,6 +33,7 @@ def find_pyproject_toml(config_file: Path | None = None) -> Path: raise ValueError(msg) +@cache def find_conftest_files(test_paths: list[Path]) -> list[Path]: list_of_conftest_files = set() for test_path in test_paths: From a95ad4fd61e3c9682e4b319df4b1395447d9ae5f Mon Sep 17 00:00:00 2001 From: Aseem Saxena Date: Thu, 9 Oct 2025 22:25:36 -0700 Subject: [PATCH 2/2] NoneType and List are not hashable --- codeflash/code_utils/config_parser.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/codeflash/code_utils/config_parser.py b/codeflash/code_utils/config_parser.py index f75541d09..2ca462801 100644 --- a/codeflash/code_utils/config_parser.py +++ b/codeflash/code_utils/config_parser.py @@ -1,13 +1,13 @@ from __future__ import annotations -from functools import cache from pathlib import Path from typing import Any import tomlkit +PYPROJECT_TOML_CACHE = {} + -@cache def find_pyproject_toml(config_file: Path | None = None) -> Path: # Find the pyproject.toml file on the root of the project @@ -21,10 +21,15 @@ def find_pyproject_toml(config_file: Path | None = None) -> Path: raise ValueError(msg) return config_file dir_path = Path.cwd() - + cur_path = dir_path + # see if it was encountered before in search + if cur_path in PYPROJECT_TOML_CACHE: + return PYPROJECT_TOML_CACHE[cur_path] + # map current path to closest file while dir_path != dir_path.parent: config_file = dir_path / "pyproject.toml" if config_file.exists(): + PYPROJECT_TOML_CACHE[cur_path] = config_file return config_file # Search for pyproject.toml in the parent directories dir_path = dir_path.parent @@ -33,7 +38,6 @@ def find_pyproject_toml(config_file: Path | None = None) -> Path: raise ValueError(msg) -@cache def find_conftest_files(test_paths: list[Path]) -> list[Path]: list_of_conftest_files = set() for test_path in test_paths: