autopep8


Nameautopep8 JSON
Version 2.3.1 PyPI version JSON
download
home_pageNone
SummaryA tool that automatically formats Python code to conform to the PEP 8 style guide
upload_time2024-06-23 05:15:55
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords automation pep8 format pycodestyle
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ========
autopep8
========

.. image:: https://img.shields.io/pypi/v/autopep8.svg
    :target: https://pypi.org/project/autopep8/
    :alt: PyPI Version

.. image:: https://github.com/hhatto/autopep8/workflows/Python%20package/badge.svg
    :target: https://github.com/hhatto/autopep8/actions
    :alt: Build status

.. image:: https://codecov.io/gh/hhatto/autopep8/branch/main/graph/badge.svg
    :target: https://codecov.io/gh/hhatto/autopep8
    :alt: Code Coverage

autopep8 automatically formats Python code to conform to the `PEP 8`_ style
guide. It uses the pycodestyle_ utility to determine what parts of the code
needs to be formatted. autopep8 is capable of fixing most of the formatting
issues_ that can be reported by pycodestyle.

.. _PEP 8: https://www.python.org/dev/peps/pep-0008/
.. _issues: https://pycodestyle.readthedocs.org/en/latest/intro.html#error-codes

.. contents::


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

From pip::

    $ pip install --upgrade autopep8

Consider using the ``--user`` option_.

.. _option: https://pip.pypa.io/en/latest/user_guide/#user-installs


Requirements
============

autopep8 requires pycodestyle_.

.. _pycodestyle: https://github.com/PyCQA/pycodestyle


Usage
=====

To modify a file in place (with aggressive level 2)::

    $ autopep8 --in-place --aggressive --aggressive <filename>

Before running autopep8.

.. code-block:: python

    import math, sys;

    def example1():
        ####This is a long comment. This should be wrapped to fit within 72 characters.
        some_tuple=(   1,2, 3,'a'  );
        some_variable={'long':'Long code lines should be wrapped within 79 characters.',
        'other':[math.pi, 100,200,300,9876543210,'This is a long string that goes on'],
        'more':{'inner':'This whole logical line should be wrapped.',some_tuple:[1,
        20,300,40000,500000000,60000000000000000]}}
        return (some_tuple, some_variable)
    def example2(): return {'has_key() is deprecated':True}.has_key({'f':2}.has_key(''));
    class Example3(   object ):
        def __init__    ( self, bar ):
         #Comments should have a space after the hash.
         if bar : bar+=1;  bar=bar* bar   ; return bar
         else:
                        some_string = """
    		           Indentation in multiline strings should not be touched.
    Only actual code should be reindented.
    """
                        return (sys.path, some_string)

After running autopep8.

.. code-block:: python

    import math
    import sys


    def example1():
        # This is a long comment. This should be wrapped to fit within 72
        # characters.
        some_tuple = (1, 2, 3, 'a')
        some_variable = {
            'long': 'Long code lines should be wrapped within 79 characters.',
            'other': [
                math.pi,
                100,
                200,
                300,
                9876543210,
                'This is a long string that goes on'],
            'more': {
                'inner': 'This whole logical line should be wrapped.',
                some_tuple: [
                    1,
                    20,
                    300,
                    40000,
                    500000000,
                    60000000000000000]}}
        return (some_tuple, some_variable)


    def example2(): return ('' in {'f': 2}) in {'has_key() is deprecated': True}


    class Example3(object):
        def __init__(self, bar):
            # Comments should have a space after the hash.
            if bar:
                bar += 1
                bar = bar * bar
                return bar
            else:
                some_string = """
    		           Indentation in multiline strings should not be touched.
    Only actual code should be reindented.
    """
                return (sys.path, some_string)

