pipx icon indicating copy to clipboard operation
pipx copied to clipboard

Feature: Add `pipx clean` command

Open ever3001 opened this issue 2 months ago • 2 comments

  • [X] I have added a news fragment under changelog.d/ (if the patch affects the end users)

Summary of changes

This PR adds a new pipx clean command that allows users to remove pipx data directories. The command provides flexible cleanup options:

Key features

  • Selective cleanup: Clean specific components using --cache, --logs, --trash, or --venvs flags
  • Full cleanup: Remove all pipx data when no flags are specified (resets to fresh installation state)
  • Safety confirmation: Requires user confirmation before cleanup (can be bypassed with --force)

This PR solves issues #1606 and #1681.

Test plan

Local tests

# Test manual cleanup
pipx install pycowsay
pipx clean --force
pipx list  # Verify pycowsay is still installed

# Test selective cleanup
pipx install pycowsay
pipx clean --cache --force
pipx clean --logs --force
pipx clean --trash --force
pipx clean --venvs --force
pipx list  # Verify pycowsay is still installed

# Execute unit tests
nox -s tests -- tests/test_clean.py

Unit tests

  • Added unit tests in tests/test_clean.py to cover various scenarios of the pipx clean command, including:
    • Cleaning individual components (cache, logs, trash, venvs)
    • Full cleanup
    • Error handling during cleanup

Github Actions CI

I run the workflow tests in my fork to ensure all tests pass in CI.

Link to workflow run: tests #5

ever3001 avatar Oct 11 '25 15:10 ever3001

Hi maintainers, just checking in to see if there’s any update on this PR. Please let me know if I missed something or if any changes are needed

ever3001 avatar Oct 26 '25 15:10 ever3001

For the test, could you change the style of it so it is consistent with our other existing tests?

Yeah, sure I will adapt them

ever3001 avatar Nov 02 '25 16:11 ever3001