Simple plugin for IDEA intended to help you to avoid overhead from starting black process each time you save a Python file.
Instead, on each press of Alt + Shift + B
plugin will send contents of the current Python file to the blackd and replace them with the formatted version (if any changes were made at all).
- Ability to trigger on each file save.
- Integration with the "Reformat Code" function.
- Start blackd when IDE opens.
- Automatic handling of Python type stubs (
.pyi
). - Rough support for Jupyter Notebook files.
- Ability to reformat selected fragment only instead of whole file.
- Load formatting settings from [tool.black] section of
pyproject.toml
- Connect to blackd over SSL if needed (e.g. blackd behind nginx)
- Configurable options:
- Hostname, port and https.
- Preferred line length (default: 88).
- Skipping sanity checks ("fast mode").
- Skipping string normalization.
- Processing of "magic trailing comma" in collections.
- Target specific Python versions.
NB: If you plan on triggering reformat on each save, please make sure to disable features in other plugins (e.g. Save Actions) which may trigger standard "Reformat code" action.
Also, please make sure to disable black in "Settings / Tools / File Watchers" if you installed it previously using the example from documentation.
Just go to the plugin page in JetBrains Plugins Repository and press Install to IDE
.
...or just compile it straight from the source code:
- Open this project in IDEA.
- Open Gradle side tab and run
buildPlugin
task. - After project is built, open your favorite IDEA-based IDE.
- In Preferences window, choose Plugins pane and click on the gear icon.
- Choose
Install Plugin from Disk
and point it to ZIP file in thebuild/distributions
directory.
- Make plugin properly dynamic.
- "Live reformatting".
- Automatic detection of applicable Python frameworks.
- Detection of possible conflicts with other plugins / File Watchers.
- Better integration with Jupyter Notebooks.
Development requirements:
- Java SDK 11 or newer
- Python 3.8 or newer
- Poetry
Run tests:
./gradlew test
Launch a testing version of PyCharm with the plugin enabled:
./gradlew runIde
- Andrey Vlasovskikh - goading me into publishing this plugin.
- Łukasz Langa - hinting at a proper font for the icon.
- Nazmul Idris - writing awesome article about IDEA plugins.
- Joachim Ansorg - for the most detailed guide to writing IDEA plugins I could find.