Options::

    usage: autopep8 [-h] [--version] [-v] [-d] [-i] [--global-config filename]
                    [--ignore-local-config] [-r] [-j n] [-p n] [-a]
                    [--experimental] [--exclude globs] [--list-fixes]
                    [--ignore errors] [--select errors] [--max-line-length n]
                    [--line-range line line] [--hang-closing] [--exit-code]
                    [files [files ...]]

    Automatically formats Python code to conform to the PEP 8 style guide.

    positional arguments:
      files                 files to format or '-' for standard in

    optional arguments:
      -h, --help            show this help message and exit
      --version             show program's version number and exit
      -v, --verbose         print verbose messages; multiple -v result in more
                            verbose messages
      -d, --diff            print the diff for the fixed source
      -i, --in-place        make changes to files in place
      --global-config filename
                            path to a global pep8 config file; if this file does
                            not exist then this is ignored (default:
                            ~/.config/pep8)
      --ignore-local-config
                            don't look for and apply local config files; if not
                            passed, defaults are updated with any config files in
                            the project's root directory
      -r, --recursive       run recursively over directories; must be used with
                            --in-place or --diff
      -j n, --jobs n        number of parallel jobs; match CPU count if value is
                            less than 1
      -p n, --pep8-passes n
                            maximum number of additional pep8 passes (default:
                            infinite)
      -a, --aggressive      enable non-whitespace changes; multiple -a result in
                            more aggressive changes
      --experimental        enable experimental fixes
      --exclude globs       exclude file/directory names that match these comma-
                            separated globs
      --list-fixes          list codes for fixes; used by --ignore and --select
      --ignore errors       do not fix these errors/warnings (default:
                            E226,E24,W50,W690)
      --select errors       fix only these errors/warnings (e.g. E4,W)
      --max-line-length n   set maximum allowed line length (default: 79)
      --line-range line line, --range line line
                            only fix errors found within this inclusive range of
                            line numbers (e.g. 1 99); line numbers are indexed at
                            1
      --hang-closing        hang-closing option passed to pycodestyle
      --exit-code           change to behavior of exit code. default behavior of
                            return value, 0 is no differences, 1 is error exit.
                            return 2 when add this option. 2 is exists
                            differences.


Features
========

autopep8 fixes the following issues_ reported by pycodestyle_::

    E101 - Reindent all lines.
    E11  - Fix indentation.
    E121 - Fix indentation to be a multiple of four.
    E122 - Add absent indentation for hanging indentation.
    E123 - Align closing bracket to match opening bracket.
    E124 - Align closing bracket to match visual indentation.
    E125 - Indent to distinguish line from next logical line.
    E126 - Fix over-indented hanging indentation.
    E127 - Fix visual indentation.
    E128 - Fix visual indentation.
    E129 - Fix visual indentation.
    E131 - Fix hanging indent for unaligned continuation line.
    E133 - Fix missing indentation for closing bracket.
    E20  - Remove extraneous whitespace.
    E211 - Remove extraneous whitespace.
    E22  - Fix extraneous whitespace around keywords.
    E224 - Remove extraneous whitespace around operator.
    E225 - Fix missing whitespace around operator.
    E226 - Fix missing whitespace around arithmetic operator.
    E227 - Fix missing whitespace around bitwise/shift operator.
    E228 - Fix missing whitespace around modulo operator.
    E231 - Add missing whitespace.
    E241 - Fix extraneous whitespace around keywords.
    E242 - Remove extraneous whitespace around operator.
    E251 - Remove whitespace around parameter '=' sign.
    E252 - Missing whitespace around parameter equals.
    E26  - Fix spacing after comment hash for inline comments.
    E265 - Fix spacing after comment hash for block comments.
    E266 - Fix too many leading '#' for block comments.
    E27  - Fix extraneous whitespace around keywords.
    E301 - Add missing blank line.
    E302 - Add missing 2 blank lines.
    E303 - Remove extra blank lines.
    E304 - Remove blank line following function decorator.
    E305 - Expected 2 blank lines after end of function or class.
    E306 - Expected 1 blank line before a nested definition.
    E401 - Put imports on separate lines.
    E402 - Fix module level import not at top of file
    E501 - Try to make lines fit within --max-line-length characters.
    E502 - Remove extraneous escape of newline.
    E701 - Put colon-separated compound statement on separate lines.
    E70  - Put semicolon-separated compound statement on separate lines.
    E711 - Fix comparison with None.
    E712 - Fix comparison with boolean.
    E713 - Use 'not in' for test for membership.
    E714 - Use 'is not' test for object identity.
    E721 - Use "isinstance()" instead of comparing types directly.
    E722 - Fix bare except.
    E731 - Use a def when use do not assign a lambda expression.
    W291 - Remove trailing whitespace.
    W292 - Add a single newline at the end of the file.
    W293 - Remove trailing whitespace on blank line.
    W391 - Remove trailing blank lines.
    W503 - Fix line break before binary operator.
    W504 - Fix line break after binary operator.
    W605 - Fix invalid escape sequence 'x'.

autopep8 also fixes some issues not found by pycodestyle_.

- Normalize files with mixed line endings.
- Put a blank line between a class docstring and its first method
  declaration. (Enabled with ``E301``.)
- Remove blank lines between a function declaration and its docstring. (Enabled
  with ``E303``.)

autopep8 avoids fixing some issues found by pycodestyle_.

- ``E112``/``E113`` for non comments are reports of bad indentation that break
  syntax rules. These should not be modified at all.
- ``E265``, which refers to spacing after comment hash, is ignored if the
  comment looks like code. autopep8 avoids modifying these since they are not
  real comments. If you really want to get rid of the pycodestyle_ warning,
  consider just removing the commented-out code. (This can be automated via
  eradicate_.)

.. _eradicate: https://github.com/myint/eradicate


More advanced usage
===================

By default autopep8 only makes whitespace changes. Thus, by default, it does
not fix ``E711`` and ``E712``. (Changing ``x == None`` to ``x is None`` may
change the meaning of the program if ``x`` has its ``__eq__`` method
overridden.) Nor does it correct deprecated code ``W6``. To enable these
more aggressive fixes, use the ``--aggressive`` option::

    $ autopep8 --aggressive <filename>

Use multiple ``--aggressive`` to increase the aggressiveness level. For
example, ``E712`` requires aggressiveness level 2 (since ``x == True`` could be
changed to either ``x`` or ``x is True``, but autopep8 chooses the former).

``--aggressive`` will also shorten lines more aggressively. It will also remove
trailing whitespace more aggressively. (Usually, we don't touch trailing
whitespace in docstrings and other multiline strings. And to do even more
aggressive changes to docstrings, use docformatter_.)

.. _docformatter: https://github.com/myint/docformatter

To enable only a subset of the fixes, use the ``--select`` option. For example,
to fix various types of indentation issues::

    $ autopep8 --select=E1,W1 <filename>

If the file being fixed is large, you may want to enable verbose progress
messages::

    $ autopep8 -v <filename>

Passing in ``--experimental`` enables the following functionality:

- Shortens code lines by taking its length into account

::

$ autopep8 --experimental <filename>

Disabling line-by-line
----------------------

It is possible to disable autopep8 untill it it turned back on again in the file, using ``autopep8: off`` and then renabling ``autopep8: on``. 

.. code-block:: python

    # autopep8: off
        [
            [23, 23, 13, 43],
            [32, 34, 34, 34],
            [56, 34, 34, 11],
            [10, 10, 10, 10],
        ]
    # autopep8: on
         
``fmt: off`` and ``fmt: on`` are also valid.

Use as a module
===============

The simplest way of using autopep8 as a module is via the ``fix_code()``
function:

    >>> import autopep8
    >>> autopep8.fix_code('x=       123\n')
    'x = 123\n'

Or with options:

    >>> import autopep8
    >>> autopep8.fix_code('print( 123 )\n',
    ...                   options={'ignore': ['E']})
    'print( 123 )\n'


Configuration
=============

By default, if ``$HOME/.config/pycodestyle`` (``~\.pycodestyle`` in Windows
environment) exists, it will be used as global configuration file.
Alternatively, you can specify the global configuration file with the
``--global-config`` option.

Also, if ``setup.cfg``, ``tox.ini``, ``.pep8`` and ``.flake8`` files exist
in the directory where the target file exists, it will be used as the
configuration file.

``pep8``, ``pycodestyle``, and ``flake8`` can be used as a section.

configuration file example::

    [pycodestyle]
    max_line_length = 120
    ignore = E501

