I am trying to make flycheck run locally for Python files, but not have flycheck run when working with python files on a remote machine. I have the problem that flycheck slows down saving and it seems to send a second file that sometimes ends up freezing up emacs. I wrote the two functions below but it doesn't seem to work correctly. I want it to disable fly-check if it is a remote file (connected through tramp) or enable flycheck-mode for all other python files. Currently, it just enables flycheck mode for all files.
(when (require 'flycheck nil t)
(setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
(add-hook 'elpy-mode-hook 'jj/flycheck-mode))
(defun jj/flycheck-mode ()
"Don't enable flycheck mode for remote buffers."
(interactive)
(if (file-remote-p default-directory)
(flycheck-mode nil)
(flycheck-mode t)))
Any way to fix this script? Or another approach?