Skip to content

Instantly share code, notes, and snippets.

@slykar
Created July 9, 2024 17:35
Show Gist options
  • Save slykar/d48c864c76af112b373d68d82ccb1000 to your computer and use it in GitHub Desktop.
Save slykar/d48c864c76af112b373d68d82ccb1000 to your computer and use it in GitHub Desktop.
Faster PyCharm mypy plugin with daemon dmypy
#!/usr/bin/env python3
import argparse
import os
import subprocess
import sys
STATUS_FILE = os.path.join(os.path.dirname(__file__), ".dmypy.json")
def virtualenv_path():
script_dir = os.path.dirname(os.path.abspath(__file__))
return os.path.join(script_dir, ".venv")
def main():
venv_path = virtualenv_path()
mypy_bin = os.path.join(venv_path, "bin", "mypy")
dmypy_bin = os.path.join(venv_path, "bin", "dmypy")
parser = argparse.ArgumentParser(description="Wrapper for dmypy and mypy")
parser.add_argument("-V", action="store_true", help="Responds with mypy version", default=False)
parser.add_argument("--follow-imports", type=str, help="Ignored")
parser.add_argument("--show-column-numbers", action="store_true", help="Ignored", default=False)
parsed_args, unknown_args = parser.parse_known_args()
if parsed_args.V:
# The PyCharm plugin uses `-V` to test the existence of mypy binary
command = [mypy_bin, "-V"]
else:
# All other calls should be passed to dmypy
command = [
dmypy_bin,
"--status-file",
STATUS_FILE,
"run",
"--",
"--follow-imports",
"skip",
"--show-column-numbers",
] + unknown_args
return subprocess.run(command)
if __name__ == "__main__":
result = main()
sys.exit(result.returncode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment