<commit_before>====
YAPF
====

.. image:: https://badge.fury.io/py/yapf.svg
    :target: http://badge.fury.io/py/yapf
    :alt: PyPI version

.. image:: https://travis-ci.org/google/yapf.svg?branch=master
    :target: https://travis-ci.org/google/yapf
    :alt: Build status

.. image:: https://coveralls.io/repos/google/yapf/badge.svg?branch=master
    :target: https://coveralls.io/r/google/yapf?branch=master
    :alt: Coverage status


Introduction
============

Most of the current formatters for Python --- e.g., autopep8, and pep8ify ---
are made to remove lint errors from code. This has some obvious limitations.
For instance, code that conforms to the PEP 8 guidelines may not be
reformatted.  But it doesn't mean that the code looks good.

YAPF takes a different approach. It's based off of 'clang-format', developed by
<NAME>. In essence, the algorithm takes the code and reformats it to the
best formatting that conforms to the style guide, even if the original code
didn't violate the style guide. The idea is also similar to the 'gofmt' tool for
the Go programming language: end all holy wars about formatting - if the whole
code base of a project is simply piped through YAPF whenever modifications are
made, the style remains consistent throughout the project and there's no point
arguing about style in every code review.

The ultimate goal is that the code YAPF produces is as good as the code that a
programmer would write if they were following the style guide. It takes away
some of the drudgery of maintaining your code.

.. footer::

    YAPF is not an official Google product (experimental or otherwise), it is
    just code that happens to be owned by Google.

.. contents::


Installation
============

To install YAPF from PyPI:

.. code-block:: shell

    $ pip install yapf

YAPF is still considered in "alpha" stage, and the released version may change
often; therefore, the best way to keep up-to-date with the latest development
is to clone this repository.

Note that if you intend to use YAPF as a command-line tool rather than as a
library, installation is not necessary. YAPF supports being run as a directory
by the Python interpreter. If you cloned/unzipped YAPF into ``DIR``, it's
possible to run:

.. code-block:: shell

    $ PYTHONPATH=DIR python DIR/yapf [options] ...


Python versions
===============

YAPF supports Python 2.7 and 3.4.1+.

YAPF requires the code it formats to be valid Python for the version YAPF itself
runs under. Therefore, if you format Python 3 code with YAPF, run YAPF itself
under Python 3 (and similarly for Python 2).


Usage
=====

Options::

    usage: yapf [-h] [-v] [-d | -i] [-r | -l START-END] [-e PATTERN]
                [--style STYLE] [--style-help] [--no-local-style]
                [files [files ...]]

    Formatter for Python code.

    positional arguments:
      files

    optional arguments:
      -h, --help            show this help message and exit
      -v, --version         show version number and exit
      -d, --diff            print the diff for the fixed source
      -i, --in-place        make changes to files in place
      -r, --recursive       run recursively over directories
      -l START-END, --lines START-END
                            range of lines to reformat, one-based
      -e PATTERN, --exclude PATTERN
                            patterns for files to exclude from formatting
      --style STYLE         specify formatting style: either a style name (for
                            example "pep8" or "google"), or the name of a file
                            with style settings. The default is pep8 unless a
                            .style.yapf or setup.cfg file located in one of the
                            parent directories of the source file (or current
                            directory for stdin)
      --style-help          show style settings and exit
      --no-local-style      don't search for local style definition (.style.yapf)


Formatting style
================

The formatting style used by YAPF is configurable and there are many "knobs"
that can be used to tune how YAPF does formatting. See the ``style.py`` module
for the full list.

To control the style, run YAPF with the ``--style`` argument. It accepts one of
the predefined styles (e.g., ``pep8`` or ``google``), a path to a configuration
file that specifies the desired style, or a dictionary of key/value pairs.

The config file is a simple listing of (case-insensitive) ``key = value`` pairs
with a ``[style]`` heading. For example:

.. code-block:: guess

    [style]
    based_on_style = pep8
    spaces_before_comment = 4
    split_before_logical_operator = true

The ``based_on_style`` setting determines which of the predefined styles this
custom style is based on (think of it like subclassing).

It's also possible to do the same on the command line with a dictionary. For
example:

.. code-block:: guess

    --style='{based_on_style: chromium, indent_width: 4}'

This will take the ``chromium`` base style and modify it to have four space
indentations.

YAPF will search for the formatting style in the following manner:

1. Specified on the command line
2. In the `[style]` section of a `.style.yapf` file in either the current
   directory or one of its parent directories.
3. In the `[yapf]` section of a `setup.cfg` file in either the current
   directory or one of its parent directories.
4. In the `~/.config/yapf/style` file in your home directory.

If none of those files are found, the default style is used (PEP8).


Example
=======

An example of the type of formatting that YAPF can do, it will take this ugly
code:

.. code-block:: python
<commit_msg>Remove invalid RST bits<commit_after>====
YAPF
====

