Repository navigation
Plugin proposal : python-m - #778
thomas-saigre wants to merge 1 commit into
Conversation
PR Summary by QodoAdd python -m module path completion plugin
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo
1. Installed modules never autocomplete
|
|
|
||
| matches+=("$entry") | ||
| [[ "$is_dir" == 1 ]] && dir_matches+=("$entry") | ||
| done < <(find "$dir" -mindepth 1 -maxdepth 1 \( -name "${base}*.py" -o -name "${base}*" -type d \) ! -name "__pycache__" -print0 2>/dev/null) |
There was a problem hiding this comment.
1. Installed modules never autocomplete 🐞 Bug ≡ Correctness
_omb_python_m_complete derives one relative directory from the typed module name and enumerates candidates exclusively with find "$dir". When an executable module comes from PYTHONPATH, site-packages, or another interpreter search path rather than the current tree, it is absent from the results.
Agent Prompt
## Issue description
The module completer searches only beneath the current working directory, so modules available through the interpreter's other search paths cannot be completed.
## Fix Focus Areas
- plugins/python-m/python-m.plugin.sh[8-32]
## Recommended Fix
Obtain the active interpreter's module search roots and enumerate matching modules or packages across all of them, preserving dotted nested-package completion and deduplicating candidates.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| else | ||
| COMPREPLY=( $(compgen -f -- "$cur") ) | ||
| fi |
There was a problem hiding this comment.
2. Spaces corrupt python file completion 🐞 Bug ≡ Correctness
The non-module branch assigns the unquoted output of compgen -f through command substitution, which applies word splitting and pathname expansion before populating COMPREPLY. When a script or directory name contains whitespace or glob characters, ordinary completion after python returns split or expanded candidates instead of the actual path.
Agent Prompt
## Issue description
Ordinary Python file completion word-splits and expands the output from `compgen`, corrupting paths containing spaces or glob characters.
## Fix Focus Areas
- plugins/python-m/python-m.plugin.sh[40-42]
## Recommended Fix
Populate `COMPREPLY` without an unquoted command substitution, such as by reading `compgen` output line-by-line into the array, and enable filename-aware completion quoting where appropriate.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| prev="${COMP_WORDS[COMP_CWORD-1]}" | ||
|
|
||
| if [[ "$prev" == "-m" ]]; then | ||
| path="${cur//.//}" |
There was a problem hiding this comment.
3. Script arguments trigger module lookup 🐞 Bug ≡ Correctness
_omb_python_m_complete enters module mode whenever the immediately preceding word equals -m, without checking whether Python has already selected a script or command to execute. For `python script.py -m <TAB>, where -m` belongs to the script's arguments, the plugin searches for Python modules instead of completing the script's argument.
Agent Prompt
## Issue description
The completer treats every preceding `-m` as a Python interpreter option, including occurrences passed to an already selected script.
## Fix Focus Areas
- plugins/python-m/python-m.plugin.sh[5-12]
## Recommended Fix
Inspect the command words before the current position and enter module completion only when `-m` occurs in the interpreter option prefix, before any script, command, module, or option terminator selects what Python will execute.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| complete -F _omb_python_m_complete python3 | ||
| complete -F _omb_python_m_complete python |
There was a problem hiding this comment.
4. Django users lose module completion 🐞 Bug ≡ Correctness
The plugin registers an exclusive completion function for python, while the existing Django completion independently registers its own exclusive function for the same command. Oh My Bash loads plugins before configured completions, so enabling both causes the later Django registration to replace this plugin and makes its python -m behavior unavailable.
Agent Prompt
## Issue description
The new exclusive Python completion registration is overwritten by configured completion modules such as Django, disabling module completion for users who enable both features.
## Fix Focus Areas
- plugins/python-m/python-m.plugin.sh[44-45]
- oh-my-bash.sh[130-137]
- completions/django.completion.sh[44-72]
## Recommended Fix
Integrate module-name completion without competing exclusive registrations, preserving or delegating to the existing Python completion handler for all other contexts and ensuring registration occurs after configured completion modules are loaded.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
|
What is the difference from completions-core/python.bash:87-90@scop/bash-completion? We should probably include it in scop/bash-completion. |
I never heard of bash-completion, but my proposition seems indeed to do what it does, maybe in a less consistent way, as I manually check for sub-packages, and do not use |
|
I checked the behavior of |
The purpose of this plugin is to allow auto completion when running python module with
python3 -m .... Cf the readme file for more details.