Skip to content

Commit

Permalink
Merge pull request #704 from koordinates/helper-support-shell-detection
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoup committed Aug 24, 2022
2 parents 2ca3b0a + 757b5f1 commit 2847b00
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ _When adding new entries to the changelog, please include issue/PR numbers where

- Install tab completion using `kart install tab-completion` instead of `kart config --install-tab-completion`. [#701](https://github.com/koordinates/kart/issues/701)
- "Primary key conflicts" - conflicts caused by reusing a primary key which is already assigned to a feature outside the spatial filter - are renamed to "spatial filter conflicts" for future proofing with other dataset types. Consequently, commit option `--allow-pk-conflicts` is renamed to `--allow-spatial-filter-conflicts`.
- Support shell detection for tab completion installation when running in helper mode. [#704](https://github.com/koordinates/kart/pull/704)
- Bugfix: directing geojson diff output to the console didn't work in a multi-dataset repo, even if only one dataset had changed. [#702](https://github.com/koordinates/kart/issues/702)

## 0.11.5
Expand Down
2 changes: 2 additions & 0 deletions kart.spec
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ pyi_analysis = Analysis(
'_cffi_backend',
# via a cython module ???
'csv',
'shellingham.posix',
'shellingham.nt',
*collect_submodules('kart'),
*collect_submodules('sqlalchemy'),
],
Expand Down
11 changes: 10 additions & 1 deletion kart/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
except ImportError:
shellingham = None

def provide_default_shell():
if os.name == 'posix':
return os.environ.get('SHELL', '')
elif os.name == 'nt':
return os.environ.get('COMSPEC', '')
raise NotImplementedError(f'OS {os.name!r} support not available')

class Shells(str, Enum):
bash = "bash"
Expand Down Expand Up @@ -187,7 +193,10 @@ def install_tab_completion(
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
4 changes: 3 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 @@ -204,8 +205,9 @@ class struct_semun(ctypes.Union):

except Exception as e:
print(
f"kart helper: unhandled exception [{e}]"
f"kart helper: unhandled exception"
) # TODO - should ext-run capture/handle this?
traceback.print_exc(file=sys.stderr)
libc.semctl(semid, 0, SETVAL, struct_semun(val=1001))
try:
# send a signal to caller that we are done
Expand Down
1 change: 1 addition & 0 deletions tests/scripts/e2e-1.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ $SQLITE=(Join-Path $KART_PREFIX 'sqlite3.exe')
New-Item -ItemType Directory -Path "${TMP_PATH}\test"
Push-Location "${TMP_PATH}\test"
try {
Exec { kart -vvvv install tab-completion --shell auto }
Exec { kart init --initial-branch=main . }
Exec { kart -v config --local 'user.name' 'Kart E2E Test 1' }
Exec { kart -v config --local 'user.email' 'kart-e2e-test-1@email.invalid' }
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 install tab-completion --shell 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

0 comments on commit 2847b00

Please sign in to comment.