Skip to content

Conversation

@matthewfeickert
Copy link
Member

@matthewfeickert matthewfeickert commented Nov 21, 2025

Description

Resolves #2622

Checklist Before Requesting Reviewer

  • Tests are passing
  • "WIP" removed from the title of the pull request
  • Selected an Assignee for the PR to be responsible for the log summary

Before Merging

For the PR Assignees:

  • Summarize commit messages into a comprehensive review of the PR
* Use click v8.x's native shell completions to produce pyhf shell completions for the CLI API.
   - c.f. https://click.palletsprojects.com/en/stable/shell-completion/
* Remove shellcomplete extra.
* Update tests for CLI API.
* Extend documentation for producing shell completions for Bash, Zsh, and Fish shells.

@matthewfeickert matthewfeickert self-assigned this Nov 21, 2025
@matthewfeickert matthewfeickert added fix A bug fix CLI Affects the CLI API labels Nov 21, 2025
@github-project-automation github-project-automation bot moved this to In progress in pyhf v0.8.0 Nov 21, 2025
Copy link
Member Author

@matthewfeickert matthewfeickert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tab completions are currently very slow, so I'm not sure what's happening there.

Some of this is LLM generated to get a working scaffolding, so this shouldn't be merged until things are better understood and the docs are updated significantly.

@codecov
Copy link

codecov bot commented Nov 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.23%. Comparing base (cad5592) to head (ddf9fde).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2639      +/-   ##
==========================================
- Coverage   98.23%   98.23%   -0.01%     
==========================================
  Files          65       65              
  Lines        4190     4188       -2     
  Branches      453      454       +1     
==========================================
- Hits         4116     4114       -2     
  Misses         45       45              
  Partials       29       29              
Flag Coverage Δ
contrib 98.11% <100.00%> (-0.01%) ⬇️
doctest 98.23% <100.00%> (-0.01%) ⬇️
unittests-3.10 96.41% <100.00%> (-0.01%) ⬇️
unittests-3.11 96.41% <100.00%> (-0.01%) ⬇️
unittests-3.12 96.41% <100.00%> (-0.01%) ⬇️
unittests-3.13 96.41% <100.00%> (-0.01%) ⬇️
unittests-3.9 96.46% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@matthewfeickert matthewfeickert added the dependencies Pull requests that update a dependency file label Nov 21, 2025
@kratsg
Copy link
Contributor

kratsg commented Nov 21, 2025

The tab completions are currently very slow, so I'm not sure what's happening there.

From the docs:

Using eval means that the command is invoked and evaluated every time a shell is started, which can delay shell responsiveness. To speed it up, write the generated script to a file, then source that. You can generate the files ahead of time and distribute them with your program to save your users a step.

If you generate it ahead of time, then it won't be as slow, but it's still going to be slow.

@matthewfeickert
Copy link
Member Author

If you generate it ahead of time, then it won't be as slow, but it's still going to be slow.

This is actually how I was testing it, I just wrote the docs to be more trivial. Though I guess we should give people the best shot at having things not be horribly slow, so I should revise this.

@matthewfeickert
Copy link
Member Author

From @henryiii:

Sounds like you need 3.15's lazy imports. 🙂 (Maybe https://github.com/scientific-python/lazy-loader would help in the interim)?

@matthewfeickert matthewfeickert force-pushed the fix/use-click-8-shell-completions branch 2 times, most recently from 63a065d to 0f7d17c Compare November 27, 2025 07:12
@matthewfeickert matthewfeickert marked this pull request as ready for review November 27, 2025 07:12
@matthewfeickert
Copy link
Member Author

