/intellij-blackconnect

IDEA plugin for using black[d] during Python development.

Primary LanguageKotlinMIT LicenseMIT

logo intellij-blackconnect

Plugin version Total downloads Plugin rating Build status Code Coverage License

NB: If you want to see this plugin as an official way to use black with PyCharm - feel free to voice your support in this Pull Request!

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).

Features

  • 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.

Installation

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.

Stable version

Just go to the plugin page in JetBrains Plugins Repository and press Install to IDE.

Development Snapshot

...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 the build/distributions directory.

TODOs

  • 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.

Contributing

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

Special thanks