Skip to content

Commit 287df5f

Browse files
authored
Use black for python codestyle (python#386)
* blacken python files * add badge for codestyle * make all dicts and lists consistent with a trailing comma * edits per @serhiy-storchaka and @terryjreedy review * Edit per @serhiy-storchaka review * Edit per @serihy-storchaka clarification * Remove unneeded unicode u
1 parent cb66ba1 commit 287df5f

4 files changed

Lines changed: 149 additions & 45 deletions

File tree

README.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
The CPython Developer's Guide
22
=============================
33

4-
.. image:: https://readthedocs.org/projects/cpython-devguide/badge/
4+
|ReadTheDocs| |Zulip| |Codestyle|
5+
6+
.. |ReadTheDocs| image:: https://readthedocs.org/projects/cpython-devguide/badge/
57
:target: https://devguide.python.org
68
:alt: Documentation Status
79

8-
.. image:: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
10+
.. |Zulip| image:: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
911
:alt: Python Zulip chat
1012
:target: https://python.zulipchat.com
11-
13+
14+
.. |Codestyle| image:: https://img.shields.io/badge/code%20style-black-000000.svg
15+
:target: https://github.com/ambv/black
16+
:alt: Code style is black
17+
1218

1319
This guide covers how to contribute to CPython. It is known by the
1420
nickname of "the devguide" by the Python core developers.

conf.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
master_doc = 'index'
4444

4545
# General information about the project.
46-
project = u'Python Developer\'s Guide'
47-
copyright = u'2011-%s, Python Software Foundation' % time.strftime('%Y')
46+
project = 'Python Developer\'s Guide'
47+
copyright = '2011-%s, Python Software Foundation' % time.strftime('%Y')
4848

4949
# The version info for the project you're documenting, acts as replacement for
5050
# |version| and |release|, also used in various other places throughout the
@@ -95,8 +95,8 @@
9595
# Use the upstream python-docs-theme
9696
html_theme = 'python_docs_theme'
9797
html_theme_options = {
98-
'collapsiblesidebar': True,
99-
'issues_url': 'https://github.com/python/devguide/issues/new',
98+
'collapsiblesidebar': True,
99+
'issues_url': 'https://github.com/python/devguide/issues/new',
100100
}
101101

102102

@@ -182,8 +182,13 @@
182182
# Grouping the document tree into LaTeX files. List of tuples
183183
# (source start file, target name, title, author, documentclass [howto/manual]).
184184
latex_documents = [
185-
('index', 'PythonDevelopersGuide.tex', u'Python Developer\'s Guide Documentation',
186-
u'Brett Cannon', 'manual'),
185+
(
186+
'index',
187+
'PythonDevelopersGuide.tex',
188+
'Python Developer\'s Guide Documentation',
189+
'Brett Cannon',
190+
'manual',
191+
),
187192
]
188193

189194
# The name of an image file (relative to this directory) to place at the top of
@@ -215,8 +220,13 @@
215220
# One entry per manual page. List of tuples
216221
# (source start file, name, description, authors, manual section).
217222
man_pages = [
218-
('index', 'pythondevelopersguide', u"Python Developer's Guide Documentation",
219-
[u'Brett Cannon'], 1)
223+
(
224+
'index',
225+
'pythondevelopersguide',
226+
"Python Developer's Guide Documentation",
227+
['Brett Cannon'],
228+
1,
229+
),
220230
]
221231

222232
# ignore linkcheck anchors for /#/$ANCHOR since it is used for

tools/rstlint.py

Lines changed: 122 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,110 @@
2020

2121
directives = [
2222
# standard docutils ones
23-
'admonition', 'attention', 'caution', 'class', 'compound', 'container',
24-
'contents', 'csv-table', 'danger', 'date', 'default-role', 'epigraph',
25-
'error', 'figure', 'footer', 'header', 'highlights', 'hint', 'image',
26-
'important', 'include', 'line-block', 'list-table', 'meta', 'note',
27-
'parsed-literal', 'pull-quote', 'raw', 'replace',
28-
'restructuredtext-test-directive', 'role', 'rubric', 'sectnum', 'sidebar',
29-
'table', 'target-notes', 'tip', 'title', 'topic', 'unicode', 'warning',
23+
'admonition',
24+
'attention',
25+
'caution',
26+
'class',
27+
'compound',
28+
'container',
29+
'contents',
30+
'csv-table',
31+
'danger',
32+
'date',
33+
'default-role',
34+
'epigraph',
35+
'error',
36+
'figure',
37+
'footer',
38+
'header',
39+
'highlights',
40+
'hint',
41+
'image',
42+
'important',
43+
'include',
44+
'line-block',
45+
'list-table',
46+
'meta',
47+
'note',
48+
'parsed-literal',
49+
'pull-quote',
50+
'raw',
51+
'replace',
52+
'restructuredtext-test-directive',
53+
'role',
54+
'rubric',
55+
'sectnum',
56+
'sidebar',
57+
'table',
58+
'target-notes',
59+
'tip',
60+
'title',
61+
'topic',
62+
'unicode',
63+
'warning',
3064
# Sphinx and Python docs custom ones
31-
'acks', 'attribute', 'autoattribute', 'autoclass', 'autodata',
32-
'autoexception', 'autofunction', 'automethod', 'automodule', 'centered',
33-
'cfunction', 'class', 'classmethod', 'cmacro', 'cmdoption', 'cmember',
34-
'code-block', 'confval', 'cssclass', 'ctype', 'currentmodule', 'cvar',
35-
'data', 'decorator', 'decoratormethod', 'deprecated-removed',
36-
'deprecated(?!-removed)', 'describe', 'directive', 'doctest', 'envvar',
37-
'event', 'exception', 'function', 'glossary', 'highlight', 'highlightlang',
38-
'impl-detail', 'index', 'literalinclude', 'method', 'miscnews', 'module',
39-
'moduleauthor', 'opcode', 'pdbcommand', 'productionlist',
40-
'program', 'role', 'sectionauthor', 'seealso', 'sourcecode', 'staticmethod',
41-
'tabularcolumns', 'testcode', 'testoutput', 'testsetup', 'toctree', 'todo',
42-
'todolist', 'versionadded', 'versionchanged'
65+
'acks',
66+
'attribute',
67+
'autoattribute',
68+
'autoclass',
69+
'autodata',
70+
'autoexception',
71+
'autofunction',
72+
'automethod',
73+
'automodule',
74+
'centered',
75+
'cfunction',
76+
'class',
77+
'classmethod',
78+
'cmacro',
79+
'cmdoption',
80+
'cmember',
81+
'code-block',
82+
'confval',
83+
'cssclass',
84+
'ctype',
85+
'currentmodule',
86+
'cvar',
87+
'data',
88+
'decorator',
89+
'decoratormethod',
90+
'deprecated-removed',
91+
'deprecated(?!-removed)',
92+
'describe',
93+
'directive',
94+
'doctest',
95+
'envvar',
96+
'event',
97+
'exception',
98+
'function',
99+
'glossary',
100+
'highlight',
101+
'highlightlang',
102+
'impl-detail',
103+
'index',
104+
'literalinclude',
105+
'method',
106+
'miscnews',
107+
'module',
108+
'moduleauthor',
109+
'opcode',
110+
'pdbcommand',
111+
'productionlist',
112+
'program',
113+
'role',
114+
'sectionauthor',
115+
'seealso',
116+
'sourcecode',
117+
'staticmethod',
118+
'tabularcolumns',
119+
'testcode',
120+
'testoutput',
121+
'testsetup',
122+
'toctree',
123+
'todo',
124+
'todolist',
125+
'versionadded',
126+
'versionchanged',
43127
]
44128

45129
all_directives = '(' + '|'.join(directives) + ')'
@@ -55,12 +139,14 @@
55139

56140
def checker(*suffixes, **kwds):
57141
"""Decorator to register a function as a checker."""
142+
58143
def deco(func):
59144
for suffix in suffixes:
60145
checkers.setdefault(suffix, []).append(func)
61146
for prop in checker_props:
62147
setattr(func, prop, kwds.get(prop, checker_props[prop]))
63148
return func
149+
64150
return deco
65151

66152

@@ -84,11 +170,11 @@ def check_suspicious_constructs(fn, lines):
84170
inprod = False
85171
for lno, line in enumerate(lines):
86172
if seems_directive_re.search(line):
87-
yield lno+1, 'comment seems to be intended as a directive'
173+
yield lno + 1, 'comment seems to be intended as a directive'
88174
if '.. productionlist::' in line:
89175
inprod = True
90176
elif not inprod and default_role_re.search(line):
91-
yield lno+1, 'default role used'
177+
yield lno + 1, 'default role used'
92178
elif inprod and not line.strip():
93179
inprod = False
94180

@@ -98,11 +184,11 @@ def check_whitespace(fn, lines):
98184
"""Check for whitespace and line length issues."""
99185
for lno, line in enumerate(lines):
100186
if '\r' in line:
101-
yield lno+1, '\\r in line'
187+
yield lno + 1, '\\r in line'
102188
if '\t' in line:
103-
yield lno+1, 'OMG TABS!!!1'
189+
yield lno + 1, 'OMG TABS!!!1'
104190
if line[:-1].rstrip(' \t') != line[:-1]:
105-
yield lno+1, 'trailing whitespace'
191+
yield lno + 1, 'trailing whitespace'
106192

107193

108194
@checker('.rst', severity=0)
@@ -111,12 +197,14 @@ def check_line_length(fn, lines):
111197
for lno, line in enumerate(lines):
112198
if len(line) > 81:
113199
# don't complain about tables, links and function signatures
114-
if line.lstrip()[0] not in '+|' and \
115-
'http://' not in line and \
116-
not line.lstrip().startswith(('.. function',
117-
'.. method',
118-
'.. cfunction')):
119-
yield lno+1, "line too long"
200+
if (
201+
line.lstrip()[0] not in '+|'
202+
and 'http://' not in line
203+
and not line.lstrip().startswith(
204+
('.. function', '.. method', '.. cfunction')
205+
)
206+
):
207+
yield lno + 1, "line too long"
120208

121209

122210
@checker('.html', severity=2, falsepositives=True)
@@ -126,7 +214,7 @@ def check_leaked_markup(fn, lines):
126214
"""
127215
for lno, line in enumerate(lines):
128216
if leaked_markup_re.search(line):
129-
yield lno+1, 'possibly leaked markup: %r' % line
217+
yield lno + 1, 'possibly leaked markup: %r' % line
130218

131219

132220
def main(argv):
@@ -137,7 +225,8 @@ def main(argv):
137225
-f enable checkers that yield many false positives
138226
-s sev only show problems with severity >= sev
139227
-i path ignore subdir or file path
140-
'''% argv[0]
228+
''' % argv[0]
229+
141230
try:
142231
gopts, args = getopt.getopt(argv[1:], 'vfs:i:')
143232
except getopt.GetoptError:
@@ -222,7 +311,7 @@ def main(argv):
222311
for severity in sorted(count):
223312
number = count[severity]
224313
print('%d problem%s with severity %d found.' %
225-
(number, number > 1 and 's' or '', severity))
314+
(number, 's' if number > 1 else '', severity))
226315
return int(bool(count))
227316

228317

tools/serve.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,3 @@ def app(environ, respond):
3535
httpd.serve_forever()
3636
except KeyboardInterrupt:
3737
print("\b\bShutting down.")
38-

0 commit comments

Comments
 (0)