Skip to content

Conversation

@ever3001
Copy link

  • 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 added 3 commits October 11, 2025 17:04
The new command supports selective cleanup with `--cache`, `--logs`,
`--trash`, and `--venvs` flags to remove specific components. Running
`pipx clean` without flags performs a full cleanup, removing all pipx
data and resetting to a fresh installation state.
Configured mypy to recognize pytest library by adding pytest plugin to mypy configuration. This allows mypy to properly type-check pytest fixtures and decorators, eliminating the need for "type: ignore" comments in test files.
@ever3001 ever3001 force-pushed the ever3001/feature/add_clean_option branch from 13bc7cf to f713984 Compare October 11, 2025 15:44
@ever3001
Copy link
Author

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

Copy link
Member

@dukecat0 dukecat0 left a comment

Choose a reason for hiding this comment

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

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

@ever3001
Copy link
Author

ever3001 commented Nov 2, 2025

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

Copy link
Member

@dukecat0 dukecat0 left a comment

Choose a reason for hiding this comment

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

Just a few more comments :D


# Execute all operations and combine exit codes
for operation in cleanup_operations:
result: ExitCode = operation(verbose)
Copy link
Member

Choose a reason for hiding this comment

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

Is ExitCode required by linter?

assert " Path: " in captured.out
assert "Removing pycowsay..." in captured.out
assert "Removing 1 installed package(s)..." in captured.out
assert "All installed packages removed." in captured.out
Copy link
Member

Choose a reason for hiding this comment

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

force: Skip confirmation prompt
"""
print(f"{hazard} {red('WARNING')}: This will remove ALL pipx data!")
print(red("All installed packages will be lost."))
Copy link
Member

Choose a reason for hiding this comment

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

From the perspective of user, I think these messages should be displayed before the y/N prompt?

action="store_true",
help="Skip confirmation prompts (use with caution!)",
)
p.set_defaults(subparser=p)
Copy link
Member

Choose a reason for hiding this comment

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

Is this used anywhere else?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants