1. cherrypy
  2. CherryPy

Commits

Gustavo Picon  committed 28b0a05

Let’s pep8ify even the sphinx scripts

  • Participants
  • Parent commits 4fa4a82
  • Branches default

Comments (0)

Files changed (4)

File sphinx/source/conf.py

View file
 # CherryPy documentation build configuration file, created by
 # sphinx-quickstart on Sat Feb 20 09:18:03 2010.
 #
-# This file is execfile()d with the current directory set to its containing dir.
+# This file is execfile()d with the current directory set to its containing
+# dir.
 #
 # Note that not all possible configuration values are present in this
 # autogenerated file.
 # All configuration values have a default; values that are commented out
 # serve to show the default.
 
-import sys, os
+import sys
+import os
 
 # If extensions (or modules to document with autodoc) are in another directory,
 # add these directories to sys.path here. If the directory is relative to the
 # documentation root, use os.path.abspath to make it absolute, like shown here.
-#sys.path.append(os.path.abspath('.'))
+# sys.path.append(os.path.abspath('.'))
 
-# -- General configuration -----------------------------------------------------
+# -- General configuration -----------------------------------------------
 
-# Add any Sphinx extension module names here, as strings. They can be extensions
-# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
-extensions = ['sphinx.ext.autodoc', 'sphinx.ext.todo', 'sphinx.ext.intersphinx']
+# Add any Sphinx extension module names here, as strings. They can be
+# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
+extensions = ['sphinx.ext.autodoc',
+              'sphinx.ext.todo', 'sphinx.ext.intersphinx']
 intersphinx_mapping = {'http://docs.python.org/2/': None}
 
 # Add any paths that contain templates here, relative to this directory.
 # for source files.
 exclude_trees = []
 
-# The reST default role (used for this markup: `text`) to use for all documents.
+# The reST default role (used for this markup: `text`) to use for all
+# documents.
 #default_role = None
 
 # If true, '()' will be appended to :func: etc. cross-reference text.
 #modindex_common_prefix = []
 
 
-# -- Options for HTML output ---------------------------------------------------
+# -- Options for HTML output ---------------------------------------------
 
 # The theme to use for HTML and HTML Help pages.  Major themes that come with
 # Sphinx are currently 'default' and 'sphinxdoc'.
 # further.  For a list of options available for each theme, see the
 # documentation.
 # html_theme_options = {
-#     "relbarbgcolor": "#880000",
+# "relbarbgcolor": "#880000",
 #     "relbartextcolor": "white",
-#     "relbarlinkcolor": "#FFEEEE",
-#     "sidebarbgcolor": "#880000",
+# "relbarlinkcolor": "#FFEEEE",
+# "sidebarbgcolor": "#880000",
 #     "sidebartextcolor": "white",
-#     "sidebarlinkcolor": "#FFEEEE",
-#     "headbgcolor": "#FFF8FB",
+# "sidebarlinkcolor": "#FFEEEE",
+# "headbgcolor": "#FFF8FB",
 #     "headtextcolor": "black",
-#     "headlinkcolor": "#660000",
-#     "footerbgcolor": "#880000",
+# "headlinkcolor": "#660000",
+# "footerbgcolor": "#880000",
 #     "footertextcolor": "white",
-#     "codebgcolor": "#FFEEEE",
+# "codebgcolor": "#FFEEEE",
 # }
 
 # Add any paths that contain custom themes here, relative to this directory.
 htmlhelp_basename = 'CherryPydoc'
 
 
-# -- Options for LaTeX output --------------------------------------------------
+# -- Options for LaTeX output --------------------------------------------
 
 # The paper size ('letter' or 'a4').
 #latex_paper_size = 'letter'
 #latex_font_size = '10pt'
 
 # Grouping the document tree into LaTeX files. List of tuples
-# (source start file, target name, title, author, documentclass [howto/manual]).
+# (source start file, target name, title, author,
+# documentclass [howto/manual]).
 latex_documents = [
-  ('index', 'CherryPy.tex', u'CherryPy Documentation',
-   u'CherryPy Team', 'manual'),
+    ('index', 'CherryPy.tex', u'CherryPy Documentation',
+     u'CherryPy Team', 'manual'),
 ]
 
 # The name of an image file (relative to this directory) to place at the top of
     # it can't import pywin32. See:
     # http://read-the-docs.readthedocs.org/en/latest/faq.html#i-get-import-errors-on-libraries-that-depend-on-c-modules
     import sys
