-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Fix PowerShell completion for PowerShell 7.4+ using Register-ArgumentCompleter #13413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Added functions to retrieve completion environment variables and the current word under the cursor. - Implemented logic to fetch installed distributions and subcommand options for improved completion. - Introduced a PowerShell completion script to enable modern tab completion for pip commands. - Updated the completion command to load the PowerShell script dynamically. This update improves the user experience by providing more accurate and context-aware command completions.
hey @ichard26 Could you please review the changes in my PR and guide me on what needs to be fixed to make the CI checks pass? I see there are some failures but would appreciate your guidance on the best way to address them. |
The current failure is that the new .ps1 file you've added doesn't get included in the Python package because nothing in the MANIFEST.in file would add it. Given this is 1 file I recommend adding a line which adds it explicitly: include {file path}. |
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
You need to fix the remaining linting errors, you can run linting locally by installing nox and running linting: https://pip.pypa.io/en/stable/development/getting-started/#running-linters, or installing pre-commit and running it directly. |
- Updated the `auto_complete_paths` function to improve path completion logic, ensuring it handles empty directories and filters entries based on the completion type. - Refactored the `get_powershell_script` function to specify return type for better type hinting. - Improved error messaging for missing shell options in the completion command. These changes enhance the user experience by providing more accurate and context-aware command completions.
- Added a placeholder mechanism in the PowerShell completion script to dynamically determine the command name. - Updated the `get_powershell_script` function to read the script in a zipapp-safe manner, improving compatibility. - Enhanced the completion command to replace the placeholder with the actual program name during execution. These changes improve the robustness and usability of the autocompletion feature in PowerShell.
Just so we're all on the same page, I won't have time to review PRs until June 25th at the earliest. More realistically, I'll be OOO until July 6th. It is possible another maintainer will be able to review your PR in the meanwhile, but I consider that unlikely as none of the core team is well-versed in writing shell completions AFAIK. Sorry about that, but this project is entirely volunteer supported so this is unavoidable. Thank you for your interest in improving pip! |
All your remaining pre-commit failures is that you have lines that are too long: https://results.pre-commit.ci/run/github/1446467/1749038869.IP9MHtygQgCpn4JgPdfpwg Here are some examples of reducing line length: logger.warning("PowerShell completion script not found or unreadable, falling back to basic completion")
logger.warning(
"PowerShell completion script not found or unreadable, "
"falling back to basic completion"
) # TypeError can be raised by importlib_resources on older Pythons if package not found
# TypeError can be raised by importlib_resources
# on older Pythons if the package is not found And if you really need to you can turn this check off (but please have justification): logger.warning("PowerShell completion script not found or unreadable, falling back to basic completion") # noqa: E501 You should rerun linting/formatting after making these changes. |
- Added type ignore comment for `locale.LC_MESSAGES` to address potential attribute errors. - Improved formatting and readability in the `get_powershell_script` function by restructuring the return statement. - Updated comments in the PowerShell completion script for clarity and consistency. These changes enhance code maintainability and improve the robustness of the PowerShell autocompletion feature.
- Updated the PowerShell completion script to clarify comments and improve formatting. - Refactored the completion command to streamline script retrieval and enhance readability. - Adjusted the `auto_complete_paths` function to refine path completion logic. - Improved test cases for completion functionality, ensuring accurate results for various command scenarios. These changes enhance the maintainability and user experience of the autocompletion feature in pip.
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
Description
This PR fixes issue #12440 where pip's PowerShell completion breaks in PowerShell 7.4+ due to the use of the deprecated
TabExpansion
function. The solution implements a modern approach usingRegister-ArgumentCompleter
API, which works across all PowerShell versions (5.1+, Core 6.0+, and 7.4+).Changes Made
New PowerShell Completion Script
src/pip/_internal/cli/pip-completion.ps1
Register-ArgumentCompleter
APIPython Backend Updates
completion.py
to load external PowerShell scriptautocompletion.py
with cursor position supportDocumentation
Key Features
Related Issues
Fixes #12440