Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix minor bug in lean configuration duplication #516

Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Improve implementation
Marinovsky committed Oct 28, 2024
commit 2bc401f04e28abde686efab1d39ea1888fbcb947
4 changes: 2 additions & 2 deletions lean/components/config/lean_config_manager.py
Original file line number Diff line number Diff line change
@@ -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

@@ -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])
10 changes: 10 additions & 0 deletions tests/components/config/test_lean_config_manager.py
Original file line number Diff line number Diff line change
@@ -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()