Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use black for python codestyle #386

Merged
merged 7 commits into from Sep 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions README.rst
@@ -1,14 +1,20 @@
The CPython Developer's Guide
=============================

.. image:: https://readthedocs.org/projects/cpython-devguide/badge/
|ReadTheDocs| |Zulip| |Codestyle|

.. |ReadTheDocs| image:: https://readthedocs.org/projects/cpython-devguide/badge/
:target: https://devguide.python.org
:alt: Documentation Status

.. image:: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
.. |Zulip| image:: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
:alt: Python Zulip chat
:target: https://python.zulipchat.com


.. |Codestyle| image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/ambv/black
:alt: Code style is black


This guide covers how to contribute to CPython. It is known by the
nickname of "the devguide" by the Python core developers.
Expand Down
26 changes: 18 additions & 8 deletions conf.py
Expand Up @@ -43,8 +43,8 @@
master_doc = 'index'

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

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


Expand Down Expand Up @@ -182,8 +182,13 @@
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'PythonDevelopersGuide.tex', u'Python Developer\'s Guide Documentation',
u'Brett Cannon', 'manual'),
(
'index',
'PythonDevelopersGuide.tex',
'Python Developer\'s Guide Documentation',
'Brett Cannon',
'manual',
),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -215,8 +220,13 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'pythondevelopersguide', u"Python Developer's Guide Documentation",
[u'Brett Cannon'], 1)
(
'index',
'pythondevelopersguide',
"Python Developer's Guide Documentation",
['Brett Cannon'],
1,
),
]

# ignore linkcheck anchors for /#/$ANCHOR since it is used for
Expand Down
155 changes: 122 additions & 33 deletions tools/rstlint.py
Expand Up @@ -20,26 +20,110 @@

directives = [
# standard docutils ones
'admonition', 'attention', 'caution', 'class', 'compound', 'container',
'contents', 'csv-table', 'danger', 'date', 'default-role', 'epigraph',
'error', 'figure', 'footer', 'header', 'highlights', 'hint', 'image',
'important', 'include', 'line-block', 'list-table', 'meta', 'note',
'parsed-literal', 'pull-quote', 'raw', 'replace',
'restructuredtext-test-directive', 'role', 'rubric', 'sectnum', 'sidebar',
'table', 'target-notes', 'tip', 'title', 'topic', 'unicode', 'warning',
'admonition',
'attention',
'caution',
'class',
'compound',
'container',
'contents',
'csv-table',
'danger',
'date',
'default-role',
'epigraph',
'error',
'figure',
'footer',
'header',
'highlights',
'hint',
'image',
'important',
'include',
'line-block',
'list-table',
'meta',
'note',
'parsed-literal',
'pull-quote',
'raw',
'replace',
'restructuredtext-test-directive',
'role',
'rubric',
'sectnum',
'sidebar',
'table',
'target-notes',
'tip',
'title',
'topic',
'unicode',
'warning',
# Sphinx and Python docs custom ones
'acks', 'attribute', 'autoattribute', 'autoclass', 'autodata',
'autoexception', 'autofunction', 'automethod', 'automodule', 'centered',
'cfunction', 'class', 'classmethod', 'cmacro', 'cmdoption', 'cmember',
'code-block', 'confval', 'cssclass', 'ctype', 'currentmodule', 'cvar',
'data', 'decorator', 'decoratormethod', 'deprecated-removed',
'deprecated(?!-removed)', 'describe', 'directive', 'doctest', 'envvar',
'event', 'exception', 'function', 'glossary', 'highlight', 'highlightlang',
'impl-detail', 'index', 'literalinclude', 'method', 'miscnews', 'module',
'moduleauthor', 'opcode', 'pdbcommand', 'productionlist',
'program', 'role', 'sectionauthor', 'seealso', 'sourcecode', 'staticmethod',
'tabularcolumns', 'testcode', 'testoutput', 'testsetup', 'toctree', 'todo',
'todolist', 'versionadded', 'versionchanged'
'acks',
'attribute',
'autoattribute',
'autoclass',
'autodata',
'autoexception',
'autofunction',
'automethod',
'automodule',
'centered',
'cfunction',
'class',
'classmethod',
'cmacro',
'cmdoption',
'cmember',
'code-block',
'confval',
'cssclass',
'ctype',
'currentmodule',
'cvar',
'data',
'decorator',
'decoratormethod',
'deprecated-removed',
'deprecated(?!-removed)',
'describe',
'directive',
'doctest',
'envvar',
'event',
'exception',
'function',
'glossary',
'highlight',
'highlightlang',
'impl-detail',
'index',
'literalinclude',
'method',
'miscnews',
'module',
'moduleauthor',
'opcode',
'pdbcommand',
'productionlist',
'program',
'role',
'sectionauthor',
'seealso',
'sourcecode',
'staticmethod',
'tabularcolumns',
'testcode',
'testoutput',
'testsetup',
'toctree',
'todo',
'todolist',
'versionadded',
'versionchanged',
willingc marked this conversation as resolved.
Show resolved Hide resolved
]

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

