Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. Metadata-Version: 2.1
  2. Name: autopep8
  3. Version: 2.0.2
  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. Classifier: Development Status :: 5 - Production/Stable
  11. Classifier: Environment :: Console
  12. Classifier: Intended Audience :: Developers
  13. Classifier: License :: OSI Approved :: MIT License
  14. Classifier: Operating System :: OS Independent
  15. Classifier: Programming Language :: Python
  16. Classifier: Programming Language :: Python :: 3
  17. Classifier: Programming Language :: Python :: 3.6
  18. Classifier: Programming Language :: Python :: 3.7
  19. Classifier: Programming Language :: Python :: 3.8
  20. Classifier: Programming Language :: Python :: 3.9
  21. Classifier: Programming Language :: Python :: 3.10
  22. Classifier: Topic :: Software Development :: Libraries :: Python Modules
  23. Classifier: Topic :: Software Development :: Quality Assurance
  24. Requires-Python: >=3.6
  25. License-File: LICENSE
  26. License-File: AUTHORS.rst
  27. Requires-Dist: pycodestyle (>=2.10.0)
  28. Requires-Dist: tomli ; python_version < "3.11"
  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/main/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. W605 - Fix invalid escape sequence 'x'.
  235. W690 - Fix various deprecated code (via lib2to3).
  236. autopep8 also fixes some issues not found by pycodestyle_.
  237. - Correct deprecated or non-idiomatic Python code (via ``lib2to3``). Use this
  238. for making Python 2.7 code more compatible with Python 3. (This is triggered
  239. if ``W690`` is enabled.)
  240. - Normalize files with mixed line endings.
  241. - Put a blank line between a class docstring and its first method
  242. declaration. (Enabled with ``E301``.)
  243. - Remove blank lines between a function declaration and its docstring. (Enabled
  244. with ``E303``.)
  245. autopep8 avoids fixing some issues found by pycodestyle_.
  246. - ``E112``/``E113`` for non comments are reports of bad indentation that break
  247. syntax rules. These should not be modified at all.
  248. - ``E265``, which refers to spacing after comment hash, is ignored if the
  249. comment looks like code. autopep8 avoids modifying these since they are not
  250. real comments. If you really want to get rid of the pycodestyle_ warning,
  251. consider just removing the commented-out code. (This can be automated via
  252. eradicate_.)
  253. .. _eradicate: https://github.com/myint/eradicate
  254. More advanced usage
  255. ===================
  256. By default autopep8 only makes whitespace changes. Thus, by default, it does
  257. not fix ``E711`` and ``E712``. (Changing ``x == None`` to ``x is None`` may
  258. change the meaning of the program if ``x`` has its ``__eq__`` method
  259. overridden.) Nor does it correct deprecated code ``W6``. To enable these
  260. more aggressive fixes, use the ``--aggressive`` option::
  261. $ autopep8 --aggressive <filename>
  262. Use multiple ``--aggressive`` to increase the aggressiveness level. For
  263. example, ``E712`` requires aggressiveness level 2 (since ``x == True`` could be
  264. changed to either ``x`` or ``x is True``, but autopep8 chooses the former).
  265. ``--aggressive`` will also shorten lines more aggressively. It will also remove
  266. trailing whitespace more aggressively. (Usually, we don't touch trailing
  267. whitespace in docstrings and other multiline strings. And to do even more
  268. aggressive changes to docstrings, use docformatter_.)
  269. .. _docformatter: https://github.com/myint/docformatter
  270. To enable only a subset of the fixes, use the ``--select`` option. For example,
  271. to fix various types of indentation issues::
  272. $ autopep8 --select=E1,W1 <filename>
  273. If the file being fixed is large, you may want to enable verbose progress
  274. messages::
  275. $ autopep8 -v <filename>
  276. Passing in ``--experimental`` enables the following functionality:
  277. - Shortens code lines by taking its length into account
  278. ::
  279. $ autopep8 --experimental <filename>
  280. Disabling line-by-line
  281. ----------------------
  282. It is possible to disable autopep8 untill it it turned back on again in the file, using ``autopep8: off`` and then renabling ``autopep8: on``.
  283. .. code-block:: python
  284. # autopep8: off
  285. [
  286. [23, 23, 13, 43],
  287. [32, 34, 34, 34],
  288. [56, 34, 34, 11],
  289. [10, 10, 10, 10],
  290. ]
  291. # autopep8: on
  292. ``fmt: off`` and ``fmt: on`` are also valid.
  293. Use as a module
  294. ===============
  295. The simplest way of using autopep8 as a module is via the ``fix_code()``
  296. function:
  297. >>> import autopep8
  298. >>> autopep8.fix_code('x= 123\n')
  299. 'x = 123\n'
  300. Or with options:
  301. >>> import autopep8
  302. >>> autopep8.fix_code('print( 123 )\n',
  303. ... options={'ignore': ['E']})
  304. 'print( 123 )\n'
  305. Configuration
  306. =============
  307. By default, if ``$HOME/.config/pycodestyle`` (``~\.pycodestyle`` in Windows
  308. environment) exists, it will be used as global configuration file.
  309. Alternatively, you can specify the global configuration file with the
  310. ``--global-config`` option.
  311. Also, if ``setup.cfg``, ``tox.ini``, ``.pep8`` and ``.flake8`` files exist
  312. in the directory where the target file exists, it will be used as the
  313. configuration file.
  314. ``pep8``, ``pycodestyle``, and ``flake8`` can be used as a section.
  315. configuration file example::
  316. [pycodestyle]
  317. max_line_length = 120
  318. ignore = E501
  319. pyproject.toml
  320. --------------
  321. autopep8 can also use ``pyproject.toml``.
  322. The section must be ``[tool.autopep8]``, and ``pyproject.toml`` takes precedence
  323. over any other configuration files.
  324. configuration file example::
  325. [tool.autopep8]
  326. max_line_length = 120
  327. ignore = "E501,W6" # or ["E501", "W6"]
  328. in-place = true
  329. recursive = true
  330. aggressive = 3
  331. Testing
  332. =======
  333. Test cases are in ``test/test_autopep8.py``. They can be run directly via
  334. ``python test/test_autopep8.py`` or via tox_. The latter is useful for
  335. testing against multiple Python interpreters. (We currently test against
  336. CPython versions 3.7, 3.8, 3.9 and 3.10. We also test against PyPy.)
  337. .. _`tox`: https://pypi.org/project/tox/
  338. Broad spectrum testing is available via ``test/acid.py``. This script runs
  339. autopep8 against Python code and checks for correctness and completeness of the
  340. code fixes. It can check that the bytecode remains identical.
  341. ``test/acid_pypi.py`` makes use of ``acid.py`` to test against the latest
  342. released packages on PyPI.
  343. Troubleshooting
  344. ===============
  345. ``pkg_resources.DistributionNotFound``
  346. --------------------------------------
  347. If you are using an ancient version of ``setuptools``, you might encounter
  348. ``pkg_resources.DistributionNotFound`` when trying to run ``autopep8``. Try
  349. upgrading ``setuptools`` to workaround this ``setuptools`` problem::
  350. $ pip install --upgrade setuptools
  351. Use ``sudo`` if you are installing to the system.
  352. Links
  353. =====
  354. * PyPI_
  355. * GitHub_
  356. * `Travis CI`_
  357. * Coveralls_
  358. .. _PyPI: https://pypi.org/project/autopep8/
  359. .. _GitHub: https://github.com/hhatto/autopep8
  360. .. _`Travis CI`: https://travis-ci.org/hhatto/autopep8
  361. .. _`Coveralls`: https://coveralls.io/r/hhatto/autopep8