Skip to content

fix(clean): keep PDM's installed packages and project plugins - #2237

Merged
tw93 merged 3 commits into
tw93:mainfrom
viniciusdsandrade:fix/2236-keep-pdm-installs
Dec 4, 2026
Merged

tw93 merged 3 commits into
tw93:mainfrom
viniciusdsandrade:fix/2236-keep-pdm-installs

Conversation

@viniciusdsandrade

Copy link
Copy Markdown
Contributor

Summary

Closes #2236

The User app cache row in clean_user_essentials removes each folder under ~/Library/Caches as a whole (lib/clean/user.sh:343-388), and nothing kept ~/Library/Caches/pdm, PDM's cache root on macOS. Two of its folders hold code PDM runs from:

  • packages/: with pdm config install.cache on, PDM installs each wheel once there, and project environments symlink into it by default (install.cache_method). After mo clean, every installed file in those environments pointed at a file that no longer existed. PDM's docs warn that "Manually deleting the caches from disk may break some projects on the system".
  • plugins/: pdm install --plugins installs each project's plugins there, and PDM skips loading them without a message once the folder is gone.

PDM's own pdm cache clear keeps the packages still in use and never touches plugins/. This PR follows the Poetry, renv and pnpm dlx shape (c32c7274):

  • lib/core/base.sh: pdm/packages* and pdm/plugins* join SAFETY_WHITELIST_PATTERNS, so they hold even after a user saves a custom whitelist. Whitelisting a nested path also protects its parent, which takes the whole pdm root out of the generic sweep.
  • lib/clean/dev.sh: clean_dev_python names the rebuildable siblings, the ones pdm cache clear empties (hashes, http, wheels, metadata), in a PDM cache row, as it already does for Poetry's artifacts and cache. The developer tools section runs on every mo clean, so that space is still reclaimed.

What the sweep used to take and nothing cleans now: PDM's small bookkeeping files at the root (use_cache.json, pip.whl, .compat_libs/, self-check/), which pdm cache clear does not clean either.

Safety Review

  • Does this change affect cleanup, uninstall, optimize, installer, remove, analyze delete, update, or install behavior?
    • Yes: mo clean no longer removes ~/Library/Caches/pdm as a whole. It keeps packages/ and plugins/ and cleans hashes/, http/, wheels/ and metadata/ from the developer tools section. Nothing outside the PDM root is swept differently.
  • Does this change affect path validation, protected directories, symlink handling, sudo boundaries, or release/install integrity?
    • Yes: two hard-safety whitelist rows, $HOME/Library/Caches/pdm/packages* and $HOME/Library/Caches/pdm/plugins*.
  • If yes, describe the new boundary or risk change clearly.
    • PDM's cached installations and project plugins are protected from cleanup, including after a custom whitelist replaces the default rows. The only new deletion targets are the four cache folders pdm cache clear empties, which the generic sweep already removed. The Whitelist: N core count that mo clean prints grows by two.

Tests

  • Automated checks (./scripts/check.sh, ./scripts/test.sh via GitHub Actions CI on this PR)
  • Manual verification

tests/clean_dev_caches.bats: PDM installs and project plugins survive the cache sweep while PDM caches are still cleaned, next to the pnpm dlx case it follows. It runs the real clean_user_essentials and clean_dev_python in dry and real mode with a custom whitelist saved, so only the hard-safety list can keep the PDM folders. A cached package and a project plugin must survive both runs, the http and wheels caches must go in the real run and stay in the dry run, and an ordinary-app cache root is the positive control. pip3 and run_with_timeout are stubbed as in the Jupyter and Yarn Berry cases of tests/clean_developer_state.bats, since /usr/bin/pip3 can open the Command Line Tools dialog.

Read against main: without the rows, is_path_whitelisted and should_protect_path hold nothing for the pdm root and the sweep takes it (PACKAGES_LOST); with the rows but without the dev.sh line, nothing cleans the caches (HTTP_KEPT).

Commits:

  • 2fb598ed fix(clean): keep PDM's installed packages and project plugins
  • 88cc0be2 fix(clean): clean the PDM caches that pdm cache clear empties
  • 7f3fdb95 test(clean): cover PDM installs and plugins in the cache sweep

Safety-related changes

  • Protects ~/Library/Caches/pdm/packages and ~/Library/Caches/pdm/plugins against removal, including under a custom whitelist.

The User app cache sweep removes each folder under ~/Library/Caches as
a whole, and nothing kept ~/Library/Caches/pdm, PDM's cache root on
macOS. With install.cache on, PDM installs each wheel once under
packages/ and project environments symlink into it by default, so
after mo clean every installed file in those environments pointed at
a file that no longer existed. plugins/ holds what `pdm install
--plugins` installed for each project, and PDM skips loading them
without a message once the folder is gone. PDM's docs warn that
deleting the cache by hand may break projects, and `pdm cache clear`
keeps the packages still in use and never touches plugins/.

pdm/packages* and pdm/plugins* join the hard-safety whitelist beside
Poetry's virtualenvs, the renv cache and pnpm dlx.

Refs tw93#2236
Whitelisting pdm/packages* and pdm/plugins* also protects their
parent, which takes the whole pdm root out of the generic
~/Library/Caches sweep and its rebuildable caches with it. Name those
in clean_dev_python, as Poetry's artifacts and cache already are:
hashes, http, wheels and metadata, the folders `pdm cache clear`
empties.

Refs tw93#2236
A new clean_dev_caches case runs the real clean_user_essentials and
clean_dev_python in dry and real mode with a custom whitelist saved,
so only the hard-safety list can keep the PDM folders. A cached
package and a project plugin must survive both runs, the http and
wheels caches must go in the real run and stay in the dry run, and an
ordinary cache root is the positive control. Without the whitelist
rows the sweep takes the pdm root (PACKAGES_LOST), and without the
named caches nothing cleans them (HTTP_KEPT).

Refs tw93#2236
@tw93
tw93 merged commit 423ccae into tw93:main Dec 4, 2026
12 checks passed
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.

[BUG] mo clean removes ~/Library/Caches/pdm, which holds the packages PDM environments symlink into and project plugins

2 participants