
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
A tool that applies the Black python source code formatter to a single piece of python source code instead of a whole file or project.
$ pip install blacken-selection
$ blacken-selection -h
usage: Apply the black code formatter for a piece of python source code
positional arguments:
SOURCE The python source code to be formatted. If not
provided then source is read from stdin.
optional arguments:
-h, --help show this help message and exit
-l LINE_LENGTH, --line-length LINE_LENGTH
How many characters per line to allow. [default: 88]
$ blacken-selection "def main(): pass"
def main():
pass
Unfortunately PyCharm External Tools cannot be used directly. The $SelectedText$ macro passes the selection as a command line argument to the tool but there is no way to properly quote a python string using double quotes.
But there is a solution:
xclip
command line tool, we will use it to grab the
code selection in PyCharm via the clipboardSetup blacken-selection-xclip.sh
as an external tool in PyCharm:
File -> Settings -> Tools -> External Tools
Click the + icon to add a new external tool with the following values:
Name: blacken
Description: Blacken a piece of python code
Program: <absolute path for your blacken-selection-xclip.sh>
Arguments:
Select a piece of python source code in your editor and from the right click context menu select:
External Tools -> blacken
Or you can confiugre a shortcut (e.g. Shift+Alt+B) to trigger the tool in:
Settings -> Keymap-> External Tools -> blacken
The tool will grab the selected text form the clipboard, format it with black,
and the copy the formatted code back to the clipboard. So you can basically do
the select
, shift+alt+B
, insert
in PyCharm to format a piece
of python code with black.
FAQs
Apply black formatter for a piece of python source code
We found that blacken-selection demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.