diff --git a/src/hatch/cli/application.py b/src/hatch/cli/application.py index 9c527fece..98a2a0709 100644 --- a/src/hatch/cli/application.py +++ b/src/hatch/cli/application.py @@ -295,13 +295,9 @@ def get_python_manager(self, directory: str | None = None): @cached_property def shell_data(self) -> tuple[str, str]: - import shellingham + from hatch.utils.shells import detect_shell - try: - return shellingham.detect_shell() - except shellingham.ShellDetectionFailure: - path = self.platform.default_shell - return Path(path).stem, path + return detect_shell(self.platform) @cached_property def env_metadata(self) -> EnvironmentMetadata: diff --git a/src/hatch/utils/shells.py b/src/hatch/utils/shells.py index 46ffa3baf..b64c983c7 100644 --- a/src/hatch/utils/shells.py +++ b/src/hatch/utils/shells.py @@ -3,12 +3,24 @@ import sys from typing import TYPE_CHECKING +from hatch.utils.fs import Path + if TYPE_CHECKING: from collections.abc import Callable, Iterable from types import FrameType from hatch.env.plugin.interface import EnvironmentInterface - from hatch.utils.fs import Path + from hatch.utils.platform import Platform + + +def detect_shell(platform: Platform) -> tuple[str, str]: + import shellingham + + try: + return shellingham.detect_shell() + except shellingham.ShellDetectionFailure: + path = platform.default_shell + return Path(path).stem, path class ShellManager: diff --git a/tests/cli/python/conftest.py b/tests/cli/python/conftest.py index c5c6aea7c..af4c66b28 100644 --- a/tests/cli/python/conftest.py +++ b/tests/cli/python/conftest.py @@ -2,10 +2,12 @@ import pytest +from hatch.utils.shells import detect_shell + @pytest.fixture(autouse=True) def default_shells(platform): - return [] if platform.windows else ['sh'] + return [] if platform.windows else [detect_shell(platform)[0]] @pytest.fixture(autouse=True)