Skip to content

Commit d696194

Browse files
committed
Revert "Fix and test global completion in zsh (#463)"
This reverts commit cb5fc38.
1 parent 50ee2c6 commit d696194

File tree

4 files changed

+23
-48
lines changed

4 files changed

+23
-48
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ jobs:
2121
run: |
2222
[[ $(uname) == Linux ]] && sudo apt-get install --yes rpm tcsh fish zsh
2323
[[ $(uname) == Darwin ]] && brew install bash tcsh fish
24-
# Some runners have python-argcomplete preinstalled
25-
# as a dependency of pipx, which interferes with the tests.
26-
[[ $(uname) == Darwin ]] && brew uninstall --ignore-dependencies python-argcomplete || true
2724
python -m pip install --quiet --upgrade codecov
2825
- run: make install
2926
- run: make lint

argcomplete/bash_completion.d/_python-argcomplete

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ _python_argcomplete_global() {
138138
req_argv=( "" "${COMP_WORDS[@]:1}" )
139139
__python_argcomplete_expand_tilde_by_ref executable
140140
else
141+
if [[ "$service" != "-default-" ]]; then
142+
# TODO: this may not be sufficient - see https://zsh.sourceforge.io/Doc/Release/Completion-System.html
143+
# May need to call _complete with avoid-completer=_python-argcomplete or something like that
144+
_default
145+
return
146+
fi
141147
executable="${words[1]}"
142148
req_argv=( "${words[@]:1}" )
143149
fi
@@ -202,15 +208,7 @@ _python_argcomplete_global() {
202208
_ARGCOMPLETE_SHELL="zsh" \
203209
_ARGCOMPLETE_SUPPRESS_SPACE=1 \
204210
__python_argcomplete_run "$executable" "${(@)req_argv[1, ${ARGCOMPLETE}-1]}"))
205-
local nosort=()
206-
local nospace=()
207-
if is-at-least 5.8; then
208-
nosort=(-o nosort)
209-
fi
210-
if [[ "${completions-}" =~ ([^\\]): && "${BASH_REMATCH[2]}" =~ [=/:] ]]; then
211-
nospace=(-S '')
212-
fi
213-
_describe "$executable" completions "${nosort[@]}" "${nospace[@]}"
211+
_describe "$executable" completions
214212
else
215213
COMPREPLY=($(IFS="$IFS" \
216214
COMP_LINE="$COMP_LINE" \
@@ -236,9 +234,5 @@ _python_argcomplete_global() {
236234
if [[ -z "${ZSH_VERSION-}" ]]; then
237235
complete -o default -o bashdefault -D -F _python_argcomplete_global
238236
else
239-
autoload is-at-least
240-
# Replace only the default completer (_default).
241-
# There are many other special contexts we don't want to override.
242-
# https://zsh.sourceforge.io/Doc/Release/Completion-System.html
243-
compdef _python_argcomplete_global -default-
237+
compdef _python_argcomplete_global -P '*'
244238
fi

argcomplete/shell_integration.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,7 @@
4242
_ARGCOMPLETE_SHELL="zsh" \
4343
_ARGCOMPLETE_SUPPRESS_SPACE=1 \
4444
__python_argcomplete_run ${script:-${words[1]}}))
45-
local nosort=()
46-
local nospace=()
47-
if is-at-least 5.8; then
48-
nosort=(-o nosort)
49-
fi
50-
if [[ "${completions-}" =~ ([^\\]): && "${match[1]}" =~ [=/:] ]]; then
51-
nospace=(-S '')
52-
fi
53-
_describe "${words[1]}" completions "${nosort[@]}" "${nospace[@]}"
45+
_describe "${words[1]}" completions -o nosort
5446
else
5547
local SUPPRESS_SPACE=0
5648
if compopt +o nospace 2> /dev/null; then
@@ -75,7 +67,6 @@
7567
if [[ -z "${ZSH_VERSION-}" ]]; then
7668
complete %(complete_opts)s -F _python_argcomplete%(function_suffix)s %(executables)s
7769
else
78-
autoload is-at-least
7970
compdef _python_argcomplete%(function_suffix)s %(executables)s
8071
fi
8172
"""

test/test.py

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ def bash_repl(command="bash"):
8181
def zsh_repl(command="zsh"):
8282
sh = _repl_sh(command, ["--no-rcs", "-V"], non_printable_insert="%(!..)")
8383
sh.run_command("autoload compinit; compinit -u")
84-
# Require two tabs to print all options (some tests rely on this).
85-
sh.run_command("setopt BASH_AUTO_LIST")
8684
return sh
8785

8886

@@ -1262,6 +1260,9 @@ def setUp(self):
12621260
path = ":".join([os.path.join(BASE_DIR, "scripts"), TEST_DIR, "$PATH"])
12631261
sh.run_command("export PATH={0}".format(path))
12641262
sh.run_command("export PYTHONPATH={0}".format(BASE_DIR))
1263+
if self.repl_provider == bash_repl:
1264+
# Disable the "python" module provided by bash-completion
1265+
sh.run_command("complete -r python python2 python3")
12651266
output = sh.run_command(self.install_cmd)
12661267
self.assertEqual(output, "")
12671268
# Register a dummy completion with an external argcomplete script
@@ -1316,24 +1317,18 @@ class TestZsh(TestBashZshBase, unittest.TestCase):
13161317
"test_parse_special_characters_dollar",
13171318
"test_comp_point", # FIXME
13181319
"test_completion_environment", # FIXME
1320+
"test_continuation", # FIXME
1321+
"test_wordbreak_chars", # FIXME
13191322
]
13201323

13211324
def repl_provider(self):
13221325
return zsh_repl()
13231326

13241327

1325-
class TestBashZshGlobalBase(TestBashZshBase):
1328+
@unittest.skipIf(BASH_MAJOR_VERSION < 4, "complete -D not supported")
1329+
class TestBashGlobal(TestBash):
13261330
install_cmd = 'eval "$(activate-global-python-argcomplete --dest=-)"'
13271331

1328-
def test_redirection_completion(self):
1329-
with TempDir(prefix="test_dir_py", dir="."):
1330-
self.sh.run_command("cd " + os.getcwd())
1331-
self.sh.run_command("echo failure > ./foo.txt")
1332-
self.sh.run_command("echo success > ./foo.\t")
1333-
with open("foo.txt") as f:
1334-
msg = f.read()
1335-
self.assertEqual(msg, "success\n")
1336-
13371332
def test_python_completion(self):
13381333
self.sh.run_command("cd " + TEST_DIR)
13391334
self.assertEqual(self.sh.run_command("python3 ./prog basic f\t"), "foo\r\n")
@@ -1373,6 +1368,9 @@ def _test_console_script(self, package=False, wheel=False):
13731368
command = "pip install {} --target .".format(test_package)
13741369
if not wheel:
13751370
command += " --no-binary :all:"
1371+
if sys.platform == "darwin":
1372+
# Work around https://stackoverflow.com/questions/24257803
1373+
command += ' --install-option="--prefix="'
13761374
install_output = self.sh.run_command(command)
13771375
self.assertEqual(self.sh.run_command("echo $?"), "0\r\n", install_output)
13781376
command = "test-module"
@@ -1381,32 +1379,27 @@ def _test_console_script(self, package=False, wheel=False):
13811379
command += " a\t"
13821380
self.assertEqual(self.sh.run_command(command), "arg\r\n")
13831381

1382+
@unittest.skipIf(os.uname()[0] == "Darwin", "Skip test that fails on MacOS")
13841383
def test_console_script_module(self):
13851384
"""Test completing a console_script for a module."""
13861385
self._test_console_script()
13871386

1387+
@unittest.skipIf(os.uname()[0] == "Darwin", "Skip test that fails on MacOS")
13881388
def test_console_script_package(self):
13891389
"""Test completing a console_script for a package."""
13901390
self._test_console_script(package=True)
13911391

1392+
@unittest.skipIf(os.uname()[0] == "Darwin", "Skip test that fails on MacOS")
13921393
def test_console_script_module_wheel(self):
13931394
"""Test completing a console_script for a module from a wheel."""
13941395
self._test_console_script(wheel=True)
13951396

1397+
@unittest.skipIf(os.uname()[0] == "Darwin", "Skip test that fails on MacOS")
13961398
def test_console_script_package_wheel(self):
13971399
"""Test completing a console_script for a package from a wheel."""
13981400
self._test_console_script(package=True, wheel=True)
13991401

14001402

1401-
@unittest.skipIf(BASH_MAJOR_VERSION < 4, "complete -D not supported")
1402-
class TestBashGlobal(TestBash, TestBashZshGlobalBase):
1403-
pass
1404-
1405-
1406-
class TestZshGlobal(TestZsh, TestBashZshGlobalBase):
1407-
pass
1408-
1409-
14101403
class Shell:
14111404
def __init__(self, shell):
14121405
self.child = pexpect.spawn(shell, encoding="utf-8")

0 commit comments

Comments
 (0)