Skip to content

gh-300: Add uninstall cleanup mode - #390

Merged
zooba merged 1 commit into
python:mainfrom
Punisheroot:feat/js/add-uninstall-cleanup
Jul 31, 2026
Merged

gh-300: Add uninstall cleanup mode#390
zooba merged 1 commit into
python:mainfrom
Punisheroot:feat/js/add-uninstall-cleanup

Conversation

@Punisheroot

Copy link
Copy Markdown
Contributor

Summary

  • Add py uninstall --cleanup to remove cached and unrecognized content while preserving every recognized runtime.
  • Use the standard confirmation flow, with --yes bypassing the prompt.
  • Reject positional runtime tags for both --cleanup and --purge, and reject combining the two options.

Context

PR #389 updated uninstall --purge to remove unrecognized content safely. This follow-up implements the less-destructive cleanup mode discussed in #300 for cases where cached or broken content should be removed without uninstalling recognized runtimes.

Recognized runtime prefixes are the preservation boundary. Everything else under the configured install and download locations may be removed.

Behavior

py uninstall --cleanup prompts with:

Clean up cached files and unrecognized content? This will preserve recognized runtimes.

If confirmed, the command:

  • preserves every runtime returned by managed-install discovery;
  • removes cached downloads, broken installations, and other unrecognized content;
  • handles the default layout where downloads and recognized runtimes share the same directory;
  • calls update_all_shortcuts after cleanup to remove stale registrations and recreate valid ones.

Passing --yes uses the existing confirmation bypass and does not display or read the prompt.

Because both cleanup modes operate globally, positional runtime tags are rejected rather than ignored. --cleanup and --purge are also mutually exclusive.

Tests

Added coverage for:

  • parsing --cleanup;
  • bypassing the cleanup prompt with --yes;
  • preserving recognized runtimes while removing cached and unrecognized content;
  • handling shared install and download directories;
  • declining the confirmation without modifying any files;
  • rejecting positional tags with --cleanup and --purge;
  • rejecting --cleanup together with --purge;
  • refreshing shortcuts and registrations after cleanup.

Existing purge tests now model the actual post-parser state, where --purge sets cmd.purge and does not remain in the positional cmd.args list.

Validation

Performed on Windows with Python 3.14.6:

  • tests/test_uninstall_command.py tests/test_commands.py: PASS (19 passed);
  • full test suite: 414 passed, 1 failed;
  • git diff --check: PASS.

The full-suite failure is the unrelated tests/test_shellext.py::test_RegReadStr: the local HKCU\Environment\PATH value is REG_SZ, while that environment-specific test expects REG_EXPAND_SZ.

Compatibility and risk

The new cleanup behavior is opt-in and retains the existing confirmation mechanism. Normal targeted uninstall behavior is unchanged.

Cleanup work is proportional to the configured install and download content it visits. Recognized runtime directories are preserved in full, including when downloads share the same root.

Closes #300

@Punisheroot
Punisheroot marked this pull request as ready for review July 31, 2026 15:48
@zooba

zooba commented Jul 31, 2026

Copy link
Copy Markdown
Member

Another great PR, much thanks!

Just so you're aware, I'm away for a couple of weeks from about now, so you may not get immediate responses (if any) on this repo. But do go check out the main CPython repository and see how you can help there!

@zooba
zooba merged commit 0e7ea19 into python:main Jul 31, 2026
4 checks passed
@Punisheroot

Copy link
Copy Markdown
Contributor Author

Thanks, @zooba! If you're heading off on vacation, I hope you have a great time!

I'll definitely try to help by closing as many issues here as I can. I'm also trying to contribute over there, I already have two open PRs, and I'm looking forward to contributing even more!

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.

Improve purge handling of unknown files

2 participants