jidicula
jidicula

Reputation: 3929

Setting up Emacs Elpy with Poetry

How can I configure Elpy to use dev dependencies like Black, Jedi, and flake8 that are installed in a Poetry project virtual environment rather than those that are installed systemwide?

Upvotes: 5

Views: 2889

Answers (2)

jidicula
jidicula

Reputation: 3929

Use the poetry.el Emacs package with poetry-tracking-mode enabled by add-hooking it to elpy-mode-hook. Elpy will automatically detect the Poetry virtual environment and check for those dev tools in that environment.

Jan 2021 update: I've since stopped using Elpy and switched to lsp-mode and lsp-python-ms - it's a far better development experience. The only caveat is that it can only discover virtualenvs local to the project, so Poetry has to be configured to create venvs locally (poetry config virtualenvs.in-project true).

Upvotes: 4

kusimari
kusimari

Reputation: 21

If you use emacs -nw, then another option is

  • Install virtualenvwrapper in poetry project. That is run poetry add -D virtualenvwrapper.
  • Install elpy dependencies you need. M-x elpy-config' to find dependencies. So poetry add -D jedi rope autopep8 yapf black flake8`. This can also be done when elpy prompts you, but then it will probably install as a normal dependency and not just dev dependency.
  • Add (setq elpy-rpc-virtualenv-path 'current) so that elpy uses the poetry virtual env for Virtualenv, Interactive Python, RPC virtual env.
  • Launch emacs through poetry poetry run emacs -nw

You need to do this for each poetry project. There should be way to install some of these globally in pyenv and have poetry and the project virtual env pick it up. However, doing it for each project keeps dependencies isolated, even for dev stuff.

Upvotes: 0

Related Questions