Skip to content

Commit

Permalink
Fix internal tests invoked from zsh shell (#1513)
Browse files Browse the repository at this point in the history
Co-authored-by: Ofek Lev <ofekmeister@gmail.com>
  • Loading branch information
haxoza and ofek authored May 23, 2024
1 parent 03655c5 commit 0e6c93a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
8 changes: 2 additions & 6 deletions src/hatch/cli/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 13 additions & 1 deletion src/hatch/utils/shells.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion tests/cli/python/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0e6c93a

Please sign in to comment.