Skip to content

Redirect Python Bytecode and ruff Caches Out of OneDrive on Windows Hosts #4328

Open

Description

@ptr727

Problem

On a Windows host, OneDrive backs up Documents and Desktop by default. Python writes __pycache__ beside each module it imports. ruff writes .ruff_cache in the project root. Code that runs or is linted from a synced folder therefore turns every run into OneDrive create and delete churn, thousands of sync operations on a busy host.

The global package caches are not part of this. pip, uv, npm, and NuGet already keep theirs under %LOCALAPPDATA% or the profile root, which OneDrive does not sync.

Proposal

Set these user-scope environment variables from the host-setup\windows tooling:

  • PYTHONPYCACHEPREFIX=%USERPROFILE%\.cache\pycache
  • RUFF_CACHE_DIR=%USERPROFILE%\.cache\ruff

Each tool names its redirected cache by the project's absolute path, so separate checkouts and worktrees never share an entry.

State in docs/host-setup.md that a repository checkout belongs outside a synced folder, ideally on a Dev Drive. That is the root fix for checkouts. The variables cover code that has to stay in a synced folder.

What This Leaves Out

  • MYPY_CACHE_DIR. mypy keys its cache by module name rather than by path. Worktrees of one repository then share entries, and agents working in separate worktrees at once keep invalidating each other's cache. Left in-tree, each worktree keeps its own.
  • Linux hosts. No folder is synced by default, and an in-tree cache is deleted with its worktree. A redirect there gains nothing and leaves an entry behind per removed worktree.
  • UV_PROJECT_ENVIRONMENT and COVERAGE_FILE. Each is one path for every project, so concurrent runs collide.

Cost

A removed worktree leaves its entry behind under %USERPROFILE%\.cache\pycache and %USERPROFILE%\.cache\ruff. Deleting either folder at any time is safe, since the tool rebuilds it on the next run. A periodic or age-based cleanup bounds the growth.

Open Questions

  • Which script owns a persistent user environment variable. No host-setup\windows script sets one, and install-tools.ps1 installs tools.
  • Whether host-setup owns the cleanup, as a scheduled task or a menu action.
  • Whether the host gate reports a Windows host lacking the variables.

The gate block in OPERATIONS.md exports a run-scoped RUFF_CACHE_DIR, which overrides the user-scope value for that run. The two do not conflict.

Activity

  1. added
    enhancement
    decision
    on Nov 20, 2026
  2. ptr727 commented on Nov 24, 2026

    @ptr727
    OwnerAuthor

    Question for the maintainer (backlog burndown away run, 2026-11-24, round 1). This issue lists three open questions in its body, and the committed rules settle only one of them. So the away run labels it decision and holds it. It is also Windows-lane work, since setting a user-scope variable is verified on a Windows host.

    1. Which script sets PYTHONPYCACHEPREFIX and RUFF_CACHE_DIR at user scope?

    1. host-setup/windows/install-tools.ps1 (recommended). It already runs on every Windows host the bootstrap sets up, and it owns the Python install whose cache this redirects. Setting the two variables there is idempotent, and no new entry point needs documenting.
    2. A new dedicated host-setup/windows/ script. It keeps install-tools.ps1 to installing tools, at the cost of one more script the bootstrap and docs must name.
    3. upgrade-host.ps1. It reaches existing hosts on their next upgrade, but a freshly stood-up host gets nothing until then.

    2. Does host-setup clean up existing __pycache__ and .ruff_cache folders in synced locations?

    1. No cleanup code, report only (recommended). The standing rule from State That a One-Off Is Detected and Reported, Never Corrected by Code #4210 says a one-off is detected and reported, never corrected by code. The leftover folders are a one-off, so the docs say how to delete them by hand.
    2. A scheduled task or menu action that deletes them. That is correction code for a one-off, which the rule declines.

    3. Does the host gate report a Windows host lacking the variables?

    1. Yes, as a report naming the command that sets them (recommended). It makes a missed setup step visible, the same detect-and-report shape as question 2.
    2. No. The variables stay an optimization the gate does not check.
  3. ptr727 commented on Nov 25, 2026

    @ptr727
    OwnerAuthor

    Answered by the maintainer (decision triage, 2026-11-25): install-tools.ps1 sets and reports, with no cleanup code.

    • host-setup/windows/install-tools.ps1 sets PYTHONPYCACHEPREFIX and RUFF_CACHE_DIR at user scope, idempotently. Its -Report run names a missing variable along with the command that sets it.
    • docs/host-setup.md says to keep checkouts outside synced folders, and that the redirected cache folders are always safe to delete.
    • No cleanup code and no scripts/host_gate.py change. Leftover in-tree cache folders are detected and reported, never corrected by code (GOVERNANCE.md one-off rule, Detect and Report a One-Off, and Let a Rollback Reopen on Promotion #4346).

    This is Windows-lane work, because the change counts as verified only when run on a Windows host. The issue stays open as work.

  4. removed
    decision
    on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions