Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Support Git Branch-Based Caching and Pre-Execution Commands #18526

Open
martinResearch opened this issue Jan 24, 2025 · 2 comments
Labels

Comments

@martinResearch
Copy link

Feature Request

Switching branches during development often causes mypy to invalidate its cache, leading to slow reanalysis. Additionally, branch-specific dependencies may differ, which can result in cache pollution if the environment isn't synchronized after switching branches.

Proposed Solutions

Branch-Specific Caching:

Introduce an option to include the Git branch name in the cache directory path. This would allow switching between branches (e.g., from branch-a to branch-b and back) without losing previously cached data, improving performance and reducing redundant analysis.

Pre-Execution Command:

Add an option to run a custom command before mypy execution. This would enable users to automatically sync dependencies, e.g. using uv pip sync requirements.txt. Running this command before mypy would ensure the environment matches the branch’s requirements, preventing cache corruption due to mismatched dependencies.

Benefits:

  • Faster mypy runs when switching branches.
  • Better isolation of cached data per branch.
  • Reduced risk of cache pollution from dependency mismatches.
  • Improved developer experience with automated environment checks.

Additional Context
If similar functionality exists, guidance on achieving this would be greatly appreciated.

Thank you for considering this feature request.

@martinResearch
Copy link
Author

As an alternative to Branch-Specific Caching maybe a solution would be to use the hash of the orignal py file as part of the cached json file name. We could then have an option to keep only the 5 most recent cached file for each python file for example to prevent an explosion of the cache.

@martinResearch
Copy link
Author

I had a go at implementing fastermypy , a thin wrapper around mypy to implement the functionality described above and it works well :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant