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

Support shell detection in helper mode #704

Merged
merged 8 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions kart.spec
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ pyi_analysis = Analysis(
'_cffi_backend',
# via a cython module ???
'csv',
'shellingham.posix',
pfw marked this conversation as resolved.
Show resolved Hide resolved
*collect_submodules('kart'),
*collect_submodules('sqlalchemy'),
],
Expand Down
9 changes: 8 additions & 1 deletion kart/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
except ImportError:
shellingham = None

def provide_default_shell():
if os.name == 'posix':
return os.environ['SHELL']
pfw marked this conversation as resolved.
Show resolved Hide resolved
raise NotImplementedError(f'OS {os.name!r} support not available')

class Shells(str, Enum):
bash = "bash"
Expand Down Expand Up @@ -187,7 +191,10 @@ def install(
if complete_var is None:
complete_var = "_{}_COMPLETE".format(prog_name.replace("-", "_").upper())
if shell is None and shellingham is not None:
shell, _ = shellingham.detect_shell()
try:
shell, _ = shellingham.detect_shell()
except shellingham.ShellDetectionFailure:
shell = os.path.basename(provide_default_shell())
if shell == "bash":
installed_path = install_bash(
prog_name=prog_name, complete_var=complete_var, shell=shell
Expand Down
5 changes: 4 additions & 1 deletion kart/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io
import os
import sys
import traceback

import click

Expand Down Expand Up @@ -203,9 +204,11 @@ class struct_semun(ctypes.Union):
)

except Exception as e:
print(os.environ)
pfw marked this conversation as resolved.
Show resolved Hide resolved
print(
f"kart helper: unhandled exception [{e}]"
f"kart helper: unhandled exception"
) # TODO - should ext-run capture/handle this?
traceback.print_exc(file=sys.stdout)
pfw marked this conversation as resolved.
Show resolved Hide resolved
libc.semctl(semid, 0, SETVAL, struct_semun(val=1001))
try:
# send a signal to caller that we are done
Expand Down
2 changes: 2 additions & 0 deletions tests/scripts/e2e-1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ set -x

echo "Using helper mode: ${KART_USE_HELPER:-0}"

kart -vvvv config --install-tab-completion auto

kart init --initial-branch=main .
kart config user.name "Kart E2E Test 1"
kart config user.email "kart-e2e-test-1@email.invalid"
Expand Down