Skip to content

Commit 4f3f0a7

Browse files
committed
try fix shell detection
1 parent 8166b44 commit 4f3f0a7

File tree

5 files changed

+26
-5
lines changed

5 files changed

+26
-5
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ jobs:
443443
shell: fish {0}
444444
run: |
445445
poetry run python -c "from shellingham import detect_shell; print(detect_shell())"
446+
echo $SHELL
446447
just test-fish || exit 1
447448
448449
- name: Store coverage files

django_typer/management/commands/shellcompletion.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@
4242
from django.utils.module_loading import import_string
4343
from django.utils.translation import gettext
4444
from django.utils.translation import gettext_lazy as _
45-
from shellingham import ShellDetectionFailure, detect_shell
45+
from shellingham import ShellDetectionFailure
4646
from typer import Argument, Option
4747
from typer.main import get_command as get_typer_command
4848

4949
from django_typer.completers import complete_import_path, these_strings
5050
from django_typer.management import TyperCommand, command, get_command, initialize
5151
from django_typer.types import COMMON_PANEL
52-
from django_typer.utils import get_usage_script, get_win_shell
52+
from django_typer.utils import detect_shell, get_usage_script, get_win_shell
5353

5454
DETECTED_SHELL = None
5555

django_typer/utils.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@
1414
from threading import local
1515
from types import MethodType, ModuleType
1616

17+
from shellingham import ShellDetectionFailure
18+
from shellingham import detect_shell as _detect_shell
19+
1720
from .config import traceback_config
1821

1922
# DO NOT IMPORT ANYTHING FROM TYPER HERE - SEE patch.py
2023

2124
__all__ = [
25+
"detect_shell",
2226
"get_usage_script",
2327
"traceback_config",
2428
"get_current_command",
@@ -29,6 +33,22 @@
2933
]
3034

3135

36+
def detect_shell(max_depth: int = 10) -> t.Tuple[str, str]:
37+
"""
38+
Detect the current shell.
39+
40+
:raises ShellDetectionFailure: If the shell cannot be detected
41+
:return: A tuple of the shell name and the shell command
42+
"""
43+
try:
44+
return _detect_shell(max_depth=max_depth)
45+
except ShellDetectionFailure:
46+
login_shell = os.environ.get("SHELL", "")
47+
if login_shell:
48+
return (os.path.basename(login_shell).lower(), login_shell)
49+
raise
50+
51+
3252
def get_usage_script(script: t.Optional[str] = None) -> t.Union[Path, str]:
3353
"""
3454
Return the script name if it is on the path or the absolute path to the script

tests/shellcompletion/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import subprocess
1414
import platform
1515

16-
from shellingham import detect_shell
16+
from django_typer.utils import detect_shell
1717

1818
from django.test import TestCase, override_settings
1919
from django_typer.management import get_command

tests/shellcompletion/test_shell_resolution.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
from django_typer.management import get_command
88
from django_typer.management.commands.shellcompletion import Command as ShellComplete
9-
from shellingham import detect_shell, ShellDetectionFailure
10-
from django_typer.utils import get_win_shell
9+
from shellingham import ShellDetectionFailure
10+
from django_typer.utils import get_win_shell, detect_shell
1111

1212

1313
def test_detect_shell():

0 commit comments

Comments
 (0)