pyproject.toml
--------------

autopep8 can also use ``pyproject.toml``.
The section must be ``[tool.autopep8]``, and ``pyproject.toml`` takes precedence
over any other configuration files.

configuration file example::

    [tool.autopep8]
    max_line_length = 120
    ignore = "E501,W6"  # or ["E501", "W6"]
    in-place = true
    recursive = true
    aggressive = 3

Usage with pre-commit
=====================

autopep8 can be used as a hook for pre-commit_.

To add autopep8 as a plugin, add this repo definition to your configuration:

.. code-block:: yaml

    repos:
    -   repo: https://github.com/hhatto/autopep8
        rev: ...  # select the tag or revision you want, or run `pre-commit autoupdate`
        hooks:
        -   id: autopep8

.. _`pre-commit`: https://pre-commit.com


Testing
=======

Test cases are in ``test/test_autopep8.py``. They can be run directly via
``python test/test_autopep8.py`` or via tox_. The latter is useful for
testing against multiple Python interpreters. (We currently test against
CPython versions 3.8, 3.9, 3.10, 3.11 and 3.12. We also test against PyPy.)

.. _`tox`: https://pypi.org/project/tox/

Broad spectrum testing is available via ``test/acid.py``. This script runs
autopep8 against Python code and checks for correctness and completeness of the
code fixes. It can check that the bytecode remains identical.
``test/acid_pypi.py`` makes use of ``acid.py`` to test against the latest
released packages on PyPI.


Troubleshooting
===============

``pkg_resources.DistributionNotFound``
--------------------------------------

If you are using an ancient version of ``setuptools``, you might encounter
``pkg_resources.DistributionNotFound`` when trying to run ``autopep8``. Try
upgrading ``setuptools`` to workaround this ``setuptools`` problem::

    $ pip install --upgrade setuptools

Use ``sudo`` if you are installing to the system.


Links
=====

* PyPI_
* GitHub_
* `Travis CI`_
* Codecov_

