User Tools

Site Tools


black_notes

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
black_notes [2021/01/28 20:32] – [configure pycharm with black] rajublack_notes [2022/02/18 15:24] – [do not convert single quotes to double quotes] raju
Line 1: Line 1:
-==== configure pycharm with black ====+==== configure pycharm to format code with black ==== 
 +To run black on the entire file
 <code> <code>
 File -> Settings File -> Settings
 -> Tools -> External Tools -> click on + sign -> Tools -> External Tools -> click on + sign
--> Name Black +-> NameBlack 
-   Description Black in pycharm configuration+   DescriptionBlack in pycharm configuration
    Program: C:\ProgramData\Continuum\Anaconda\envs\[ENV_NAME]\Scripts\black.exe    Program: C:\ProgramData\Continuum\Anaconda\envs\[ENV_NAME]\Scripts\black.exe
    Arguments: $FilePath$    Arguments: $FilePath$
Line 10: Line 11:
 </code> </code>
  
-Ref:- +To run black on selected text 
 +<code> 
 +File -> Settings 
 +-> Tools -> External Tools -> click on + sign 
 +-> Name: Black Selected 
 +   Description: run black on selected text 
 +   Program: "C:\Program Files\Git\bin\bash.exe" 
 +   Arguments: --login H:\work\myrepos\rutils\python3\black_on_selected.sh C:\ProgramData\Continuum\Anaconda\envs\ro_udw_env\Scripts\black.exe $FilePath$ $SelectionStartLine$ $SelectionEndLine$ 
 +   Working directory: $ProjectFileDir$ 
 +</code> 
 + 
 +Restart pycharm after adding the external tools. 
 + 
 +To format code 
 +<code> 
 +Select code of interest 
 +-> Tools -> External Tools -> Black Selected 
 +</code> 
 + 
 + 
 +See also :-  
 +  * [[https://github.com/KamarajuKusumanchi/rutils/blob/master/python3/black_on_selected.sh | black_on_selected.sh]] (github.com/KamarajuKusumanchi) simpler implementation; works with GNU sed. Tested it on Windows 10 + git bash + GNU sed 4.7.
   * https://godatadriven.com/blog/partial-python-code-formatting-with-black-pycharm/ - well explained; His script is a bit complex and the sed commands are mac specific.   * https://godatadriven.com/blog/partial-python-code-formatting-with-black-pycharm/ - well explained; His script is a bit complex and the sed commands are mac specific.
-  * - simpler implementation; works with GNU sedTested it on Windows 10 + git bash + GNU sed 4.7.+  * https://www.jetbrains.com/help/pycharm/configuring-third-party-tools.html 
 + 
 + 
 +==== do not convert single quotes to double quotes ==== 
 +pass ''%%--%%skip-string-normalization'' on the command line. 
 + 
 +Ref:- 
 +  * https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#strings - this option is meant as an adoption helper, avoid using it for new projects. 
 + 
  
 ==== useful links ==== ==== useful links ====
black_notes.txt · Last modified: 2022/02/18 22:45 by raju