METADATA 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. Metadata-Version: 2.1
  2. Name: autopep8
  3. Version: 1.6.0
  4. Summary: A tool that automatically formats Python code to conform to the PEP 8 style guide
  5. Home-page: https://github.com/hhatto/autopep8
  6. Author: Hideo Hattori
  7. Author-email: hhatto.jp@gmail.com
  8. License: Expat License
  9. Keywords: automation,pep8,format,pycodestyle
  10. Platform: UNKNOWN
  11. Classifier: Development Status :: 5 - Production/Stable
  12. Classifier: Environment :: Console
  13. Classifier: Intended Audience :: Developers
  14. Classifier: License :: OSI Approved :: MIT License
  15. Classifier: Operating System :: OS Independent
  16. Classifier: Programming Language :: Python
  17. Classifier: Programming Language :: Python :: 2
  18. Classifier: Programming Language :: Python :: 2.7
  19. Classifier: Programming Language :: Python :: 3
  20. Classifier: Programming Language :: Python :: 3.6
  21. Classifier: Programming Language :: Python :: 3.7
  22. Classifier: Programming Language :: Python :: 3.8
  23. Classifier: Programming Language :: Python :: 3.9
  24. Classifier: Programming Language :: Python :: 3.10
  25. Classifier: Topic :: Software Development :: Libraries :: Python Modules
  26. Classifier: Topic :: Software Development :: Quality Assurance
  27. Requires-Dist: pycodestyle (>=2.8.0)
  28. Requires-Dist: toml
  29. ========
  30. autopep8
  31. ========
  32. .. image:: https://img.shields.io/pypi/v/autopep8.svg
  33. :target: https://pypi.org/project/autopep8/
  34. :alt: PyPI Version
  35. .. image:: https://github.com/hhatto/autopep8/workflows/Python%20package/badge.svg
  36. :target: https://github.com/hhatto/autopep8/actions
  37. :alt: Build status
  38. .. image:: https://codecov.io/gh/hhatto/autopep8/branch/master/graph/badge.svg
  39. :target: https://codecov.io/gh/hhatto/autopep8
  40. :alt: Code Coverage
  41. autopep8 automatically formats Python code to conform to the `PEP 8`_ style
  42. guide. It uses the pycodestyle_ utility to determine what parts of the code
  43. needs to be formatted. autopep8 is capable of fixing most of the formatting
  44. issues_ that can be reported by pycodestyle.
  45. .. _PEP 8: https://www.python.org/dev/peps/pep-0008/
  46. .. _issues: https://pycodestyle.readthedocs.org/en/latest/intro.html#error-codes
  47. .. contents::
  48. Installation
  49. ============
  50. From pip::
  51. $ pip install --upgrade autopep8
  52. Consider using the ``--user`` option_.
  53. .. _option: https://pip.pypa.io/en/latest/user_guide/#user-installs
  54. Requirements
  55. ============
  56. autopep8 requires pycodestyle_.
  57. .. _pycodestyle: https://github.com/PyCQA/pycodestyle
  58. Usage
  59. =====
  60. To modify a file in place (with aggressive level 2)::
  61. $ autopep8 --in-place --aggressive --aggressive <filename>
  62. Before running autopep8.
  63. .. code-block:: python
  64. import math, sys;
  65. def example1():
  66. ####This is a long comment. This should be wrapped to fit within 72 characters.
  67. some_tuple=( 1,2, 3,'a' );
  68. some_variable={'long':'Long code lines should be wrapped within 79 characters.',
  69. 'other':[math.pi, 100,200,300,9876543210,'This is a long string that goes on'],
  70. 'more':{'inner':'This whole logical line should be wrapped.',some_tuple:[1,
  71. 20,300,40000,500000000,60000000000000000]}}
  72. return (some_tuple, some_variable)
  73. def example2(): return {'has_key() is deprecated':True}.has_key({'f':2}.has_key(''));
  74. class Example3( object ):
  75. def __init__ ( self, bar ):
  76. #Comments should have a space after the hash.
  77. if bar : bar+=1; bar=bar* bar ; return bar
  78. else:
  79. some_string = """
  80. Indentation in multiline strings should not be touched.
  81. Only actual code should be reindented.
  82. """
  83. return (sys.path, some_string)
  84. After running autopep8.
  85. .. code-block:: python
  86. import math
  87. import sys
  88. def example1():
  89. # This is a long comment. This should be wrapped to fit within 72
  90. # characters.
  91. some_tuple = (1, 2, 3, 'a')
  92. some_variable = {
  93. 'long': 'Long code lines should be wrapped within 79 characters.',
  94. 'other': [
  95. math.pi,
  96. 100,
  97. 200,
  98. 300,
  99. 9876543210,
  100. 'This is a long string that goes on'],
  101. 'more': {
  102. 'inner': 'This whole logical line should be wrapped.',
  103. some_tuple: [
  104. 1,
  105. 20,
  106. 300,
  107. 40000,
  108. 500000000,
  109. 60000000000000000]}}
  110. return (some_tuple, some_variable)
  111. def example2(): return ('' in {'f': 2}) in {'has_key() is deprecated': True}
  112. class Example3(object):
  113. def __init__(self, bar):
  114. # Comments should have a space after the hash.
  115. if bar:
  116. bar += 1
  117. bar = bar * bar
  118. return bar
  119. else:
  120. some_string = """
  121. Indentation in multiline strings should not be touched.
  122. Only actual code should be reindented.
  123. """
  124. return (sys.path, some_string)
  125. Options::
  126. usage: autopep8 [-h] [--version] [-v] [-d] [-i] [--global-config filename]
  127. [--ignore-local-config] [-r] [-j n] [-p n] [-a]
  128. [--experimental] [--exclude globs] [--list-fixes]
  129. [--ignore errors] [--select errors] [--max-line-length n]
  130. [--line-range line line] [--hang-closing] [--exit-code]
  131. [files [files ...]]
  132. Automatically formats Python code to conform to the PEP 8 style guide.
  133. positional arguments:
  134. files files to format or '-' for standard in
  135. optional arguments:
  136. -h, --help show this help message and exit
  137. --version show program's version number and exit
  138. -v, --verbose print verbose messages; multiple -v result in more
  139. verbose messages
  140. -d, --diff print the diff for the fixed source
  141. -i, --in-place make changes to files in place
  142. --global-config filename
  143. path to a global pep8 config file; if this file does
  144. not exist then this is ignored (default:
  145. ~/.config/pep8)
  146. --ignore-local-config
  147. don't look for and apply local config files; if not
  148. passed, defaults are updated with any config files in
  149. the project's root directory
  150. -r, --recursive run recursively over directories; must be used with
  151. --in-place or --diff
  152. -j n, --jobs n number of parallel jobs; match CPU count if value is
  153. less than 1
  154. -p n, --pep8-passes n
  155. maximum number of additional pep8 passes (default:
  156. infinite)
  157. -a, --aggressive enable non-whitespace changes; multiple -a result in
  158. more aggressive changes
  159. --experimental enable experimental fixes
  160. --exclude globs exclude file/directory names that match these comma-
  161. separated globs
  162. --list-fixes list codes for fixes; used by --ignore and --select
  163. --ignore errors do not fix these errors/warnings (default:
  164. E226,E24,W50,W690)
  165. --select errors fix only these errors/warnings (e.g. E4,W)
  166. --max-line-length n set maximum allowed line length (default: 79)
  167. --line-range line line, --range line line
  168. only fix errors found within this inclusive range of
  169. line numbers (e.g. 1 99); line numbers are indexed at
  170. 1
  171. --hang-closing hang-closing option passed to pycodestyle
  172. --exit-code change to behavior of exit code. default behavior of
  173. return value, 0 is no differences, 1 is error exit.
  174. return 2 when add this option. 2 is exists
  175. differences.
  176. Features
  177. ========
  178. autopep8 fixes the following issues_ reported by pycodestyle_::
  179. E101 - Reindent all lines.
  180. E11 - Fix indentation.
  181. E121 - Fix indentation to be a multiple of four.
  182. E122 - Add absent indentation for hanging indentation.
  183. E123 - Align closing bracket to match opening bracket.
  184. E124 - Align closing bracket to match visual indentation.
  185. E125 - Indent to distinguish line from next logical line.
  186. E126 - Fix over-indented hanging indentation.
  187. E127 - Fix visual indentation.
  188. E128 - Fix visual indentation.
  189. E129 - Fix visual indentation.
  190. E131 - Fix hanging indent for unaligned continuation line.
  191. E133 - Fix missing indentation for closing bracket.
  192. E20 - Remove extraneous whitespace.
  193. E211 - Remove extraneous whitespace.
  194. E22 - Fix extraneous whitespace around keywords.
  195. E224 - Remove extraneous whitespace around operator.
  196. E225 - Fix missing whitespace around operator.
  197. E226 - Fix missing whitespace around arithmetic operator.
  198. E227 - Fix missing whitespace around bitwise/shift operator.
  199. E228 - Fix missing whitespace around modulo operator.
  200. E231 - Add missing whitespace.
  201. E241 - Fix extraneous whitespace around keywords.
  202. E242 - Remove extraneous whitespace around operator.
  203. E251 - Remove whitespace around parameter '=' sign.
  204. E252 - Missing whitespace around parameter equals.
  205. E26 - Fix spacing after comment hash for inline comments.
  206. E265 - Fix spacing after comment hash for block comments.
  207. E266 - Fix too many leading '#' for block comments.
  208. E27 - Fix extraneous whitespace around keywords.
  209. E301 - Add missing blank line.
  210. E302 - Add missing 2 blank lines.
  211. E303 - Remove extra blank lines.
  212. E304 - Remove blank line following function decorator.
  213. E305 - Expected 2 blank lines after end of function or class.
  214. E306 - Expected 1 blank line before a nested definition.
  215. E401 - Put imports on separate lines.
  216. E402 - Fix module level import not at top of file
  217. E501 - Try to make lines fit within --max-line-length characters.
  218. E502 - Remove extraneous escape of newline.
  219. E701 - Put colon-separated compound statement on separate lines.
  220. E70 - Put semicolon-separated compound statement on separate lines.
  221. E711 - Fix comparison with None.
  222. E712 - Fix comparison with boolean.
  223. E713 - Use 'not in' for test for membership.
  224. E714 - Use 'is not' test for object identity.
  225. E721 - Use "isinstance()" instead of comparing types directly.
  226. E722 - Fix bare except.
  227. E731 - Use a def when use do not assign a lambda expression.
  228. W291 - Remove trailing whitespace.
  229. W292 - Add a single newline at the end of the file.
  230. W293 - Remove trailing whitespace on blank line.
  231. W391 - Remove trailing blank lines.
  232. W503 - Fix line break before binary operator.
  233. W504 - Fix line break after binary operator.
  234. W601 - Use "in" rather than "has_key()".
  235. W602 - Fix deprecated form of raising exception.
  236. W603 - Use "!=" instead of "<>"
  237. W604 - Use "repr()" instead of backticks.
  238. W605 - Fix invalid escape sequence 'x'.
  239. W690 - Fix various deprecated code (via lib2to3).
  240. autopep8 also fixes some issues not found by pycodestyle_.
  241. - Correct deprecated or non-idiomatic Python code (via ``lib2to3``). Use this
  242. for making Python 2.7 code more compatible with Python 3. (This is triggered
  243. if ``W690`` is enabled.)
  244. - Normalize files with mixed line endings.
  245. - Put a blank line between a class docstring and its first method
  246. declaration. (Enabled with ``E301``.)
  247. - Remove blank lines between a function declaration and its docstring. (Enabled
  248. with ``E303``.)
  249. autopep8 avoids fixing some issues found by pycodestyle_.
  250. - ``E112``/``E113`` for non comments are reports of bad indentation that break
  251. syntax rules. These should not be modified at all.
  252. - ``E265``, which refers to spacing after comment hash, is ignored if the
  253. comment looks like code. autopep8 avoids modifying these since they are not
  254. real comments. If you really want to get rid of the pycodestyle_ warning,
  255. consider just removing the commented-out code. (This can be automated via
  256. eradicate_.)
  257. .. _eradicate: https://github.com/myint/eradicate
  258. More advanced usage
  259. ===================
  260. By default autopep8 only makes whitespace changes. Thus, by default, it does
  261. not fix ``E711`` and ``E712``. (Changing ``x == None`` to ``x is None`` may
  262. change the meaning of the program if ``x`` has its ``__eq__`` method
  263. overridden.) Nor does it correct deprecated code ``W6``. To enable these
  264. more aggressive fixes, use the ``--aggressive`` option::
  265. $ autopep8 --aggressive <filename>
  266. Use multiple ``--aggressive`` to increase the aggressiveness level. For
  267. example, ``E712`` requires aggressiveness level 2 (since ``x == True`` could be
  268. changed to either ``x`` or ``x is True``, but autopep8 chooses the former).
  269. ``--aggressive`` will also shorten lines more aggressively. It will also remove
  270. trailing whitespace more aggressively. (Usually, we don't touch trailing
  271. whitespace in docstrings and other multiline strings. And to do even more
  272. aggressive changes to docstrings, use docformatter_.)
  273. .. _docformatter: https://github.com/myint/docformatter
  274. To enable only a subset of the fixes, use the ``--select`` option. For example,
  275. to fix various types of indentation issues::
  276. $ autopep8 --select=E1,W1 <filename>
  277. Similarly, to just fix deprecated code::
  278. $ autopep8 --aggressive --select=W6 <filename>
  279. The above is useful when trying to port a single code base to work with both
  280. Python 2 and Python 3 at the same time.
  281. If the file being fixed is large, you may want to enable verbose progress
  282. messages::
  283. $ autopep8 -v <filename>
  284. Passing in ``--experimental`` enables the following functionality:
  285. - Shortens code lines by taking its length into account
  286. ::
  287. $ autopep8 --experimental <filename>
  288. Use as a module
  289. ===============
  290. The simplest way of using autopep8 as a module is via the ``fix_code()``
  291. function:
  292. >>> import autopep8
  293. >>> autopep8.fix_code('x= 123\n')
  294. 'x = 123\n'
  295. Or with options:
  296. >>> import autopep8
  297. >>> autopep8.fix_code('x.has_key(y)\n',
  298. ... options={'aggressive': 1})
  299. 'y in x\n'
  300. >>> autopep8.fix_code('print( 123 )\n',
  301. ... options={'ignore': ['E']})
  302. 'print( 123 )\n'
  303. Configuration
  304. =============
  305. By default, if ``$HOME/.config/pycodestyle`` (``~\.pycodestyle`` in Windows
  306. environment) exists, it will be used as global configuration file.
  307. Alternatively, you can specify the global configuration file with the
  308. ``--global-config`` option.
  309. Also, if ``setup.cfg``, ``tox.ini``, ``.pep8`` and ``.flake8`` files exist
  310. in the directory where the target file exists, it will be used as the
  311. configuration file.
  312. ``pep8``, ``pycodestyle``, and ``flake8`` can be used as a section.
  313. configuration file example::
  314. [pycodestyle]
  315. max_line_length = 120
  316. ignore = E501
  317. pyproject.toml
  318. --------------
  319. autopep8 can also use ``pyproject.toml``.
  320. The section must be ``[tool.autopep8]``, and ``pyproject.toml`` takes precedence
  321. over any other configuration files.
  322. configuration file example::
  323. [tool.autopep8]
  324. max_line_length = 120
  325. ignore = "E501,W6" # or ["E501", "W6"]
  326. in-place = true
  327. recursive = true
  328. aggressive = 3
  329. Testing
  330. =======
  331. Test cases are in ``test/test_autopep8.py``. They can be run directly via
  332. ``python test/test_autopep8.py`` or via tox_. The latter is useful for
  333. testing against multiple Python interpreters. (We currently test against
  334. CPython versions 2.7, 3.6 3.7 and 3.8. We also test against PyPy.)
  335. .. _`tox`: https://pypi.org/project/tox/
  336. Broad spectrum testing is available via ``test/acid.py``. This script runs
  337. autopep8 against Python code and checks for correctness and completeness of the
  338. code fixes. It can check that the bytecode remains identical.
  339. ``test/acid_pypi.py`` makes use of ``acid.py`` to test against the latest
  340. released packages on PyPI.
  341. Troubleshooting
  342. ===============
  343. ``pkg_resources.DistributionNotFound``
  344. --------------------------------------
  345. If you are using an ancient version of ``setuptools``, you might encounter
  346. ``pkg_resources.DistributionNotFound`` when trying to run ``autopep8``. Try
  347. upgrading ``setuptools`` to workaround this ``setuptools`` problem::
  348. $ pip install --upgrade setuptools
  349. Use ``sudo`` if you are installing to the system.
  350. Links
  351. =====
  352. * PyPI_
  353. * GitHub_
  354. * `Travis CI`_
  355. * Coveralls_
  356. .. _PyPI: https://pypi.org/project/autopep8/
  357. .. _GitHub: https://github.com/hhatto/autopep8
  358. .. _`Travis CI`: https://travis-ci.org/hhatto/autopep8
  359. .. _`Coveralls`: https://coveralls.io/r/hhatto/autopep8