Switch to flake8/hacking instead of pep8+pyflakes.

Change-Id: I26a5b2b1923d6301a5ebdb6474d68a489f9fbe72
This commit is contained in:
Monty Taylor 2013-04-06 13:46:19 -04:00
parent 2205171cb6
commit f828f2fc16
6 changed files with 442 additions and 461 deletions

View File

@ -271,7 +271,7 @@ import string
import sys
from oslo.config import iniparser
from six.moves import filter
from six import moves
class Error(Exception):
@ -407,7 +407,7 @@ def _get_config_dirs(project=None):
'/etc'
]
return list(filter(bool, cfg_dirs))
return list(moves.filter(bool, cfg_dirs))
def _search_dirs(dirs, basename, extension=""):
@ -462,7 +462,7 @@ def find_config_files(project=None, prog=None, extension='.conf'):
config_files.append(_search_dirs(cfg_dirs, project, extension))
config_files.append(_search_dirs(cfg_dirs, prog, extension))
return list(filter(bool, config_files))
return list(moves.filter(bool, config_files))
def _is_opt_registered(opts, opt):
@ -703,7 +703,8 @@ class Opt(object):
class StrOpt(Opt):
"""
"""String options.
String opts do not have their values transformed and are returned as
str objects.
"""
@ -712,7 +713,8 @@ class StrOpt(Opt):
class BoolOpt(Opt):
"""
"""Boolean options.
Bool opts are set to True or False on the command line using --optname or
--noopttname respectively.
@ -806,15 +808,14 @@ class FloatOpt(Opt):
class ListOpt(Opt):
"""
"""List Options.
List opt values are simple string values separated by commas. The opt value
is a list containing these strings.
"""
class _StoreListAction(argparse.Action):
"""
An argparse action for parsing an option value into a list.
"""
"""An argparse action for parsing an option value into a list."""
def __call__(self, parser, namespace, values, option_string=None):
if values is not None:
values = [a.strip() for a in values.split(',')]
@ -835,14 +836,16 @@ class ListOpt(Opt):
class DictOpt(Opt):
"""
"""Dictionary options.
Dictionary opt values are key:value pairs separated by commas. The opt
value is a dictionary of these key/value pairs
"""
@staticmethod
def _split(line):
"""
"""Split a line.
Split a line into key/value pairs separated by commas, then split
the each into key and value using colons as separator and then
stuff the key/value (s) into a dictionary
@ -851,9 +854,7 @@ class DictOpt(Opt):
for v in line.split(',')])
class _StoreDictAction(argparse.Action):
"""
An argparse action for parsing an option value into a dictionary.
"""
"""An argparse action for parsing an option value into a dictionary."""
def __call__(self, parser, namespace, values, option_string=None):
if values is not None:
values = DictOpt._split(values)
@ -875,7 +876,8 @@ class DictOpt(Opt):
class MultiStrOpt(Opt):
"""
"""Multi-string option.
Multistr opt values are string opts which may be specified multiple times.
The opt value is a list containing all the string values specified.
"""
@ -898,7 +900,8 @@ class MultiStrOpt(Opt):
class SubCommandOpt(Opt):
"""
"""Sub-command options.
Sub-command options allow argparse sub-parsers to be used to parse
additional command line arguments.
@ -949,8 +952,7 @@ class SubCommandOpt(Opt):
class OptGroup(object):
"""
Represents a group of opts.
"""Represents a group of opts.
CLI opts in the group are automatically prefixed with the group name.
@ -1094,8 +1096,7 @@ class MultiConfigParser(object):
class ConfigOpts(collections.Mapping):
"""
Config options which may be set on the command line or in config files.
"""Config options which may be set on the command line or in config files.
ConfigOpts is a configuration option manager with APIs for registering
option schemas, grouping options, parsing option values and retrieving
@ -1515,7 +1516,7 @@ class ConfigOpts(collections.Mapping):
logger.log(lvl, "=" * 80)
def _sanitize(opt, value):
"""Obfuscate values of options declared secret"""
"""Obfuscate values of options declared secret."""
return value if not opt.secret else '*' * len(str(value))
for opt_name in sorted(self._opts):
@ -1728,9 +1729,9 @@ class ConfigOpts(collections.Mapping):
class GroupAttr(collections.Mapping):
"""
A helper class representing the option values of a group as a mapping
and attributes.
"""Helper class.
Represents the option values of a group as a mapping and attributes.
"""
def __init__(self, conf, group):
@ -1765,9 +1766,9 @@ class ConfigOpts(collections.Mapping):
class SubCommandAttr(object):
"""
A helper class representing the name and arguments of an argparse
sub-parser.
"""Helper class.
Represents the name and arguments of an argparse sub-parser.
"""
def __init__(self, conf, group, dest):
@ -1799,8 +1800,9 @@ class ConfigOpts(collections.Mapping):
class StrSubWrapper(object):
"""
A helper class exposing opt values as a dict for string substitution.
"""Helper class.
Exposes opt values as a dict for string substitution.
"""
def __init__(self, conf):

View File

@ -99,15 +99,15 @@ class BaseParser(object):
self._assignment(key, value)
def assignment(self, key, value):
"""Called when a full assignment is parsed"""
"""Called when a full assignment is parsed."""
raise NotImplementedError()
def new_section(self, section):
"""Called when a new section is started"""
"""Called when a new section is started."""
raise NotImplementedError()
def comment(self, comment):
"""Called when a comment is parsed"""
"""Called when a comment is parsed."""
pass
def error_invalid_assignment(self, line):

File diff suppressed because it is too large Load Diff

View File

@ -1,34 +0,0 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright (c) 2013 Intel Corporation.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# @author: Zhongyue Luo, Intel Corporation.
#
import sys
from pylint import lint
ENABLED_PYLINT_MSGS = ['W0611']
def main(dirpath):
enable_opt = '--enable=%s' % ','.join(ENABLED_PYLINT_MSGS)
lint.Run(['--reports=n', '--disable=all', enable_opt, dirpath])
if __name__ == '__main__':
main(sys.argv[1])

View File

@ -1,3 +1,9 @@
# Install bounded pep8/pyflakes first, then let flake8 install
pep8==1.4.5
pyflakes==0.7.2
flake8==2.0
hacking>=0.5.3,<0.6
discover
fixtures>=0.3.12
mox

19
tox.ini
View File

@ -1,5 +1,5 @@
[tox]
envlist = py26,py27,pep8,pylint
envlist = py26,py27,pep8
[testenv]
setenv = VIRTUAL_ENV={envdir}
@ -8,23 +8,18 @@ deps = -r{toxinidir}/tools/pip-requires
commands = python setup.py testr --slowest --testr-args='{posargs}'
[testenv:pep8]
deps = pep8==1.3.3
commands = pep8 --repeat --show-source --exclude=.tox,dist,doc,*.egg --ignore=E125 .
[testenv:pylint]
deps = pylint>=0.26.0
commands = python ./tools/lint.py ./oslo
python ./tools/lint.py ./tests
commands = flake8
[testenv:cover]
setenv = VIRTUAL_ENV={envdir}
commands =
python setup.py testr --coverage
[testenv:venv]
commands = {posargs}
[testenv:pyflakes]
deps = pyflakes
commands = pyflakes oslo setup.py
[flake8]
show-source = True
exclude = .tox,dist,doc,*.egg,build
ignore = E125
builtins = _