.. image:: https://badge.fury.io/py/yapf.svg
    :target: http://badge.fury.io/py/yapf
    :alt: PyPI version

.. image:: https://travis-ci.org/google/yapf.svg?branch=master
    :target: https://travis-ci.org/google/yapf
    :alt: Build status

.. image:: https://coveralls.io/repos/google/yapf/badge.svg?branch=master
    :target: https://coveralls.io/r/google/yapf?branch=master
    :alt: Coverage status


Introduction
============

Most of the current formatters for Python --- e.g., autopep8, and pep8ify ---
are made to remove lint errors from code. This has some obvious limitations.
For instance, code that conforms to the PEP 8 guidelines may not be
reformatted.  But it doesn't mean that the code looks good.

YAPF takes a different approach. It's based off of 'clang-format', developed by
<NAME>. In essence, the algorithm takes the code and reformats it to the
best formatting that conforms to the style guide, even if the original code
didn't violate the style guide. The idea is also similar to the 'gofmt' tool for
the Go programming language: end all holy wars about formatting - if the whole
code base of a project is simply piped through YAPF whenever modifications are
made, the style remains consistent throughout the project and there's no point
arguing about style in every code review.

The ultimate goal is that the code YAPF produces is as good as the code that a
programmer would write if they were following the style guide. It takes away
some of the drudgery of maintaining your code.

.. footer::

    YAPF is not an official Google product (experimental or otherwise), it is
    just code that happens to be owned by Google.

.. contents::


Installation
============

To install YAPF from PyPI:

.. code-block::

    $ pip install yapf

YAPF is still considered in "alpha" stage, and the released version may change
often; therefore, the best way to keep up-to-date with the latest development
is to clone this repository.

Note that if you intend to use YAPF as a command-line tool rather than as a
library, installation is not necessary. YAPF supports being run as a directory
by the Python interpreter. If you cloned/unzipped YAPF into ``DIR``, it's
possible to run:

.. code-block::

    $ PYTHONPATH=DIR python DIR/yapf [options] ...


Python versions
===============

YAPF supports Python 2.7 and 3.4.1+.

YAPF requires the code it formats to be valid Python for the version YAPF itself
runs under. Therefore, if you format Python 3 code with YAPF, run YAPF itself
under Python 3 (and similarly for Python 2).


Usage
=====

Options::

    usage: yapf [-h] [-v] [-d | -i] [-r | -l START-END] [-e PATTERN]
                [--style STYLE] [--style-help] [--no-local-style]
                [files [files ...]]

    Formatter for Python code.

    positional arguments:
      files

    optional arguments:
      -h, --help            show this help message and exit
      -v, --version         show version number and exit
      -d, --diff            print the diff for the fixed source
      -i, --in-place        make changes to files in place
      -r, --recursive       run recursively over directories
      -l START-END, --lines START-END
                            range of lines to reformat, one-based
      -e PATTERN, --exclude PATTERN
                            patterns for files to exclude from formatting
      --style STYLE         specify formatting style: either a style name (for
                            example "pep8" or "google"), or the name of a file
                            with style settings. The default is pep8 unless a
                            .style.yapf or setup.cfg file located in one of the
                            parent directories of the source file (or current
                            directory for stdin)
      --style-help          show style settings and exit
      --no-local-style      don't search for local style definition (.style.yapf)


Formatting style
================

The formatting style used by YAPF is configurable and there are many "knobs"
that can be used to tune how YAPF does formatting. See the ``style.py`` module
for the full list.

To control the style, run YAPF with the ``--style`` argument. It accepts one of
the predefined styles (e.g., ``pep8`` or ``google``), a path to a configuration
file that specifies the desired style, or a dictionary of key/value pairs.

The config file is a simple listing of (case-insensitive) ``key = value`` pairs
with a ``[style]`` heading. For example:

.. code-block::

    [style]
    based_on_style = pep8
    spaces_before_comment = 4
    split_before_logical_operator = true

The ``based_on_style`` setting determines which of the predefined styles this
custom style is based on (think of it like subclassing).

It's also possible to do the same on the command line with a dictionary. For
example:

.. code-block::

    --style='{based_on_style: chromium, indent_width: 4}'

This will take the ``chromium`` base style and modify it to have four space
indentations.

YAPF will search for the formatting style in the following manner:

1. Specified on the command line
2. In the `[style]` section of a `.style.yapf` file in either the current
   directory or one of its parent directories.
3. In the `[yapf]` section of a `setup.cfg` file in either the current
   directory or one of its parent directories.
4. In the `~/.config/yapf/style` file in your home directory.

If none of those files are found, the default style is used (PEP8).


Example
=======

An example of the type of formatting that YAPF can do, it will take this ugly
code:

.. code-block:: python

{'fraction_non_alphanumeric': 0.08710188280837586, 'fraction_numerical': 0.0038711947914833716, 'mean_word_length': 2.8246971736204576, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7334270', 'n_tokens_mistral': 3261, 'n_tokens_neox': 3118, 'n_words': 1535}