.. _PyPI: https://pypi.org/project/autopep8/
.. _GitHub: https://github.com/hhatto/autopep8
.. _`Travis CI`: https://travis-ci.org/hhatto/autopep8
.. _`Codecov`: https://app.codecov.io/gh/hhatto/autopep8

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "autopep8",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "automation, pep8, format, pycodestyle",
    "author": null,
    "author_email": "Hideo Hattori <hhatto.jp@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/6c/52/65556a5f917a4b273fd1b705f98687a6bd721dbc45966f0f6687e90a18b0/autopep8-2.3.1.tar.gz",
    "platform": null,
    "description": "========\nautopep8\n========\n\n.. image:: https://img.shields.io/pypi/v/autopep8.svg\n    :target: https://pypi.org/project/autopep8/\n    :alt: PyPI Version\n\n.. image:: https://github.com/hhatto/autopep8/workflows/Python%20package/badge.svg\n    :target: https://github.com/hhatto/autopep8/actions\n    :alt: Build status\n\n.. image:: https://codecov.io/gh/hhatto/autopep8/branch/main/graph/badge.svg\n    :target: https://codecov.io/gh/hhatto/autopep8\n    :alt: Code Coverage\n\nautopep8 automatically formats Python code to conform to the `PEP 8`_ style\nguide. It uses the pycodestyle_ utility to determine what parts of the code\nneeds to be formatted. autopep8 is capable of fixing most of the formatting\nissues_ that can be reported by pycodestyle.\n\n.. _PEP 8: https://www.python.org/dev/peps/pep-0008/\n.. _issues: https://pycodestyle.readthedocs.org/en/latest/intro.html#error-codes\n\n.. contents::\n\n\nInstallation\n============\n\nFrom pip::\n\n    $ pip install --upgrade autopep8\n\nConsider using the ``--user`` option_.\n\n.. _option: https://pip.pypa.io/en/latest/user_guide/#user-installs\n\n\nRequirements\n============\n\nautopep8 requires pycodestyle_.\n\n.. _pycodestyle: https://github.com/PyCQA/pycodestyle\n\n\nUsage\n=====\n\nTo modify a file in place (with aggressive level 2)::\n\n    $ autopep8 --in-place --aggressive --aggressive <filename>\n\nBefore running autopep8.\n\n.. code-block:: python\n\n    import math, sys;\n\n    def example1():\n        ####This is a long comment. This should be wrapped to fit within 72 characters.\n        some_tuple=(   1,2, 3,'a'  );\n        some_variable={'long':'Long code lines should be wrapped within 79 characters.',\n        'other':[math.pi, 100,200,300,9876543210,'This is a long string that goes on'],\n        'more':{'inner':'This whole logical line should be wrapped.',some_tuple:[1,\n        20,300,40000,500000000,60000000000000000]}}\n        return (some_tuple, some_variable)\n    def example2(): return {'has_key() is deprecated':True}.has_key({'f':2}.has_key(''));\n    class Example3(   object ):\n        def __init__    ( self, bar ):\n         #Comments should have a space after the hash.\n         if bar : bar+=1;  bar=bar* bar   ; return bar\n         else:\n                        some_string = \"\"\"\n    \t\t           Indentation in multiline strings should not be touched.\n    Only actual code should be reindented.\n    \"\"\"\n                        return (sys.path, some_string)\n\nAfter running autopep8.\n\n.. code-block:: python\n\n    import math\n    import sys\n\n\n    def example1():\n        # This is a long comment. This should be wrapped to fit within 72\n        # characters.\n        some_tuple = (1, 2, 3, 'a')\n        some_variable = {\n            'long': 'Long code lines should be wrapped within 79 characters.',\n            'other': [\n                math.pi,\n                100,\n                200,\n                300,\n                9876543210,\n                'This is a long string that goes on'],\n            'more': {\n                'inner': 'This whole logical line should be wrapped.',\n                some_tuple: [\n                    1,\n                    20,\n                    300,\n                    40000,\n                    500000000,\n                    60000000000000000]}}\n        return (some_tuple, some_variable)\n\n\n    def example2(): return ('' in {'f': 2}) in {'has_key() is deprecated': True}\n\n\n    class Example3(object):\n        def __init__(self, bar):\n            # Comments should have a space after the hash.\n            if bar:\n                bar += 1\n                bar = bar * bar\n                return bar\n            else:\n                some_string = \"\"\"\n    \t\t           Indentation in multiline strings should not be touched.\n    Only actual code should be reindented.\n    \"\"\"\n                return (sys.path, some_string)\n\nOptions::\n\n    usage: autopep8 [-h] [--version] [-v] [-d] [-i] [--global-config filename]\n                    [--ignore-local-config] [-r] [-j n] [-p n] [-a]\n                    [--experimental] [--exclude globs] [--list-fixes]\n                    [--ignore errors] [--select errors] [--max-line-length n]\n                    [--line-range line line] [--hang-closing] [--exit-code]\n                    [files [files ...]]\n\n    Automatically formats Python code to conform to the PEP 8 style guide.\n\n    positional arguments:\n      files                 files to format or '-' for standard in\n\n    optional arguments:\n      -h, --help            show this help message and exit\n      --version             show program's version number and exit\n      -v, --verbose         print verbose messages; multiple -v result in more\n                            verbose messages\n      -d, --diff            print the diff for the fixed source\n      -i, --in-place        make changes to files in place\n      --global-config filename\n                            path to a global pep8 config file; if this file does\n                            not exist then this is ignored (default:\n                            ~/.config/pep8)\n      --ignore-local-config\n                            don't look for and apply local config files; if not\n                            passed, defaults are updated with any config files in\n                            the project's root directory\n      -r, --recursive       run recursively over directories; must be used with\n                            --in-place or --diff\n      -j n, --jobs n        number of parallel jobs; match CPU count if value is\n                            less than 1\n      -p n, --pep8-passes n\n                            maximum number of additional pep8 passes (default:\n                            infinite)\n      -a, --aggressive      enable non-whitespace changes; multiple -a result in\n                            more aggressive changes\n      --experimental        enable experimental fixes\n      --exclude globs       exclude file/directory names that match these comma-\n                            separated globs\n      --list-fixes          list codes for fixes; used by --ignore and --select\n      --ignore errors       do not fix these errors/warnings (default:\n                            E226,E24,W50,W690)\n      --select errors       fix only these errors/warnings (e.g. E4,W)\n      --max-line-length n   set maximum allowed line length (default: 79)\n      --line-range line line, --range line line\n                            only fix errors found within this inclusive range of\n                            line numbers (e.g. 1 99); line numbers are indexed at\n                            1\n      --hang-closing        hang-closing option passed to pycodestyle\n      --exit-code           change to behavior of exit code. default behavior of\n                            return value, 0 is no differences, 1 is error exit.\n                            return 2 when add this option. 2 is exists\n                            differences.\n\n\nFeatures\n========\n\nautopep8 fixes the following issues_ reported by pycodestyle_::\n\n    E101 - Reindent all lines.\n    E11  - Fix indentation.\n    E121 - Fix indentation to be a multiple of four.\n    E122 - Add absent indentation for hanging indentation.\n    E123 - Align closing bracket to match opening bracket.\n    E124 - Align closing bracket to match visual indentation.\n    E125 - Indent to distinguish line from next logical line.\n    E126 - Fix over-indented hanging indentation.\n    E127 - Fix visual indentation.\n    E128 - Fix visual indentation.\n    E129 - Fix visual indentation.\n    E131 - Fix hanging indent for unaligned continuation line.\n    E133 - Fix missing indentation for closing bracket.\n    E20  - Remove extraneous whitespace.\n    E211 - Remove extraneous whitespace.\n    E22  - Fix extraneous whitespace around keywords.\n    E224 - Remove extraneous whitespace around operator.\n    E225 - Fix missing whitespace around operator.\n    E226 - Fix missing whitespace around arithmetic operator.\n    E227 - Fix missing whitespace around bitwise/shift operator.\n    E228 - Fix missing whitespace around modulo operator.\n    E231 - Add missing whitespace.\n    E241 - Fix extraneous whitespace around keywords.\n    E242 - Remove extraneous whitespace around operator.\n    E251 - Remove whitespace around parameter '=' sign.\n    E252 - Missing whitespace around parameter equals.\n    E26  - Fix spacing after comment hash for inline comments.\n    E265 - Fix spacing after comment hash for block comments.\n    E266 - Fix too many leading '#' for block comments.\n    E27  - Fix extraneous whitespace around keywords.\n    E301 - Add missing blank line.\n    E302 - Add missing 2 blank lines.\n    E303 - Remove extra blank lines.\n    E304 - Remove blank line following function decorator.\n    E305 - Expected 2 blank lines after end of function or class.\n    E306 - Expected 1 blank line before a nested definition.\n    E401 - Put imports on separate lines.\n    E402 - Fix module level import not at top of file\n    E501 - Try to make lines fit within --max-line-length characters.\n    E502 - Remove extraneous escape of newline.\n    E701 - Put colon-separated compound statement on separate lines.\n    E70  - Put semicolon-separated compound statement on separate lines.\n    E711 - Fix comparison with None.\n    E712 - Fix comparison with boolean.\n    E713 - Use 'not in' for test for membership.\n    E714 - Use 'is not' test for object identity.\n    E721 - Use \"isinstance()\" instead of comparing types directly.\n    E722 - Fix bare except.\n    E731 - Use a def when use do not assign a lambda expression.\n    W291 - Remove trailing whitespace.\n    W292 - Add a single newline at the end of the file.\n    W293 - Remove trailing whitespace on blank line.\n    W391 - Remove trailing blank lines.\n    W503 - Fix line break before binary operator.\n    W504 - Fix line break after binary operator.\n    W605 - Fix invalid escape sequence 'x'.\n\nautopep8 also fixes some issues not found by pycodestyle_.\n\n- Normalize files with mixed line endings.\n- Put a blank line between a class docstring and its first method\n  declaration. (Enabled with ``E301``.)\n- Remove blank lines between a function declaration and its docstring. (Enabled\n  with ``E303``.)\n\nautopep8 avoids fixing some issues found by pycodestyle_.\n\n- ``E112``/``E113`` for non comments are reports of bad indentation that break\n  syntax rules. These should not be modified at all.\n- ``E265``, which refers to spacing after comment hash, is ignored if the\n  comment looks like code. autopep8 avoids modifying these since they are not\n  real comments. If you really want to get rid of the pycodestyle_ warning,\n  consider just removing the commented-out code. (This can be automated via\n  eradicate_.)\n\n.. _eradicate: https://github.com/myint/eradicate\n\n\nMore advanced usage\n===================\n\nBy default autopep8 only makes whitespace changes. Thus, by default, it does\nnot fix ``E711`` and ``E712``. (Changing ``x == None`` to ``x is None`` may\nchange the meaning of the program if ``x`` has its ``__eq__`` method\noverridden.) Nor does it correct deprecated code ``W6``. To enable these\nmore aggressive fixes, use the ``--aggressive`` option::\n\n    $ autopep8 --aggressive <filename>\n\nUse multiple ``--aggressive`` to increase the aggressiveness level. For\nexample, ``E712`` requires aggressiveness level 2 (since ``x == True`` could be\nchanged to either ``x`` or ``x is True``, but autopep8 chooses the former).\n\n``--aggressive`` will also shorten lines more aggressively. It will also remove\ntrailing whitespace more aggressively. (Usually, we don't touch trailing\nwhitespace in docstrings and other multiline strings. And to do even more\naggressive changes to docstrings, use docformatter_.)\n\n.. _docformatter: https://github.com/myint/docformatter\n\nTo enable only a subset of the fixes, use the ``--select`` option. For example,\nto fix various types of indentation issues::\n\n    $ autopep8 --select=E1,W1 <filename>\n\nIf the file being fixed is large, you may want to enable verbose progress\nmessages::\n\n    $ autopep8 -v <filename>\n\nPassing in ``--experimental`` enables the following functionality:\n\n- Shortens code lines by taking its length into account\n\n::\n\n$ autopep8 --experimental <filename>\n\nDisabling line-by-line\n----------------------\n\nIt is possible to disable autopep8 untill it it turned back on again in the file, using ``autopep8: off`` and then renabling ``autopep8: on``. \n\n.. code-block:: python\n\n    # autopep8: off\n        [\n            [23, 23, 13, 43],\n            [32, 34, 34, 34],\n            [56, 34, 34, 11],\n            [10, 10, 10, 10],\n        ]\n    # autopep8: on\n         \n``fmt: off`` and ``fmt: on`` are also valid.\n\nUse as a module\n===============\n\nThe simplest way of using autopep8 as a module is via the ``fix_code()``\nfunction:\n\n    >>> import autopep8\n    >>> autopep8.fix_code('x=       123\\n')\n    'x = 123\\n'\n\nOr with options:\n\n    >>> import autopep8\n    >>> autopep8.fix_code('print( 123 )\\n',\n    ...                   options={'ignore': ['E']})\n    'print( 123 )\\n'\n\n\nConfiguration\n=============\n\nBy default, if ``$HOME/.config/pycodestyle`` (``~\\.pycodestyle`` in Windows\nenvironment) exists, it will be used as global configuration file.\nAlternatively, you can specify the global configuration file with the\n``--global-config`` option.\n\nAlso, if ``setup.cfg``, ``tox.ini``, ``.pep8`` and ``.flake8`` files exist\nin the directory where the target file exists, it will be used as the\nconfiguration file.\n\n``pep8``, ``pycodestyle``, and ``flake8`` can be used as a section.\n\nconfiguration file example::\n\n    [pycodestyle]\n    max_line_length = 120\n    ignore = E501\n\npyproject.toml\n--------------\n\nautopep8 can also use ``pyproject.toml``.\nThe section must be ``[tool.autopep8]``, and ``pyproject.toml`` takes precedence\nover any other configuration files.\n\nconfiguration file example::\n\n    [tool.autopep8]\n    max_line_length = 120\n    ignore = \"E501,W6\"  # or [\"E501\", \"W6\"]\n    in-place = true\n    recursive = true\n    aggressive = 3\n\nUsage with pre-commit\n=====================\n\nautopep8 can be used as a hook for pre-commit_.\n\nTo add autopep8 as a plugin, add this repo definition to your configuration:\n\n.. code-block:: yaml\n\n    repos:\n    -   repo: https://github.com/hhatto/autopep8\n        rev: ...  # select the tag or revision you want, or run `pre-commit autoupdate`\n        hooks:\n        -   id: autopep8\n\n.. _`pre-commit`: https://pre-commit.com\n\n\nTesting\n=======\n\nTest cases are in ``test/test_autopep8.py``. They can be run directly via\n``python test/test_autopep8.py`` or via tox_. The latter is useful for\ntesting against multiple Python interpreters. (We currently test against\nCPython versions 3.8, 3.9, 3.10, 3.11 and 3.12. We also test against PyPy.)\n\n.. _`tox`: https://pypi.org/project/tox/\n\nBroad spectrum testing is available via ``test/acid.py``. This script runs\nautopep8 against Python code and checks for correctness and completeness of the\ncode fixes. It can check that the bytecode remains identical.\n``test/acid_pypi.py`` makes use of ``acid.py`` to test against the latest\nreleased packages on PyPI.\n\n\nTroubleshooting\n===============\n\n``pkg_resources.DistributionNotFound``\n--------------------------------------\n\nIf you are using an ancient version of ``setuptools``, you might encounter\n``pkg_resources.DistributionNotFound`` when trying to run ``autopep8``. Try\nupgrading ``setuptools`` to workaround this ``setuptools`` problem::\n\n    $ pip install --upgrade setuptools\n\nUse ``sudo`` if you are installing to the system.\n\n\nLinks\n=====\n\n* PyPI_\n* GitHub_\n* `Travis CI`_\n* Codecov_\n\n.. _PyPI: https://pypi.org/project/autopep8/\n.. _GitHub: https://github.com/hhatto/autopep8\n.. _`Travis CI`: https://travis-ci.org/hhatto/autopep8\n.. _`Codecov`: https://app.codecov.io/gh/hhatto/autopep8\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A tool that automatically formats Python code to conform to the PEP 8 style guide",
    "version": "2.3.1",
    "project_urls": {
        "Repository": "https://github.com/hhatto/autopep8"
    },
    "split_keywords": [
        "automation",
        " pep8",
        " format",
        " pycodestyle"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ad9ef0beffe45b507dca9d7540fad42b316b2fd1076dc484c9b1f23d9da570d7",
                "md5": "287514b6f225228c8ebd0c8a1a040f70",
                "sha256": "a203fe0fcad7939987422140ab17a930f684763bf7335bdb6709991dd7ef6c2d"
            },
            "downloads": -1,
            "filename": "autopep8-2.3.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "287514b6f225228c8ebd0c8a1a040f70",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.8",
            "size": 45667,
            "upload_time": "2024-06-23T05:15:51",
            "upload_time_iso_8601": "2024-06-23T05:15:51.290667Z",
            "url": "https://files.pythonhosted.org/packages/ad/9e/f0beffe45b507dca9d7540fad42b316b2fd1076dc484c9b1f23d9da570d7/autopep8-2.3.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6c5265556a5f917a4b273fd1b705f98687a6bd721dbc45966f0f6687e90a18b0",
                "md5": "3eaa29fd60ce5ebb3218dddd1bd9cff5",
                "sha256": "8d6c87eba648fdcfc83e29b788910b8643171c395d9c4bcf115ece035b9c9dda"
            },
            "downloads": -1,
            "filename": "autopep8-2.3.1.tar.gz",
            "has_sig": false,
            "md5_digest": "3eaa29fd60ce5ebb3218dddd1bd9cff5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 92064,
            "upload_time": "2024-06-23T05:15:55",
            "upload_time_iso_8601": "2024-06-23T05:15:55.401371Z",
            "url": "https://files.pythonhosted.org/packages/6c/52/65556a5f917a4b273fd1b705f98687a6bd721dbc45966f0f6687e90a18b0/autopep8-2.3.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-23 05:15:55",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hhatto",
    "github_project": "autopep8",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "autopep8"
}
        
Elapsed time: 0.28779s