@kratsg This is ready for review. My suggestion is that even though we know this is slow for the time being (though would still be good to get your check on this also) that we move forward with it so that we can drop an outdated and deprecated dependency and extra`.

Copilot finished reviewing on behalf of matthewfeickert November 27, 2025 07:14
@matthewfeickert matthewfeickert added the build Changes that affect the build system or external dependencies label Nov 27, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates from the external click_completion library to Click v8.x's native shell completion functionality, simplifying the dependency structure and modernizing the shell completion implementation.

Key changes:

  • Replaced click_completion dependency with Click v8.x native shell completion API
  • Removed the shellcomplete optional dependency extra from pyproject.toml
  • Updated CLI tests to verify the new completion implementation for bash, zsh, and fish shells

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/pyhf/cli/complete.py Migrated from click_completion to Click v8.x native completion API with inline documentation for bash, zsh, and fish shells
tests/test_cli.py Replaced legacy tests with new tests for bash, zsh, and fish completion instructions, plus a test for no-shell invocation
pyproject.toml Removed shellcomplete extra and updated the "all" extra to exclude it

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 20 to 23
Bash:
mkdir -p ~/.completions
_PYHF_COMPLETE=bash_source pyhf > ~/.completions/pyhf-complete.sh
echo ". ~/.completions/pyhf-complete.sh" >> ~/.bashrc
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring instructions don't match the actual command output. The docstring shows:

echo ". ~/.completions/pyhf-complete.sh" >> ~/.bashrc

But the actual command output includes -e flag and \\n:

echo -e "\\n. ~/.completions/pyhf-complete.sh" >> ~/.bashrc

These should be consistent. Either update the docstring to match the output, or simplify the output to match the docstring.

Copilot uses AI. Check for mistakes.
@matthewfeickert matthewfeickert force-pushed the fix/use-click-8-shell-completions branch from 0f7d17c to 65f1163 Compare November 27, 2025 07:22
* Use click v8.x's native shell completions to produce pyhf shell completions
  for the CLI API.
   - c.f. https://click.palletsprojects.com/en/stable/shell-completion/
* Remove shellcomplete extra.
* Update tests for CLI API.
* Extend documentation for producing shell completions for Bash, Zsh, and
  Fish shells.
@matthewfeickert matthewfeickert force-pushed the fix/use-click-8-shell-completions branch from 65f1163 to ddf9fde Compare November 27, 2025 07:23
Copilot finished reviewing on behalf of matthewfeickert November 27, 2025 07:25
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +15 to +33
Supported shells: bash, zsh, fish
To enable completion, run the appropriate command for your shell:
\b
Bash:
mkdir -p ~/.completions
_PYHF_COMPLETE=bash_source pyhf > ~/.completions/pyhf-complete.sh
echo -e "\n. ~/.completions/pyhf-complete.sh" >> ~/.bashrc
\b
Zsh:
mkdir -p ~/.completions
_PYHF_COMPLETE=zsh_source pyhf > ~/.completions/pyhf-complete.zsh
echo -e "\n. ~/.completions/pyhf-complete.zsh" >> ~/.zshrc
\b
Fish:
_PYHF_COMPLETE=fish_source pyhf >> ~/.config/fish/completions/pyhf.fish
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shell completion instructions are duplicated in both the docstring (lines 20-33) and the instructions dictionary (lines 42-55). This creates a maintenance burden where updates must be made in two places. Consider removing the detailed instructions from the docstring and keeping only the high-level description, or generate the help text dynamically from the instructions dictionary.

Suggested change
Supported shells: bash, zsh, fish
To enable completion, run the appropriate command for your shell:
\b
Bash:
mkdir -p ~/.completions
_PYHF_COMPLETE=bash_source pyhf > ~/.completions/pyhf-complete.sh
echo -e "\n. ~/.completions/pyhf-complete.sh" >> ~/.bashrc
\b
Zsh:
mkdir -p ~/.completions
_PYHF_COMPLETE=zsh_source pyhf > ~/.completions/pyhf-complete.zsh
echo -e "\n. ~/.completions/pyhf-complete.zsh" >> ~/.zshrc
\b
Fish:
_PYHF_COMPLETE=fish_source pyhf >> ~/.config/fish/completions/pyhf.fish
Supported shells: bash, zsh, fish.
When run, this command will print instructions for enabling shell completion
for the specified shell.

Copilot uses AI. Check for mistakes.
bold=True,
)
)
click.echo("and then source your shell configuration or restart your shell.")
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing capitalization at the start of the sentence. The sentence should begin with a capital letter for consistency with standard English grammar.

Suggested change
click.echo("and then source your shell configuration or restart your shell.")
click.echo("And then source your shell configuration or restart your shell.")

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Changes that affect the build system or external dependencies CLI Affects the CLI API dependencies Pull requests that update a dependency file fix A bug fix

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

Find alternative to click-completion which is now in maintenance mode

2 participants