.dir-locals.el 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. ;;; .dir-locals.el
  2. ;;
  3. ;; If you get ``*** EPC Error ***`` with this setup in your emacs session,
  4. ;; mostly you have jedi-mode enabled but the python enviroment is missed. The
  5. ;; python environment has to be next to the ``<repo>/.dir-locals.el`` in::
  6. ;;
  7. ;; ./local/py3
  8. ;;
  9. ;; In Emacs, some buffer locals are referencing the project environment:
  10. ;;
  11. ;; - prj-root --> <repo>/
  12. ;; - python-environment-directory --> <repo>/local
  13. ;; - python-environment-default-root-name --> py3
  14. ;; - python-shell-virtualenv-root --> <repo>/local/py3
  15. ;; When this variable is set with the path of the virtualenv to use,
  16. ;; `process-environment' and `exec-path' get proper values in order to run
  17. ;; shells inside the specified virtualenv, example::
  18. ;; (setq python-shell-virtualenv-root "/path/to/env/")
  19. ;;
  20. ;; To setup such an environment build target 'pyenv' or 'pyenvinstall'::
  21. ;;
  22. ;; $ make pyenvinstall
  23. ;;
  24. ;; Alternatively create the virtualenv, source it and install jedi + epc
  25. ;; (required by `emacs-jedi <https://tkf.github.io/emacs-jedi>`_)::
  26. ;;
  27. ;; $ virtualenv --python=python3 "--no-site-packages" ./local/py3
  28. ;; ...
  29. ;; $ source ./local/py3/bin/activate
  30. ;; (py3)$ # now install into the activated 'py3' environment ..
  31. ;; (py3)$ pip install jedi epc
  32. ;; ...
  33. ((nil
  34. . ((fill-column . 80)
  35. ))
  36. (python-mode
  37. . ((indent-tabs-mode . nil)
  38. ;; project root folder is where the `.dir-locals.el' is located
  39. (eval . (setq-local
  40. prj-root (locate-dominating-file default-directory ".dir-locals.el")))
  41. (eval . (setq-local
  42. python-environment-directory (expand-file-name "./local" prj-root)))
  43. ;; use 'py3' enviroment as default
  44. (eval . (setq-local
  45. python-environment-default-root-name "py3"))
  46. (eval . (setq-local
  47. python-shell-virtualenv-root
  48. (concat python-environment-directory
  49. "/"
  50. python-environment-default-root-name)))
  51. ;; python-shell-virtualenv-path is obsolete, use python-shell-virtualenv-root!
  52. ;; (eval . (setq-local
  53. ;; python-shell-virtualenv-path python-shell-virtualenv-root))
  54. (eval . (setq-local
  55. python-shell-interpreter
  56. (expand-file-name "bin/python" python-shell-virtualenv-root)))
  57. (eval . (setq-local
  58. python-environment-virtualenv
  59. (list (expand-file-name "bin/virtualenv" python-shell-virtualenv-root)
  60. ;;"--system-site-packages"
  61. "--quiet")))
  62. (eval . (setq-local
  63. pylint-command
  64. (expand-file-name "bin/pylint" python-shell-virtualenv-root)))
  65. ;; pylint will find the '.pylintrc' file next to the CWD
  66. ;; https://pylint.readthedocs.io/en/latest/user_guide/run.html#command-line-options
  67. (eval . (setq-local
  68. flycheck-pylintrc ".pylintrc"))
  69. ;; flycheck & other python stuff should use the local py3 environment
  70. (eval . (setq-local
  71. flycheck-python-pylint-executable python-shell-interpreter))
  72. ;; use 'M-x jedi:show-setup-info' and 'M-x epc:controller' to inspect jedi server
  73. ;; https://tkf.github.io/emacs-jedi/latest/#jedi:environment-root -- You
  74. ;; can specify a full path instead of a name (relative path). In that case,
  75. ;; python-environment-directory is ignored and Python virtual environment
  76. ;; is created at the specified path.
  77. (eval . (setq-local jedi:environment-root python-shell-virtualenv-root))
  78. ;; https://tkf.github.io/emacs-jedi/latest/#jedi:server-command
  79. (eval .(setq-local
  80. jedi:server-command
  81. (list python-shell-interpreter
  82. jedi:server-script)
  83. ))
  84. ;; jedi:environment-virtualenv --> see above 'python-environment-virtualenv'
  85. ;; is set buffer local! No need to setup jedi:environment-virtualenv:
  86. ;;
  87. ;; Virtualenv command to use. A list of string. If it is nil,
  88. ;; python-environment-virtualenv is used instead. You must set non-nil
  89. ;; value to jedi:environment-root in order to make this setting work.
  90. ;;
  91. ;; https://tkf.github.io/emacs-jedi/latest/#jedi:environment-virtualenv
  92. ;;
  93. ;; (eval . (setq-local
  94. ;; jedi:environment-virtualenv
  95. ;; (list (expand-file-name "bin/virtualenv" python-shell-virtualenv-root)
  96. ;; ;;"--python"
  97. ;; ;;"/usr/bin/python3.4"
  98. ;; )))
  99. ;; jedi:server-args
  100. )))