Search code examples
pythonpython-3.xmacrospycharmpython-black

FilePath macro does not contain value in Pycharm


I have installed the Python Black code formatter (https://github.com/psf/black). I want to integrate it into my PyCharm as an external tool. I have added the arguments of Black but the $FilePath$ macro does not provide the path of current file.

My current config:

Settings > Tools > External Tools > Black

Program: /home/milanbalazs/.local/bin/black
Arguments: --fast -l 100 -v $FilePath$
Working directory: /home/milanbalazs/.local/bin

Output of Black when I run it:

/home/milanbalazs/.local/bin/black --fast -l 100 -v
No paths given. Nothing to do 😴

Process finished with exit code 0

As you can see above the $FilePath$ macro does not provide the path of file. But when I check it in the Insert Macro... option then it provides the correct path in the Macro preview box.

Any idea how can I solve it or what can be the problem?


Solution

  • I guess it's a feature. $FilePath$ (and other similar macros) requires a file to be selected either in the editor or in the project tree.