Skip to content

Commit

Permalink
Improve implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Marinovsky committed Oct 28, 2024
1 parent 05b3d5f commit 2bc401f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lean/components/config/lean_config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from os.path import normcase
from os.path import normcase, normpath
from pathlib import Path
from typing import Any, Dict, Optional, List

Expand Down Expand Up @@ -98,7 +98,7 @@ def get_known_lean_config_paths(self) -> List[Path]:
:return: a list of paths to Lean config files that were used in the past
"""
lean_config_paths = self._cache_storage.get("known-lean-config-paths", [])
lean_config_paths = [Path(normcase(p)) for p in lean_config_paths if Path(p).is_file()]
lean_config_paths = [Path(normpath(normcase(p))) for p in lean_config_paths if Path(p).is_file()]
lean_config_paths = list(set(lean_config_paths))

self._cache_storage.set("known-lean-config-paths", [str(p) for p in lean_config_paths])
Expand Down
10 changes: 10 additions & 0 deletions tests/components/config/test_lean_config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ def test_get_known_lean_config_path_with_duplicated_paths() -> None:

assert manager.get_known_lean_config_paths() == [Path.cwd() / "custom-lean.json"]

def test_get_known_lean_config_path_normalizes_path_and_case() -> None:
custom_config_path = Path.cwd() / "//folder//..//custom-lean.json//"
custom_config_path.touch()
custom_config_path.write_text("{}", encoding="utf-8")

manager = _create_lean_config_manager()
manager.set_default_lean_config_path(custom_config_path)

assert manager.get_known_lean_config_paths() == [Path(os.path.normcase(Path.cwd() / "/custom-lean.json"))]

def test_get_cli_root_directory_returns_path_to_directory_containing_config_file() -> None:
create_fake_lean_cli_directory()

Expand Down

0 comments on commit 2bc401f

Please sign in to comment.