-    
+
     class Mock(object):
+
         def __init__(self, *args, **kwargs):
             pass
-        
+
         def __call__(self, *args, **kwargs):
             return Mock()
-        
+
         @classmethod
         def __getattr__(cls, name):
             if name in ('__file__', '__path__'):

File sphinx/source/tutorial/files/songs.py

View file
     }
 }
 
+
 class Songs:
 
     exposed = True
 
     def GET(self, id=None):
 
-        if id == None:
+        if id is None:
             return('Here are all the songs we have: %s' % songs)
         elif id in songs:
             song = songs[id]
 
-            return('Song with the ID %s is called %s, and the artist is %s' % (id, song['title'], song['artist']))
+            return(
+                'Song with the ID %s is called %s, and the artist is %s' % (
+                    id, song['title'], song['artist']))
         else:
             return('No song with the ID %s :-(' % id)
 
             song['title'] = title or song['title']
             song['artist'] = artist or song['artist']
 
-            return('Song with the ID %s is now called %s, and the artist is now %s' % (id, song['title'], song['artist']))
+            return(
+                'Song with the ID %s is now called %s, '
+                'and the artist is now %s' % (
+                    id, song['title'], song['artist'])
+            )
         else:
             return('No song with the ID %s :-(' % id)
 
         Songs(), '/api/songs',
         {'/':
             {'request.dispatch': cherrypy.dispatch.MethodDispatcher()}
-        }
+         }
     )
 
     cherrypy.engine.start()

File sphinx/util/convert-trac.py

View file
 import urllib2
 from StringIO import StringIO
 
+
 def get_options():
-	global options
-	parser = optparse.OptionParser(usage=inspect.cleandoc(__doc__))
-	parser.add_option('-U', '--url', help="Trac URL from which to retrieve source")
-	options, args = parser.parse_args()
-	try:
-		options.filename = args.pop()
-	except IndexError:
-		parser.error("Filename required")
+    global options
+    parser = optparse.OptionParser(usage=inspect.cleandoc(__doc__))
+    parser.add_option('-U', '--url',
+                      help="Trac URL from which to retrieve source")
+    options, args = parser.parse_args()
+    try:
+        options.filename = args.pop()
+    except IndexError:
+        parser.error("Filename required")
 
 # each of the replacement functions should have a docstring
 #  which is a regular expression to be matched.
 
+
 def replace_external_link(matcher):
-	r"\[(?P<href>(?P<scheme>\w+)\://.+?) (?P<name>.+?)\]"
-	return '`{name} <{href}>`_'.format(**matcher.groupdict())
+    r"\[(?P<href>(?P<scheme>\w+)\://.+?) (?P<name>.+?)\]"
+    return '`{name} <{href}>`_'.format(**matcher.groupdict())
+
 
 def replace_wiki_link(matcher):
-	r"\[wiki\:(?P<ref>.+?) (?P<name>.+?)\]"
-	return '`{name} <TODO-fix wiki target {ref}>`_'.format(**matcher.groupdict())
+    r"\[wiki\:(?P<ref>.+?) (?P<name>.+?)\]"
+    return '`{name} <TODO-fix wiki target {ref}>`_'.format(
+        **matcher.groupdict()
+    )
 
 # character array indexed by level for characters
 heading_characters = [None, '*', '=', '-', '^']
 
+
 def replace_headings(matcher):
-	r"^(?P<level>=+) (?P<name>.*) (?P=level)$"
-	level = len(matcher.groupdict()['level'])
-	char = heading_characters[level]
-	name = matcher.groupdict()['name']
-	lines = [name, char*len(name)]
-	if level == 1:
-		lines.insert(0, char*len(name))
-	return '\n'.join(lines)
+    r"^(?P<level>=+) (?P<name>.*) (?P=level)$"
+    level = len(matcher.groupdict()['level'])
+    char = heading_characters[level]
+    name = matcher.groupdict()['name']
+    lines = [name, char * len(name)]
+    if level == 1:
+        lines.insert(0, char * len(name))
+    return '\n'.join(lines)
+
 
 def indent(block):