def checker(*suffixes, **kwds):
"""Decorator to register a function as a checker."""

def deco(func):
for suffix in suffixes:
checkers.setdefault(suffix, []).append(func)
for prop in checker_props:
setattr(func, prop, kwds.get(prop, checker_props[prop]))
return func

return deco


Expand All @@ -84,11 +170,11 @@ def check_suspicious_constructs(fn, lines):
inprod = False
for lno, line in enumerate(lines):
if seems_directive_re.search(line):
yield lno+1, 'comment seems to be intended as a directive'
yield lno + 1, 'comment seems to be intended as a directive'
if '.. productionlist::' in line:
inprod = True
elif not inprod and default_role_re.search(line):
yield lno+1, 'default role used'
yield lno + 1, 'default role used'
elif inprod and not line.strip():
inprod = False

Expand All @@ -98,11 +184,11 @@ def check_whitespace(fn, lines):
"""Check for whitespace and line length issues."""
for lno, line in enumerate(lines):
if '\r' in line:
yield lno+1, '\\r in line'
yield lno + 1, '\\r in line'
if '\t' in line:
yield lno+1, 'OMG TABS!!!1'
yield lno + 1, 'OMG TABS!!!1'
if line[:-1].rstrip(' \t') != line[:-1]:
yield lno+1, 'trailing whitespace'
yield lno + 1, 'trailing whitespace'


@checker('.rst', severity=0)
Expand All @@ -111,12 +197,14 @@ def check_line_length(fn, lines):
for lno, line in enumerate(lines):
if len(line) > 81:
# don't complain about tables, links and function signatures
if line.lstrip()[0] not in '+|' and \
'http://' not in line and \
not line.lstrip().startswith(('.. function',
'.. method',
'.. cfunction')):
yield lno+1, "line too long"
if (
line.lstrip()[0] not in '+|'
and 'http://' not in line
and not line.lstrip().startswith(
('.. function', '.. method', '.. cfunction')
willingc marked this conversation as resolved.
Show resolved Hide resolved
)
):
yield lno + 1, "line too long"


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


def main(argv):
Expand All @@ -137,7 +225,8 @@ def main(argv):
-f enable checkers that yield many false positives
-s sev only show problems with severity >= sev
-i path ignore subdir or file path
'''% argv[0]
''' % argv[0]

try:
gopts, args = getopt.getopt(argv[1:], 'vfs:i:')
except getopt.GetoptError:
Expand Down Expand Up @@ -222,7 +311,7 @@ def main(argv):
for severity in sorted(count):
number = count[severity]
print('%d problem%s with severity %d found.' %
(number, number > 1 and 's' or '', severity))
(number, 's' if number > 1 else '', severity))
return int(bool(count))


Expand Down
1 change: 0 additions & 1 deletion tools/serve.py
Expand Up @@ -35,4 +35,3 @@ def app(environ, respond):
httpd.serve_forever()
except KeyboardInterrupt:
print("\b\bShutting down.")