diff --git a/src/algorithms/searching/__init__.py b/src/algorithms/searching/__init__.py new file mode 100644 index 0000000..3b66995 --- /dev/null +++ b/src/algorithms/searching/__init__.py @@ -0,0 +1,40 @@ +""" +Searching algorithms (lightweight top-level namespace). + +Provides lazy accessors for submodules to avoid circular import issues. +""" + +from importlib import import_module +from typing import Any + +__all__ = [ + "advanced_search", + "binary_search", + "linear_search", + "quickselect", +] + + +def __getattr__(name: str) -> Any: + """ + Lazily import and expose searching submodules as attributes: + - advanced_search + - binary_search + - linear_search + - quickselect + """ + if name in __all__: + import sys + + canonical = f"interview_workbook.algorithms.searching.{name}" + # If already imported under canonical path, reuse it to avoid reload/circulars + if canonical in sys.modules: + return sys.modules[canonical] + # Try canonical import first + try: + return import_module(canonical) + except ModuleNotFoundError: + # Fallback to local under src/ if present + local = f"{__name__}.{name}" + return import_module(local) + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") diff --git a/src/algorithms/searching/advanced_search.py b/src/algorithms/searching/advanced_search.py new file mode 100644 index 0000000..7a751de --- /dev/null +++ b/src/algorithms/searching/advanced_search.py @@ -0,0 +1,3 @@ +# Proxy module to expose interview_workbook searching under src.algorithms.searching.* +# This enables tests importing src.algorithms.searching.* to resolve correctly. +from interview_workbook.algorithms.searching.advanced_search import * # noqa: F401,F403 diff --git a/src/algorithms/searching/binary_search.py b/src/algorithms/searching/binary_search.py new file mode 100644 index 0000000..a0a039b --- /dev/null +++ b/src/algorithms/searching/binary_search.py @@ -0,0 +1,3 @@ +# Proxy module to expose interview_workbook searching under src.algorithms.searching.* +# This enables tests importing src.algorithms.searching.* to resolve correctly. +from interview_workbook.algorithms.searching.binary_search import * # noqa: F401,F403 diff --git a/src/algorithms/searching/linear_search.py b/src/algorithms/searching/linear_search.py new file mode 100644 index 0000000..703f984 --- /dev/null +++ b/src/algorithms/searching/linear_search.py @@ -0,0 +1,3 @@ +# Proxy module to expose interview_workbook searching under src.algorithms.searching.* +# This enables tests importing src.algorithms.searching.* to resolve correctly. +from interview_workbook.algorithms.searching.linear_search import * # noqa: F401,F403 diff --git a/src/algorithms/searching/quickselect.py b/src/algorithms/searching/quickselect.py new file mode 100644 index 0000000..5c5c722 --- /dev/null +++ b/src/algorithms/searching/quickselect.py @@ -0,0 +1,3 @@ +# Proxy module to expose interview_workbook searching under src.algorithms.searching.* +# This enables tests importing src.algorithms.searching.* to resolve correctly. +from interview_workbook.algorithms.searching.quickselect import * # noqa: F401,F403 diff --git a/src/algorithms/sorting/__init__.py b/src/algorithms/sorting/__init__.py index 8c76a31..8cf8346 100644 --- a/src/algorithms/sorting/__init__.py +++ b/src/algorithms/sorting/__init__.py @@ -9,8 +9,11 @@ __all__ = [ "bubble_sort", + "heap_sort", "insertion_sort", + "merge_sort", "non_comparison_sorts", + "quick_sort", "selection_sort", ] @@ -19,9 +22,12 @@ def __getattr__(name: str) -> Any: """ Lazily import and expose sorting submodules as attributes: - bubble_sort + - heap_sort - insertion_sort - - selection_sort + - merge_sort - non_comparison_sorts + - quick_sort + - selection_sort """ if name in __all__: import sys diff --git a/src/algorithms/sorting/heap_sort.py b/src/algorithms/sorting/heap_sort.py new file mode 100644 index 0000000..f33066e --- /dev/null +++ b/src/algorithms/sorting/heap_sort.py @@ -0,0 +1,3 @@ +# Proxy module to expose interview_workbook sorting under src.algorithms.sorting.* +# This enables tests importing src.algorithms.sorting.* to resolve correctly. +from interview_workbook.algorithms.sorting.heap_sort import * # noqa: F401,F403 diff --git a/src/algorithms/sorting/merge_sort.py b/src/algorithms/sorting/merge_sort.py new file mode 100644 index 0000000..e50b421 --- /dev/null +++ b/src/algorithms/sorting/merge_sort.py @@ -0,0 +1,3 @@ +# Proxy module to expose interview_workbook sorting under src.algorithms.sorting.* +# This enables tests importing src.algorithms.sorting.* to resolve correctly. +from interview_workbook.algorithms.sorting.merge_sort import * # noqa: F401,F403 diff --git a/src/algorithms/sorting/quick_sort.py b/src/algorithms/sorting/quick_sort.py new file mode 100644 index 0000000..3dc4c7e --- /dev/null +++ b/src/algorithms/sorting/quick_sort.py @@ -0,0 +1,3 @@ +# Proxy module to expose interview_workbook sorting under src.algorithms.sorting.* +# This enables tests importing src.algorithms.sorting.* to resolve correctly. +from interview_workbook.algorithms.sorting.quick_sort import * # noqa: F401,F403