-	add_indent = lambda s: '    ' + s
-	lines = StringIO(block)
-	i_lines = map(add_indent, lines)
-	return ''.join(i_lines)
+    add_indent = lambda s: '    ' + s
+    lines = StringIO(block)
+    i_lines = map(add_indent, lines)
+    return ''.join(i_lines)
+
 
 def replace_inline_code(matcher):
-	r"\{\{\{(?P<code>[^\n]*?)\}\}\}"
-	return '``{code}``'.format(**matcher.groupdict())
+    r"\{\{\{(?P<code>[^\n]*?)\}\}\}"
+    return '``{code}``'.format(**matcher.groupdict())
+
 
 def replace_code_block(matcher):
-	r"\{\{\{\n(?P<code>(.|\n)*?)^\}\}\}"
-	return '::\n\n' + indent(matcher.groupdict()['code'])
+    r"\{\{\{\n(?P<code>(.|\n)*?)^\}\}\}"
+    return '::\n\n' + indent(matcher.groupdict()['code'])
+
 
 def replace_page_outline(matcher):
-	r"\[\[PageOutline\]\]\n"
-	return ''
+    r"\[\[PageOutline\]\]\n"
+    return ''
+
 
 def replace_bang_symbols(matcher):
-	r"!(?P<symbol>\w+)"
-	return matcher.groupdict()['symbol']
+    r"!(?P<symbol>\w+)"
+    return matcher.groupdict()['symbol']
 
 # a number of the files end in
 """{{{
 #!html
 <h2 class='compatibility'>Older versions</h2>
-}}}""" # and everything after is garbage, so just remove it.
+}}}"""  # and everything after is garbage, so just remove it.
+
+
 def remove_2x_compat_notes(matcher):
-	r"\{\{\{\n#!html\n<h2(.|\n)*"
-	return ''
+    r"\{\{\{\n#!html\n<h2(.|\n)*"
+    return ''
 
 replacements = [remove_2x_compat_notes] + \
-	[func for name, func in globals().items() if name.startswith('replace_')]
+    [func for name,
+     func in globals().items() if name.startswith('replace_')]
+
 
 def normalize_linebreaks(text):
-	return text.replace('\r\n', '\n')
+    return text.replace('\r\n', '\n')
+
 
 def convert_file():
-	filename = options.filename
-	if options.url:
-		text = urllib2.urlopen(options.url).read()
-		text = normalize_linebreaks(text)
-	else:
-		shutil.copy(filename, filename+'.bak')
-		text = open(filename).read()
-	# iterate over each of the replacements and execute it
-	new_text = text
-	for repl in replacements:
-		pattern = re.compile(inspect.getdoc(repl), re.MULTILINE)
-		new_text = pattern.sub(repl, new_text)
+    filename = options.filename
+    if options.url:
+        text = urllib2.urlopen(options.url).read()
+        text = normalize_linebreaks(text)
+    else:
+        shutil.copy(filename, filename + '.bak')
+        text = open(filename).read()
+    # iterate over each of the replacements and execute it
+    new_text = text
+    for repl in replacements:
+        pattern = re.compile(inspect.getdoc(repl), re.MULTILINE)
+        new_text = pattern.sub(repl, new_text)
 
-	open(filename, 'w').write(new_text)
-	print("done")
+    open(filename, 'w').write(new_text)
+    print("done")
 
 
 def handle_command_line():
-	get_options()
-	convert_file()
+    get_options()
+    convert_file()
 
 if __name__ == '__main__':
-	handle_command_line()
+    handle_command_line()

File sphinx/util/test-doc.py

View file
 import docutils.parsers.rst
 from StringIO import StringIO
 
+
 def print_with_line_numbers(block):
-	stream = StringIO(block)
-	for number, line in enumerate(stream):
-		number += 1
-		print(number, line.rstrip())
+    stream = StringIO(block)
+    for number, line in enumerate(stream):
+        number += 1
+        print(number, line.rstrip())
 
 target_class_spec = sys.argv[1]
 import cherrypy
 source = inspect.getdoc(target_class)
 print_with_line_numbers(source)
 parser = docutils.parsers.rst.Parser()
-settings = None ## ?
+settings = None  # ?
 document = docutils.utils.new_document(source, settings)
 parser.parse(source, document)