python / python/mypy

Make cache more agnostic to venvs

Open
#18,013 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

I noticed that the mypy cache will mark almost everything as stale if the cache was produced with a venv different from the one running mypy. I think this is due to a full path being placed into cache files & interface_hashes, for files that are stdlib or packages. Then those packages, and everything depending on them, gets invalidated (which ends up being 99% of everything in big projects). I think it would be cool if the cache were more agnostic to this, for two reasons:

  1. when testing locally, I occasionally use a second venv with maybe 1 or 2 different packages to test out changes (maybe a package upgraded or added types). Ideally only those packages and their descendants would be invalidated.
  2. when trying out remote caches, the CI venv will be "different" (existing at a different path), but the lockfile will be exactly the same. Ideally nothing would be invalidated.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how mypy writes and compares cache files and interface_hashes, especially where full paths from virtual environments are recorded. Reproduce the invalidation with two venv paths and compare the cache behavior. Done means equivalent environments with different paths avoid broad invalidation while changed packages and their descendants still become stale.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.