pablogsal / black-pycharm

Pycharm plugin for https://github.com/ambv/black
32 stars 11 forks source link

how to use the tool on windows #6

Open ssamdani-1729 opened 5 years ago

ssamdani-1729 commented 5 years ago

I'm wondering how I can make this work on a windows version of Pycharm. I have installed the black tool in a conda virtual environment and this same virtual environment is being used by PyCharm.

neulaender commented 5 years ago

As the tool needs to be installed in /usr/local/bin/black I guess there is no way for windows. You might try the ubuntu-shell for windows?

ghost commented 5 years ago

You can configure the pycharm plugin from pycharm's file -> settings -> tools menu. There you can set the path to the black executable.

You can also setup an external tool hook in pycharm, also in settings > tools. However this won't use the plugin but will run the tool directly.

JosXa commented 4 years ago

I would love to see either of the following two things in order to make the plugin work on windows:

(obviously the 1st being the easier option).

denis-roy commented 4 years ago

As per Black's documentation section on integrations, no plugin is required to use Black in PyCharm.

Here's a working procedure for v19.10b1.dev49 which is the current latest at the date of this post:


PyCharm/IntelliJ IDEA Integration

Install Black

$ pip install black

Locate your Black installation folder

On macOS / Linux / BSD:

$ which black
/usr/local/bin/black        
^-possible location-^

On Windows:

$ where black
%LocalAppData%\Programs\Python\Python36-32\Scripts\black.exe
^-possible location-^

Open External tools in PyCharm/IntelliJ IDEA

On macOS:

PyCharm -> Preferences -> Tools -> External Tools

On Windows / Linux / BSD:

File -> Settings -> Tools -> External Tools

Add Black as an external tool

Click the + icon to add a new external tool with the following values:

Usage

Format the currently opened file by selecting Tools -> External Tools -> black. Alternatively, you can set a keyboard shortcut by navigating to Preferences or Settings -> Keymap -> External Tools -> External Tools - Black

Optionally, run Black on every file save

⚠ Make sure you have the File Watcher plugin installed.

Go to Preferences or Settings -> Tools -> File Watchers and click + to add a new watcher: