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,7 +72,8 @@ 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 default value for the ``%(arg)s`` argument is taken from "
"the Rally environment. Usually, the default value is equal to" "the Rally environment. Usually, the default value is equal to"
" the UUID of the last successful run of ``%(cmd)s``, if the " " the UUID of the last successful run of ``%(cmd)s``, if the "
"``--no-use`` argument was not used." % { "``--no-use`` argument was not used." % {
@ -82,13 +82,14 @@ def compose_note_about_default_uuids(argument, 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(
"You can set the default value by executing ``%(cmd)s <uuid>``"
" (ref__).\n\n __ #%(ref)s" % {"cmd": cmd, " (ref__).\n\n __ #%(ref)s" % {"cmd": cmd,
"ref": cmd.replace(" ", "-")}) "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
@ -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
@ -178,8 +180,8 @@ def make_category_section(name, parser):
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]
@ -201,9 +203,9 @@ class CLIReferenceDirective(rst.Directive):
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,7 +209,7 @@ 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)
@ -219,17 +218,17 @@ class PluginsReferenceDirective(rst.Directive):
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,7 +258,8 @@ 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(
"One of the following groups of "
"parameters should be provided.")) "parameters should be provided."))
for i, oneOf in enumerate(schema["oneOf"], 1): for i, oneOf in enumerate(schema["oneOf"], 1):
description = None description = None
@ -279,7 +279,7 @@ 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
@ -287,7 +287,7 @@ class PluginsReferenceDirective(rst.Directive):
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

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
@ -37,14 +37,14 @@ import rally.common.version
# 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 = []
@ -188,7 +188,7 @@ html_last_updated_fmt = subprocess.Popen(
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.
@ -229,10 +229,8 @@ htmlhelp_basename = "%sdoc" % project
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. # Additional stuff for the LaTeX preamble.
# "preamble": "", # "preamble": "",
} }
@ -287,7 +285,8 @@ latex_documents = [
# 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",
"Testing framework and tool for all kinds of tests",
"Development"), "Development"),
] ]

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

@ -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