@@ -10,6 +10,19 @@ Options include the following:
10
10
11
11
## PyCharm/IntelliJ IDEA
12
12
13
+ There are three different ways you can use _ Black_ from PyCharm:
14
+
15
+ 1 . As local server using the BlackConnect plugin
16
+ 1 . As external tool
17
+ 1 . As file watcher
18
+
19
+ The first option is the simplest to set up and formats the fastest (by spinning up
20
+ {doc}` Black's HTTP server </usage_and_configuration/black_as_a_server> ` , avoiding the
21
+ startup cost on subsequent formats), but if you would prefer to not install a
22
+ third-party plugin or blackd's extra dependencies, the other two are also great options.
23
+
24
+ ### As local server
25
+
13
26
1 . Install _ Black_ with the ` d ` extra.
14
27
15
28
``` console
@@ -46,6 +59,99 @@ Options include the following:
46
59
- In ` Trigger Settings ` section of plugin configuration check
47
60
` Trigger when saving changed files ` .
48
61
62
+ ### As external tool
63
+
64
+ 1 . Install ` black ` .
65
+
66
+ ``` console
67
+ $ pip install black
68
+ ```
69
+
70
+ 1 . Locate your ` black ` installation folder.
71
+
72
+ On macOS / Linux / BSD:
73
+
74
+ ``` console
75
+ $ which black
76
+ /usr/local/bin/black # possible location
77
+ ```
78
+
79
+ On Windows:
80
+
81
+ ``` console
82
+ $ where black
83
+ %LocalAppData%\Programs\Python\Python36-32\Scripts\black.exe # possible location
84
+ ```
85
+
86
+ Note that if you are using a virtual environment detected by PyCharm, this is an
87
+ unneeded step. In this case the path to ` black ` is ` $PyInterpreterDirectory$/black ` .
88
+
89
+ 1 . Open External tools in PyCharm/IntelliJ IDEA
90
+
91
+ On macOS:
92
+
93
+ ` PyCharm -> Preferences -> Tools -> External Tools `
94
+
95
+ On Windows / Linux / BSD:
96
+
97
+ ` File -> Settings -> Tools -> External Tools `
98
+
99
+ 1 . Click the + icon to add a new external tool with the following values:
100
+
101
+ - Name: Black
102
+ - Description: Black is the uncompromising Python code formatter.
103
+ - Program: \< install_location_from_step_2>
104
+ - Arguments: ` "$FilePath$" `
105
+
106
+ 1 . Format the currently opened file by selecting ` Tools -> External Tools -> black ` .
107
+
108
+ - Alternatively, you can set a keyboard shortcut by navigating to
109
+ ` Preferences or Settings -> Keymap -> External Tools -> External Tools - Black ` .
110
+
111
+ ### As file watcher
112
+
113
+ 1 . Install ` black ` .
114
+
115
+ ``` console
116
+ $ pip install black
117
+ ```
118
+
119
+ 1 . Locate your ` black ` installation folder.
120
+
121
+ On macOS / Linux / BSD:
122
+
123
+ ``` console
124
+ $ which black
125
+ /usr/local/bin/black # possible location
126
+ ```
127
+
128
+ On Windows:
129
+
130
+ ``` console
131
+ $ where black
132
+ %LocalAppData%\Programs\Python\Python36-32\Scripts\black.exe # possible location
133
+ ```
134
+
135
+ Note that if you are using a virtual environment detected by PyCharm, this is an
136
+ unneeded step. In this case the path to ` black ` is ` $PyInterpreterDirectory$/black ` .
137
+
138
+ 1 . Make sure you have the
139
+ [ File Watchers] ( https://plugins.jetbrains.com/plugin/7177-file-watchers ) plugin
140
+ installed.
141
+ 1 . Go to ` Preferences or Settings -> Tools -> File Watchers ` and click ` + ` to add a new
142
+ watcher:
143
+ - Name: Black
144
+ - File type: Python
145
+ - Scope: Project Files
146
+ - Program: \< install_location_from_step_2>
147
+ - Arguments: ` $FilePath$ `
148
+ - Output paths to refresh: ` $FilePath$ `
149
+ - Working directory: ` $ProjectFileDir$ `
150
+
151
+ - In Advanced Options
152
+ - Uncheck "Auto-save edited files to trigger the watcher"
153
+ - Uncheck "Trigger the watcher on external changes"
154
+
49
155
## Wing IDE
50
156
51
157
Wing IDE supports ` black ` via ** Preference Settings** for system wide settings and
0 commit comments