Skip to content

Commit

Permalink
Fix bug with bash autocompletion for the users who has . in their P…
Browse files Browse the repository at this point in the history
…ATH environment variable (#868)
  • Loading branch information
thoth291 authored Aug 18, 2020
1 parent cff6265 commit efcce5f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
6 changes: 5 additions & 1 deletion hydra/_internal/core_plugins/bash_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ def install(self) -> None:
true
fi
if ! [ -x "$(command -v $helper)" ]; then
EXECUTABLE=($(command -v $helper))
if [ "$HYDRA_COMP_DEBUG" == "1" ]; then
printf "EXECUTABLE_FIRST='${EXECUTABLE[0]}'\\n"
fi
if ! [ -x "${EXECUTABLE[0]}" ]; then
false
fi
Expand Down
1 change: 1 addition & 0 deletions news/868.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug with bash autocompletion for the users who has `.` in their PATH environment variable
25 changes: 25 additions & 0 deletions tests/scripts/test_bash_dot_in_path.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# Navigate to app with minimal configuration
cd tests/test_apps/app_with_cfg/

# Locate python
PYTHON=$(command -v python)

# Setup hydra bash completion
eval "$(python my_app.py -sc install=bash)"

# Setup debugging
export HYDRA_COMP_DEBUG=1
export PATH=$PATH:.

# Do actual test
test=$(COMP_LINE='python my_app.py' hydra_bash_completion |\
grep EXECUTABLE_FIRST |\
awk '{split($0,a,"=");b=substr(a[2],2,length(a[2])-2);print b}')

if [ $test == $PYTHON ]; then
echo TRUE
else
echo FALSE
fi
15 changes: 15 additions & 0 deletions tests/test_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ def create_config_loader() -> ConfigLoaderImpl:
)


@pytest.mark.skipif(sys.platform == "win32", reason="does not run on windows")
class TestDotInPathCompletion:
def test_bash_completion_with_dot_in_path(self) -> None:
process = subprocess.Popen(
"tests/scripts/test_bash_dot_in_path.bash",
shell=False,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout, stderr = process.communicate()
assert stderr == b""
assert stdout == b"TRUE\n"
return


base_completion_list: List[str] = [
"dict.",
"dict_prefix=",
Expand Down

0 comments on commit efcce5f

Please sign in to comment.