serhii.net

In the middle of the desert you can say anything you want

24 Jan 2022

Setting up pycharm for poetry, black etc.

Setting up the poetry environment

Create a new project, point it at the folder with the sources, and instead of trying to use an existing poetry environment, just create a new one. It will use the same virtualenv as usual when running poetry shell inside that directory. Nice!1

The project uses ./src/package_name layout (220105-1142 Order of directories inside a python project), which created issues in the editor (tests and files run fine though). Fixed by adding ./src as Source Root, then it parses all imports as packgae name

Setting up black

Black as external tool

Official Black instructions for Pycharm worked for me: Editor integration — Black 21.12b0 documentation

Creating a binding for black in ideavim

This was tricky! I found a really nice post2 that showed how to spawn vim from ideavim. I tried following its example but

nmap <leader>f :action Tool_External_Tools_black<CR>

didn’t work.

The post mentioned running :actionlist inside the editor to get the list of all available actions (I used to rely on a github gist for that!). Well, would you believe, External Tools has a space inside it.

So the correct line is:

nmap <leader>f :action Tool_External Tools_black<CR>

Wow. …Wow.

In any case works now!


  1. Reddit suggested using poetry env info, which gives info about the environment, and add that interpreter to pycharm directly ↩︎

  2. Customising IdeaVim - Chathura Colombage; His example .ideavimrc from that post is really really interesting, TODO steal ideas! ↩︎

Nel mezzo del deserto posso dire tutto quello che voglio.
comments powered by Disqus