Add py files in doc directories to pep8 check

Change-Id: Idb4f8864ab51f5e4ee2eef7745d40d5d8b5e57ce
This commit is contained in:
chenhb-zte 2017-04-01 11:13:03 +08:00
parent c63ba779ae
commit 16809b37a7
10 changed files with 93 additions and 97 deletions

View File

@ -21,8 +21,7 @@ from docutils.parsers import rst
from rally.cli import cliutils from rally.cli import cliutils
from rally.cli import main from rally.cli import main
from rally.cli import manage from rally.cli import manage
from utils import (category, subcategory, hint, make_definition, note, import utils
paragraph, parse_text, warning)
class Parser(object): class Parser(object):
@ -73,22 +72,24 @@ DEFAULT_UUIDS_CMD = {
def compose_note_about_default_uuids(argument, dest): def compose_note_about_default_uuids(argument, dest):
# TODO(andreykurilin): add references to commands # TODO(andreykurilin): add references to commands
return note("The default value for the ``%(arg)s`` argument is taken from " return utils.note(
"the Rally environment. Usually, the default value is equal to" "The default value for the ``%(arg)s`` argument is taken from "
" the UUID of the last successful run of ``%(cmd)s``, if the " "the Rally environment. Usually, the default value is equal to"
"``--no-use`` argument was not used." % { " the UUID of the last successful run of ``%(cmd)s``, if the "
"arg": argument, "``--no-use`` argument was not used." % {
"cmd": "``, ``".join(DEFAULT_UUIDS_CMD[dest])}) "arg": argument,
"cmd": "``, ``".join(DEFAULT_UUIDS_CMD[dest])})
def compose_use_cmd_hint_msg(cmd): def compose_use_cmd_hint_msg(cmd):
return hint("You can set the default value by executing ``%(cmd)s <uuid>``" return utils.hint(
" (ref__).\n\n __ #%(ref)s" % {"cmd": cmd, "You can set the default value by executing ``%(cmd)s <uuid>``"
"ref": cmd.replace(" ", "-")}) " (ref__).\n\n __ #%(ref)s" % {"cmd": cmd,
"ref": cmd.replace(" ", "-")})
def make_arguments_section(category_name, cmd_name, arguments, defaults): def make_arguments_section(category_name, cmd_name, arguments, defaults):
elements = [paragraph("**Command arguments**:")] elements = [utils.paragraph("**Command arguments**:")]
for args, kwargs in arguments: for args, kwargs in arguments:
# for future changes... # for future changes...
# :param args: a single command argument which can represented by # :param args: a single command argument which can represented by
@ -109,14 +110,14 @@ def make_arguments_section(category_name, cmd_name, arguments, defaults):
# "use" command with reference # "use" command with reference
if dest in ("deployment", "task"): if dest in ("deployment", "task"):
description.append(compose_note_about_default_uuids( description.append(compose_note_about_default_uuids(
args[0], dest)) args[0], dest))
description.append( description.append(
compose_use_cmd_hint_msg("rally %s use" % dest)) compose_use_cmd_hint_msg("rally %s use" % dest))
elif dest == "verification": elif dest == "verification":
description.append(compose_note_about_default_uuids( description.append(compose_note_about_default_uuids(
args[0], dest)) args[0], dest))
description.append( description.append(
compose_use_cmd_hint_msg("rally verify use")) compose_use_cmd_hint_msg("rally verify use"))
description.append(kwargs.get("help")) description.append(kwargs.get("help"))
@ -138,7 +139,8 @@ def make_arguments_section(category_name, cmd_name, arguments, defaults):
if metavar: if metavar:
args = ["%s %s" % (arg, metavar) for arg in args] args = ["%s %s" % (arg, metavar) for arg in args]
elements.extend(make_definition(", ".join(args), ref, description)) elements.extend(utils.make_definition(", ".join(args),
ref, description))
return elements return elements
@ -154,8 +156,8 @@ def make_command_section(category_name, name, parser):
# NOTE(andreykurilin): there is only one category in rally-manage, so # NOTE(andreykurilin): there is only one category in rally-manage, so
# let's just hardcode it. # let's just hardcode it.
cmd = "rally-manage" if category_name == "db" else "rally" cmd = "rally-manage" if category_name == "db" else "rally"
section = subcategory("%s %s %s" % (cmd, category_name, name)) section = utils.subcategory("%s %s %s" % (cmd, category_name, name))
section.extend(parse_text(parser["description"])) section.extend(utils.parse_text(parser["description"]))
if parser["parser"].arguments: if parser["parser"].arguments:
defaults = get_defaults(parser["parser"].defaults["action_fn"]) defaults = get_defaults(parser["parser"].defaults["action_fn"])
section.extend(make_arguments_section( section.extend(make_arguments_section(
@ -164,7 +166,7 @@ def make_command_section(category_name, name, parser):
def make_category_section(name, parser): def make_category_section(name, parser):
category_obj = category("Category: %s" % name) category_obj = utils.category("Category: %s" % name)
# NOTE(andreykurilin): we are re-using `_add_command_parsers` method from # NOTE(andreykurilin): we are re-using `_add_command_parsers` method from
# `rally.cli.cliutils`, but, since it was designed to print help message, # `rally.cli.cliutils`, but, since it was designed to print help message,
# generated description for categories contains specification for all # generated description for categories contains specification for all
@ -177,9 +179,9 @@ def make_category_section(name, parser):
if description.startswith("[Deprecated"): if description.startswith("[Deprecated"):
i = description.find("]") i = description.find("]")
msg = description[1:i] msg = description[1:i]
description = description[i+1:].strip() description = description[i + 1:].strip()
category_obj.append(warning(msg)) category_obj.append(utils.warning(msg))
category_obj.extend(parse_text(description)) category_obj.extend(utils.parse_text(description))
for command in sorted(parser.subparser.parsers.keys()): for command in sorted(parser.subparser.parsers.keys()):
subparser = parser.subparser.parsers[command] subparser = parser.subparser.parsers[command]
@ -196,14 +198,14 @@ class CLIReferenceDirective(rst.Directive):
categories = copy.copy(main.categories) categories = copy.copy(main.categories)
categories["db"] = manage.DBCommands categories["db"] = manage.DBCommands
if "group" in self.options: if "group" in self.options:
categories = {k: v for k,v in categories.items() categories = {k: v for k, v in categories.items()
if k == self.options["group"]} if k == self.options["group"]}
cliutils._add_command_parsers(categories, parser) cliutils._add_command_parsers(categories, parser)
content = [] content = []
for category in sorted(categories.keys()): for cg in sorted(categories.keys()):
content.append(make_category_section( content.append(make_category_section(
category, parser.parsers[category]["parser"])) cg, parser.parsers[cg]["parser"]))
return content return content

View File

@ -21,27 +21,26 @@ from oslo_utils import importutils
def include_var(name, rawtext, text, lineno, inliner, options=None, def include_var(name, rawtext, text, lineno, inliner, options=None,
content=None): content=None):
""" """include variable
:param name: The local name of the interpreted role, the role name :param name: The local name of the interpreted role, the role name
actually used in the document. actually used in the document.
:param rawtext: A string containing the enitre interpreted text input, :param rawtext: A string containing the enitre interpreted text input,
including the role and markup. Return it as a problematic node including the role and markup. Return it as a problematic
linked to a system message if a problem is encountered. node linked to a system message if a problem is
encountered.
:param text: The interpreted text content. :param text: The interpreted text content.
:param lineno: The line number where the interpreted text begins. :param lineno: The line number where the interpreted text begins.
:param inliner: The docutils.parsers.rst.states.Inliner object that :param inliner: The docutils.parsers.rst.states.Inliner object that
called include_var. It contains the several attributes useful for called include_var. It contains the several attributes
error reporting and document tree access. useful for error reporting and document tree access.
:param options: A dictionary of directive options for customization :param options: A dictionary of directive options for customization
(from the "role" directive), to be interpreted by the role function. (from the 'role' directive), to be interpreted by the
Used for additional attributes for the generated elements and other role function. Used for additional attributes for the
functionality. generated elements and other functionality.
:param content: A list of strings, the directive content for :param content: A list of strings, the directive content for
customization (from the "role" directive). To be interpreted by the customization (from the 'role' directive). To be
role function. interpreted by the role function.
:return: :return:
""" """
obj = importutils.import_class(text) obj = importutils.import_class(text)

View File

@ -21,8 +21,7 @@ import re
from rally.common.plugin import discover from rally.common.plugin import discover
from rally.common.plugin import plugin from rally.common.plugin import plugin
from rally import plugins from rally import plugins
from utils import category, subcategory, section, paragraph, parse_text, \ import utils
make_definitions, note
JSON_SCHEMA_TYPES_MAP = {"boolean": "bool", JSON_SCHEMA_TYPES_MAP = {"boolean": "bool",
@ -210,26 +209,26 @@ class PluginsReferenceDirective(rst.Directive):
if "type" in item: if "type" in item:
iname += " (%s)" % item["type"] iname += " (%s)" % item["type"]
terms.append((iname, [item["doc"]])) terms.append((iname, [item["doc"]]))
return make_definitions(title=title, return utils.make_definitions(title=title,
ref_prefix=ref_prefix, ref_prefix=ref_prefix,
terms=terms, terms=terms,
descriptions=description) descriptions=description)
def _make_plugin_section(self, plugin_cls, base_name=None): def _make_plugin_section(self, plugin_cls, base_name=None):
section_name = plugin_cls.get_name() section_name = plugin_cls.get_name()
if base_name: if base_name:
section_name += " [%s]" % base_name section_name += " [%s]" % base_name
section_obj = section(section_name) section_obj = utils.section(section_name)
info = plugin_cls.get_info() info = plugin_cls.get_info()
if info["title"]: if info["title"]:
section_obj.append(paragraph(info["title"])) section_obj.append(utils.paragraph(info["title"]))
if info["description"]: if info["description"]:
section_obj.extend(parse_text(info["description"])) section_obj.extend(utils.parse_text(info["description"]))
if info["namespace"]: if info["namespace"]:
section_obj.append(paragraph( section_obj.append(utils.paragraph(
"**Namespace**: %s" % info["namespace"])) "**Namespace**: %s" % info["namespace"]))
if base_name: if base_name:
@ -242,7 +241,7 @@ class PluginsReferenceDirective(rst.Directive):
ref_prefix)) ref_prefix))
if info["returns"]: if info["returns"]:
section_obj.extend(parse_text( section_obj.extend(utils.parse_text(
"**Returns**:\n%s" % info["returns"])) "**Returns**:\n%s" % info["returns"]))
if info["schema"]: if info["schema"]:
@ -259,8 +258,9 @@ class PluginsReferenceDirective(rst.Directive):
description=["*Dictionary is expected. Keys should " description=["*Dictionary is expected. Keys should "
"follow pattern(s) described bellow.*"])) "follow pattern(s) described bellow.*"]))
elif "oneOf" in schema: elif "oneOf" in schema:
section_obj.append(note("One of the following groups of " section_obj.append(utils.note(
"parameters should be provided.")) "One of the following groups of "
"parameters should be provided."))
for i, oneOf in enumerate(schema["oneOf"], 1): for i, oneOf in enumerate(schema["oneOf"], 1):
description = None description = None
if oneOf.get("doc", None): if oneOf.get("doc", None):
@ -279,15 +279,15 @@ class PluginsReferenceDirective(rst.Directive):
filename = info["module"].replace(".", "/") filename = info["module"].replace(".", "/")
ref = "https://github.com/openstack/rally/blob/master/%s.py" % filename ref = "https://github.com/openstack/rally/blob/master/%s.py" % filename
section_obj.extend(parse_text("**Module**:\n`%s`__\n\n__ %s" section_obj.extend(utils.parse_text("**Module**:\n`%s`__\n\n__ %s"
% (info["module"], ref))) % (info["module"], ref)))
return section_obj return section_obj
def _make_plugin_base_section(self, base_cls, base_name=None): def _make_plugin_base_section(self, base_cls, base_name=None):
if base_name: if base_name:
title = ("%ss" % base_name if base_name[-1] != "y" title = ("%ss" % base_name if base_name[-1] != "y"
else "%sies" % base_name[:-1]) else "%sies" % base_name[:-1])
subcategory_obj = subcategory(title) subcategory_obj = utils.subcategory(title)
else: else:
subcategory_obj = [] subcategory_obj = []
for p in sorted(base_cls.get_all(), key=lambda o: o.get_name()): for p in sorted(base_cls.get_all(), key=lambda o: o.get_name()):
@ -301,7 +301,7 @@ class PluginsReferenceDirective(rst.Directive):
@staticmethod @staticmethod
def _parse_class_name(cls): def _parse_class_name(cls):
name = "" name = ""
for word in re.split(r'([A-Z][a-z]*)', cls.__name__): for word in re.split(r"([A-Z][a-z]*)", cls.__name__):
if word: if word:
if len(word) > 1 and name: if len(word) > 1 and name:
name += " " name += " "
@ -345,7 +345,7 @@ class PluginsReferenceDirective(rst.Directive):
if base_name in IGNORED_BASES: if base_name in IGNORED_BASES:
continue continue
if category_name not in categories: if category_name not in categories:
categories[category_name] = category(category_name) categories[category_name] = utils.category(category_name)
category_of_base = categories[category_name] category_of_base = categories[category_name]
category_of_base.append(self._make_plugin_base_section(base_cls, category_of_base.append(self._make_plugin_base_section(base_cls,
base_name)) base_name))

View File

@ -18,8 +18,8 @@ Docutils is awful library. Let's apply some hacks and aliases to simplify usage
from docutils import frontend from docutils import frontend
from docutils import nodes from docutils import nodes
from docutils import utils
from docutils.parsers import rst from docutils.parsers import rst
from docutils import utils
import string import string
import six import six
@ -27,7 +27,8 @@ import six
def parse_text(text): def parse_text(text):
parser = rst.Parser() parser = rst.Parser()
settings = frontend.OptionParser(components=(rst.Parser,)).get_default_values() settings = frontend.OptionParser(
components=(rst.Parser,)).get_default_values()
document = utils.new_document(text, settings) document = utils.new_document(text, settings)
parser.parse(text, document) parser.parse(text, document)
return document.children return document.children
@ -45,8 +46,8 @@ def make_definition(term, ref, descriptions):
"""Constructs definition with reference to it.""" """Constructs definition with reference to it."""
ref = ref.replace("_", "-").replace(" ", "-") ref = ref.replace("_", "-").replace(" ", "-")
definition = parse_text( definition = parse_text(
".. _%(ref)s:\n\n* *%(term)s* [ref__]\n\n__ #%(ref)s" % ".. _%(ref)s:\n\n* *%(term)s* [ref__]\n\n__ #%(ref)s" %
{"ref": ref, "term": term}) {"ref": ref, "term": term})
for descr in descriptions: for descr in descriptions:
if descr: if descr:
if isinstance(descr, (six.text_type, six.binary_type)): if isinstance(descr, (six.text_type, six.binary_type)):

