I am using flycheck with some python linters (python-flake8 and python-mypy) and I would like to modify the directory from which these linters are run by flycheck.

My directory structure is as follows:


And I would like to run the linters from root when checking a .py file under it.

In .dir-locals.el, I currently have the following:

((python-mode . ((flycheck-flake8rc . "setup.cfg")
                 (flycheck-mypy.ini . "setup.cfg"))))

What can I do in my .dir-locals.el so that the linters are run from root?

There is a merge-request on Github for flycheck regarding the addition of a :default-directory for flycheck (https://github.com/flycheck/flycheck/pull/973) but I have no idea how this actually works and if this can be set in .dir-locals.el.

Edit: I found a temporary solution by modifying the flycheck-mypy package and adding a :working-directory option:

(defun flycheck-mypy--find-project-root (_checker)
   (locate-dominating-file buffer-file-name "setup.cfg")))

(flycheck-define-checker python-mypy
    :working-directory flycheck-mypy--find-project-root (_checker)

But I would really like to be able to change this on a per-project basis.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.