2

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?

milanbalazs
  • 4,811
  • 4
  • 23
  • 45
  • Do you have a file in focus while invoking the external tool? – Pavel Karateev Sep 09 '19 at 09:46
  • WoW, You are right. If the `code editor` window is not in focus or something in the `project view` window the `$FilePath$` macro doesn't provide the path of file. On the other hand if something is selected in the `project view` window, the macro proved the path of that file/dir. It is strange for me. Is it a bug or a feature? :) If you write your comment as an answer, I will mark my question as answered. – milanbalazs Sep 09 '19 at 10:05

1 Answers1

2

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.

Pavel Karateev
  • 7,737
  • 3
  • 32
  • 59