Skip to content

Commit d9bf3f8

Browse files
committed
refactor(python): _comp_xfunc_python_modules main command convention
1 parent 5085d6b commit d9bf3f8

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

completions/pydoc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ _comp_cmd_pydoc()
2323
_comp_compgen -- -W 'keywords topics modules'
2424

2525
if ! _comp_looks_like_path "$cur"; then
26-
local python=python
27-
[[ ${1##*/} == *3* ]] && python=python3
28-
_comp_xfunc python modules $python
26+
# Prefer python in the same dir for resolving modules
27+
local pathcmd
28+
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
29+
_comp_xfunc python modules
2930
fi
3031

3132
# Note that we don't do "pydoc modules" as it is known to hang on

completions/python

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,22 @@
22

33
# @since 2.12
44
_comp_xfunc_python_modules()
5+
{
6+
local python=python
7+
[[ ${comp_args[0]##*/} == *3* ]] && python=python3
8+
_comp_cmd_python__modules "$python"
9+
}
10+
11+
# @deprecated 2.12 use `_comp_xfunc_python_modules` instead
12+
_python_modules()
13+
{
14+
_comp_cmd_python__modules "${1:-python}"
15+
}
16+
17+
_comp_cmd_python__modules()
518
{
619
COMPREPLY+=($(compgen -W \
7-
"$("${1:-python}" "${BASH_SOURCE[0]%/*}/../helpers/python" "$cur" \
20+
"$("$1" "${BASH_SOURCE[0]%/*}/../helpers/python" "$cur" \
821
2>/dev/null)" -- "$cur"))
922
}
1023

@@ -15,7 +28,6 @@ _comp_xfunc_python_warning_actions()
1528
${prefix:+-P "$prefix"}
1629
}
1730

18-
_comp_deprecate_func 2.12 _python_modules _comp_xfunc_python_modules
1931
_comp_deprecate_func 2.12 _python_warning_actions \
2032
_comp_xfunc_python_warning_actions
2133

@@ -39,7 +51,7 @@ _comp_cmd_python()
3951
return
4052
;;
4153
-${noargopts}m)
42-
_comp_xfunc_python_modules "$1"
54+
_comp_cmd_python__modules "$1"
4355
return
4456
;;
4557
-${noargopts}Q)

0 commit comments

Comments
 (0)