View File

@ -21,7 +21,7 @@
# All configuration values have a default; values that are commented out # All configuration values have a default; values that are commented out
# serve to show the default. # serve to show the default.
import datetime import datetime as dt
import os import os
import subprocess import subprocess
import sys import sys
@ -31,20 +31,20 @@ import rally.common.version
# If extensions (or modules to document with autodoc) are in another directory, # 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 # 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. # documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.extend([ # sys.path.extend([
# os.path.abspath("../.."), # os.path.abspath("../.."),
# os.path.abspath("../"), # os.path.abspath("../"),
# os.path.abspath("./") # os.path.abspath("./")
#]) # ])
sys.path.insert(0, os.path.abspath('../../')) sys.path.insert(0, os.path.abspath("../../"))
sys.path.insert(0, os.path.abspath('../')) sys.path.insert(0, os.path.abspath("../"))
sys.path.insert(0, os.path.abspath('./')) sys.path.insert(0, os.path.abspath("./"))
# -- General configuration ---------------------------------------------------- # -- General configuration ----------------------------------------------------
on_rtd = os.environ.get('READTHEDOCS') == 'True' on_rtd = os.environ.get("READTHEDOCS") == "True"
# If your documentation needs a minimal Sphinx version, state it here. # If your documentation needs a minimal Sphinx version, state it here.
# needs_sphinx = "1.0" # needs_sphinx = "1.0"
@ -79,7 +79,7 @@ master_doc = "index"
# General information about the project. # General information about the project.
project = u"Rally" project = u"Rally"
copyright = u"%d, OpenStack Foundation" % datetime.datetime.now().year copyright = u"%d, OpenStack Foundation" % dt.datetime.now().year
# The version info for the project you're documenting, acts as replacement for # The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the # |version| and |release|, also used in various other places throughout the
@ -147,7 +147,7 @@ else:
# Add any paths that contain custom themes here, relative to this directory. # Add any paths that contain custom themes here, relative to this directory.
if not on_rtd: if not on_rtd:
import oslosphinx import oslosphinx
theme_dir = os.path.join(os.path.dirname(oslosphinx.__file__), 'theme') theme_dir = os.path.join(os.path.dirname(oslosphinx.__file__), "theme")
html_theme_path = [theme_dir, "_templates"] html_theme_path = [theme_dir, "_templates"]
else: else:
html_theme_path = [] html_theme_path = []
@ -181,14 +181,14 @@ else:
git_cmd = [ git_cmd = [
"git", "log", "--pretty=format:'%ad, commit %h'", "--date=local", "-n1"] "git", "log", "--pretty=format:'%ad, commit %h'", "--date=local", "-n1"]
html_last_updated_fmt = subprocess.Popen( html_last_updated_fmt = subprocess.Popen(
git_cmd, stdout=subprocess.PIPE).communicate()[0] git_cmd, stdout=subprocess.PIPE).communicate()[0]
# If true, SmartyPants will be used to convert quotes and dashes to # If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities. # typographically correct entities.
html_use_smartypants = False html_use_smartypants = False
# Custom sidebar templates, maps document names to template names. # Custom sidebar templates, maps document names to template names.
html_sidebars = {'**': ['searchbox.html', 'globaltoc.html']} html_sidebars = {"**": ["searchbox.html", "globaltoc.html"]}
# Additional templates that should be rendered to pages, maps page names to # Additional templates that should be rendered to pages, maps page names to
# template names. # template names.
@ -227,14 +227,12 @@ htmlhelp_basename = "%sdoc" % project
# -- Options for LaTeX output ------------------------------------------------- # -- Options for LaTeX output -------------------------------------------------
latex_elements = { latex_elements = {
# The paper size ("letterpaper" or "a4paper"). # The paper size ("letterpaper" or "a4paper").
#"papersize": "letterpaper", # "papersize": "letterpaper",
# The font size ("10pt", "11pt" or "12pt").
# The font size ("10pt", "11pt" or "12pt"). # "pointsize": "10pt",
#"pointsize": "10pt", # Additional stuff for the LaTeX preamble.
# "preamble": "",
# Additional stuff for the LaTeX preamble.
#"preamble": "",
} }
# Grouping the document tree into LaTeX files. List of tuples # Grouping the document tree into LaTeX files. List of tuples
@ -286,9 +284,10 @@ latex_documents = [
# (source start file, target name, title, author, # (source start file, target name, title, author,
# dir menu entry, description, category) # dir menu entry, description, category)
texinfo_documents = [ texinfo_documents = [
("index", "Rally", u"Rally Documentation", ("index", "Rally", u"Rally Documentation",
u"Rally Team", "Rally", "Testing framework and tool for all kinds of tests", u"Rally Team", "Rally",
"Development"), "Testing framework and tool for all kinds of tests",
"Development"),
] ]
# Documents to append as an appendix to all manuals. # Documents to append as an appendix to all manuals.

View File

@ -13,13 +13,9 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from rally import plugins
from rally.common.plugin import discover
from rally.common.plugin import info from rally.common.plugin import info
from rally.common.plugin import plugin from rally.common.plugin import plugin
from rally.deployment import engine from rally import plugins
from rally.deployment.serverprovider import provider
from rally.task import sla
from tests.unit import test from tests.unit import test
EXCEPTIONS_DOCSTR = "missed_docstrings.txt" EXCEPTIONS_DOCSTR = "missed_docstrings.txt"
@ -28,7 +24,6 @@ EXCEPTIONS_FORMAT = "wrong_format.txt"
class DocstringsTestCase(test.TestCase): class DocstringsTestCase(test.TestCase):
def setUp(self): def setUp(self):
super(DocstringsTestCase, self).setUp() super(DocstringsTestCase, self).setUp()
plugins.load() plugins.load()

View File

@ -69,7 +69,7 @@ class TestFormat(testtools.TestCase):
docs_dir = os.path.join(os.path.dirname(__file__), os.pardir, docs_dir = os.path.join(os.path.dirname(__file__), os.pardir,
os.pardir, os.pardir, "doc") os.pardir, os.pardir, "doc")
for root, dirnames, filenames in os.walk(docs_dir): for root, dirnames, filenames in os.walk(docs_dir):
for filename in fnmatch.filter(filenames, '*.rst'): for filename in fnmatch.filter(filenames, "*.rst"):
files.append(os.path.join(root, filename)) files.append(os.path.join(root, filename))
for filename in files: for filename in files:

View File

@ -74,7 +74,7 @@ class TitlesTestCase(test.TestCase):
self.assertTrue( self.assertTrue(
len(line) < 80, len(line) < 80,
msg="%s:%d: Line limited to a maximum of 79 characters." % msg="%s:%d: Line limited to a maximum of 79 characters." %
(tpl, i+1)) (tpl, i + 1))
def _check_no_cr(self, tpl, raw): def _check_no_cr(self, tpl, raw):
matches = re.findall("\r", raw) matches = re.findall("\r", raw)
@ -88,7 +88,7 @@ class TitlesTestCase(test.TestCase):
trailing_spaces = re.findall(" +$", line) trailing_spaces = re.findall(" +$", line)
self.assertEqual( self.assertEqual(
len(trailing_spaces), 0, len(trailing_spaces), 0,
"Found trailing spaces on line %s of %s" % (i+1, tpl)) "Found trailing spaces on line %s of %s" % (i + 1, tpl))
def test_template(self): def test_template(self):
with open(os.path.join(self.specs_path, "template.rst")) as f: with open(os.path.join(self.specs_path, "template.rst")) as f:

View File

@ -22,8 +22,8 @@ import traceback
import yaml import yaml
from rally import api from rally import api
from rally.task import scenario
from rally.task import engine from rally.task import engine
from rally.task import scenario
from tests.unit import test from tests.unit import test

View File

@ -78,7 +78,7 @@ commands = python {toxinidir}/tests/ci/sync_requirements.py {posargs}
[flake8] [flake8]
ignore = H703,H105 ignore = H703,H105
show-source = true show-source = true
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,tools,build,setup.py exclude=.venv,.git,.tox,dist,*lib/python*,*egg,tools,build,setup.py
[hacking] [hacking]
import_exceptions = rally.common.i18n import_exceptions = rally.common.i18n