@@ -496,6 +496,14 @@ Then run it on a file or series of files to get a report of any violations.
496
496
optparse.py:472:29: E221 multiple spaces before operator
497
497
optparse.py:544:21: W601 .has_key() is deprecated, use 'in'
498
498
499
+ Auto-Formatting
500
+ ~~~~~~~~~~~~~~~
501
+
502
+ There are several auto-formatting tools that can reformat your code,
503
+ in order to comply with PEP 8.
504
+
505
+ **autopep8 **
506
+
499
507
The program `autopep8 <https://pypi.org/project/autopep8/ >`_ can be used to
500
508
automatically reformat code in the PEP 8 style. Install the program with:
501
509
@@ -513,6 +521,49 @@ Excluding the ``--in-place`` flag will cause the program to output the modified
513
521
code directly to the console for review. The ``--aggressive `` flag will perform
514
522
more substantial changes and can be applied multiple times for greater effect.
515
523
524
+ **yapf **
525
+
526
+ While autopep8 focuses on solving the PEP 8 violations, `yapf <https://github.com/google/yapf >`_
527
+ tries to improve the format of your code aside from complying with PEP 8.
528
+ This formatter aims at providing as good looking code as a programmer who
529
+ writes PEP 8 compliant code.
530
+ It gets installed with:
531
+
532
+ .. code-block :: console
533
+
534
+ $ pip install yapf
535
+
536
+ Run the auto-formatting of a file with:
537
+
538
+ .. code-block :: console
539
+
540
+ $ yapf --in-place optparse.py
541
+
542
+ Similar to autopep8, running the command without the ``--in-place `` flag will
543
+ output the diff for review before applying the changes.
544
+
545
+ **black **
546
+
8000
td>
547
+ The auto-formatter `black <https://github.com/psf/black >`_ offers an
548
+ opinionated and deterministic reformatting of your code base.
549
+ Its main focus lies in providing a uniform code style without the need of
550
+ configuration throughout its users. Hence, users of black are able to forget
551
+ about formatting altogether. Also, due to the deterministic approach minimal
552
+ git diffs with only the relevant changes are guaranteed. You can install the
553
+ tool as follows:
554
+
555
+ .. code-block :: console
556
+
557
+ $ pip install black
558
+
559
+ A python file can be formatted with:
560
+
561
+ .. code-block :: console
562
+
563
+ $ black optparse.py
564
+
565
+ Adding the ``--diff `` flag provides the code modification for review without
566
+ direct application.
516
567
517
568
***********
518
569
Conventions
0 commit comments