[SCM] Samba Shared Repository - branch master updated
Andrew Bartlett
abartlet at samba.org
Tue Oct 14 01:07:02 MDT 2014
The branch, master has been updated
via 0c2c75a filter-subunit: Drop support for allow_empty_output hack.
via 77b72d4 samba3dump: Add subunit-enabled test for samba3dump.
via 23ac8d1 urgent_replication: Use subunit reporting, remove allow_empty_output.
via 7043a8b testr: Use waf testonly and create a custom directory for new workers.
via edc1ced selftest: Actually honor --with-selftest-prefix.
via b2e4f31 Don't import into testr when --load-list was specified, as testr will take care of that itself.
via 7cc7093 Don't ignore testsuites without --list support, but consider them as atomic entities.
via c7b6897 Run duplicate symbol check as just another test, rather than as part of "waf test".
via d9458aa samba.tests.unicodenames: Fix docstring formatting so pydoctor understands it.
via 08ca688 py_net: Fix typo in change_password docstring, and indentation in set_password docstring.
via eef3a7b samba_tool_drs: Fix docstring formatting so pydoctor groks it.
via 8bf6036 Fix pydoctor invocation.
via 2cdf553 samba.tests.source: Fix lint.
via 997ee57 Remove obsolete pep8 test.
via 0c24085 Fix more pep8 issues in code I touched recently.
via 9a014d2 Remove last instances of pep8 error E602 (old style exceptions).
via bd6faaf Remove last instances of pep8 error E712 (use 'is' rather than '==' for booleans)
via b605d15 pep8: Import new version.
via 2553714 Remove last instance of pep8 error E701 (more statements on one line).
via bbaa739 Remove remaining instance of pep8 E211 (too many spaces before operator).
from bcf298e lib/util: Add RFC3339 timestamp support to timeval_str_buf()
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 0c2c75a2d7afdb3e08aa29f6b996d953dcc3b5a1
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Sun Oct 12 21:18:08 2014 -0700
filter-subunit: Drop support for allow_empty_output hack.
Change-Id: If4f336ef770202dcf69484b9bccc6c0c80bd5f9b
Signed-Off-By: Jelmer Vernooij <jelmer at samba.org>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
Autobuild-User(master): Andrew Bartlett <abartlet at samba.org>
Autobuild-Date(master): Tue Oct 14 09:06:05 CEST 2014 on sn-devel-104
commit 77b72d4c8e02e6bba9ef8c90287455a784afe9d8
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Sun Oct 12 21:17:05 2014 -0700
samba3dump: Add subunit-enabled test for samba3dump.
Change-Id: Ie9682c715fc91d923dcd1951236f8b36fa519327
Signed-Off-By: Jelmer Vernooij <jelmer at samba.org>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
commit 23ac8d130c1f476fda5d984531266a6c210c2982
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Sun Oct 12 21:11:22 2014 -0700
urgent_replication: Use subunit reporting, remove allow_empty_output.
Change-Id: I6d479b218eff6c4292fbb99e4760bbd62ce1f380
Signed-Off-By: Jelmer Vernooij <jelmer at samba.org>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
commit 7043a8b62a7093764f92bcd098df72a844139f7d
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Sun Oct 12 19:53:35 2014 -0700
testr: Use waf testonly and create a custom directory for new workers.
Using waf testonly helps speed up test runs, and the custom directory is
required to run multiple workers in parallel.
Change-Id: I339420c5c503c270a04888a1c990836cb0c91e94
Signed-Off-By: Jelmer Vernooij <jelmer at samba.org>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
commit edc1cedf932de2bc068da9a5db844ac4c48f4324
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Sun Oct 12 19:52:49 2014 -0700
selftest: Actually honor --with-selftest-prefix.
Change-Id: Ie8c995a273781309224e17b8970a864479444036
Signed-Off-By: Jelmer Vernooij <jelmer at samba.org>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
commit b2e4f312a2680f314ccd9a9d294e50035f117e07
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Sun Oct 12 17:58:41 2014 -0700
Don't import into testr when --load-list was specified, as testr will
take care of that itself.
Change-Id: I3d57f4cfafdd48751dfbd145f220dc5cf000ec3f
Signed-Off-By: Jelmer Vernooij <jelmer at samba.org>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
commit 7cc7093fb3f52e438239578e70aaee6c3ef12cda
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Sun Oct 12 17:49:39 2014 -0700
Don't ignore testsuites without --list support, but consider them as
atomic entities.
This prevents any such testsuites from being skipped when run using
testr.
Bug: https://bugzilla.samba.org/show_bug.cgi?id=10874
Change-Id: I6ae8c92bb70e86a3b848b9cb3a53e2af466c3fe3
Signed-Off-By: Jelmer Vernooij <jelmer at samba.org>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
commit c7b6897b80e724023c3b092d086ab574bff564e1
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Sun Oct 12 17:48:10 2014 -0700
Run duplicate symbol check as just another test, rather than as part of "waf test".
This allows it to be scheduled independently as part of a parallel test
run, and reduces the overhead of "waf test".
Change-Id: I780fd2c4dd711ed27df73f56de98e7f1ffd53aaf
Signed-Off-By: Jelmer Vernooij <jelmer at samba.org>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
Bug: https://bugzilla.samba.org/show_bug.cgi?id=10875
commit d9458aa2d9be1ddd7c6d6edd993e12973195e307
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Sun Oct 12 16:08:15 2014 -0700
samba.tests.unicodenames: Fix docstring formatting so pydoctor understands it.
Change-Id: I8983cd4483c380fd0c9e4da843eb70750450a0fa
Signed-Off-By: Jelmer Vernooij <jelmer at samba.org>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
commit 08ca688d4ec126ff72ffb46de2d764ae890401ad
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Sun Oct 12 16:07:41 2014 -0700
py_net: Fix typo in change_password docstring, and indentation in
set_password docstring.
Change-Id: I93e9ed79ee43233fc3c1bb69d8eb0a5c6e0e3940
Signed-off-by: Jelmer Vernooij <jelmer at samba.org>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
commit eef3a7be2d07771115e3fb0b3cfd6bcfb4061aaa
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Sun Oct 12 16:07:34 2014 -0700
samba_tool_drs: Fix docstring formatting so pydoctor groks it.
Change-Id: I827044ef876118935b0f91e318d3c815326a2f01
Signed-off-by: Jelmer Vernooij <jelmer at samba.org>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
commit 8bf60364828c7b3b1d8f6d79b6834bc5a8ed4339
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Sun Oct 12 15:48:53 2014 -0700
Fix pydoctor invocation.
Signed-Off-By: Jelmer Vernooij <jelmer at samba.org>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
Bug: https://bugzilla.samba.org/show_bug.cgi?id=10754
Change-Id: I1ca311dcba52350dc284439119a8166dee1de50a
commit 2cdf55354593dd96120ea34929f4be7133f0e230
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Sat Sep 27 18:03:04 2014 +0200
samba.tests.source: Fix lint.
Change-Id: I3dc614c34aa2c4fca6f2ca68196e71b9129b5b76
Signed-off-by: Jelmer Vernooij <jelmer at samba.org>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
commit 997ee574a3d1976b132bf2478d9f8f49d70d3e07
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Mon Jun 2 03:12:52 2014 +0200
Remove obsolete pep8 test.
Signed-Off-By: Jelmer Vernooij <jelmer at samba.org>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
Change-Id: I7f6634a035e9c93820cd4eef0261ecd5dd3865ab
commit 0c2408531709eb720a2e96f72afbc2ecbfe6b06d
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Mon Jun 2 02:53:01 2014 +0200
Fix more pep8 issues in code I touched recently.
Signed-Off-By: Jelmer Vernooij <jelmer at samba.org>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
Change-Id: I35f3204bdf5d00b3280d703427ded2fa2163a6f7
commit 9a014d265b4e134fb5cea12aaca88ba5eb91cc05
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Mon Jun 2 02:37:11 2014 +0200
Remove last instances of pep8 error E602 (old style exceptions).
Signed-Off-By: Jelmer Vernooij <jelmer at samba.org>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
Change-Id: If709757643e6eed8cffa8950170c337f51edb9d9
commit bd6faaf56a6237874cc84ddb8be0f09a9b742a54
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Mon Jun 2 02:36:13 2014 +0200
Remove last instances of pep8 error E712 (use 'is' rather than '==' for booleans)
Signed-Off-By: Jelmer Vernooij <jelmer at samba.org>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
Change-Id: I43b394a6225b4c2049d979fda75548c82d781f67
commit b605d152de80889925c7b7a3e723a3581fe5e21a
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Mon Jun 2 02:24:06 2014 +0200
pep8: Import new version.
Signed-Off-By: Jelmer Vernooij <jelmer at samba.org>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
Change-Id: I22d897a8f46a4ac57a91db3ad05286d9d0066806
commit 2553714004cb1d6b5889fa81cd6b0ef9c1be9608
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Mon Jun 2 01:34:47 2014 +0200
Remove last instance of pep8 error E701 (more statements on one line).
Signed-Off-By: Jelmer Vernooij <jelmer at samba.org>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
Change-Id: I419f0536b43d98ce6bb52c5907413a02ea1a6937
commit bbaa739bbda4685fa5e38ea0d939496398e11ebf
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Mon Jun 2 01:33:43 2014 +0200
Remove remaining instance of pep8 E211 (too many spaces before operator).
Signed-Off-By: Jelmer Vernooij <jelmer at samba.org>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
Change-Id: I9af3bf582bba8fc1094addb12cd0a5ce04406b5b
-----------------------------------------------------------------------
Summary of changes:
.testr.conf | 2 +-
buildtools/wafsamba/samba3.py | 13 +-
buildtools/wafsamba/test_duplicate_symbol.sh | 12 +
buildtools/wafsamba/wafsamba.py | 7 +-
lib/pep8/pep8.py | 2167 +++++++++++++++--------
python/samba/drs_utils.py | 31 +-
python/samba/kcc_utils.py | 6 +-
python/samba/provision/backend.py | 20 +-
python/samba/schema.py | 17 +-
python/samba/tests/__init__.py | 7 +-
python/samba/tests/blackbox/samba_tool_drs.py | 51 +-
python/samba/tests/dns.py | 14 +-
python/samba/tests/samba3.py | 2 +-
python/samba/tests/samba3sam.py | 6 +-
python/samba/tests/source.py | 65 +-
python/samba/tests/unicodenames.py | 5 +-
selftest/selftest.pl | 3 +
selftest/selftesthelpers.py | 9 +-
selftest/tests.py | 38 +-
selftest/wscript | 25 +-
source4/dsdb/tests/python/urgent_replication.py | 116 +-
source4/libnet/py_net.c | 6 +-
source4/scripting/bin/samba_kcc | 4 +-
source4/scripting/bin/samba_upgradeprovision | 2 +-
source4/selftest/test_samba3dump.sh | 14 +
source4/selftest/tests.py | 4 +-
wscript | 10 +-
27 files changed, 1625 insertions(+), 1031 deletions(-)
create mode 100755 buildtools/wafsamba/test_duplicate_symbol.sh
create mode 100755 source4/selftest/test_samba3dump.sh
Changeset truncated at 500 lines:
diff --git a/.testr.conf b/.testr.conf
index 00d0857..5a181e3 100644
--- a/.testr.conf
+++ b/.testr.conf
@@ -1,4 +1,4 @@
[DEFAULT]
-test_command=./buildtools/bin/waf test --filtered-subunit $IDOPTION $LISTOPT
+test_command=./buildtools/bin/waf testonly --filtered-subunit $IDOPTION $LISTOPT --with-selftest-prefix=$(mktemp -d)
test_id_option=--load-list $IDFILE
test_list_option=--list
diff --git a/buildtools/wafsamba/samba3.py b/buildtools/wafsamba/samba3.py
index 64cd8c7..ffe6784 100644
--- a/buildtools/wafsamba/samba3.py
+++ b/buildtools/wafsamba/samba3.py
@@ -6,16 +6,17 @@ from optparse import SUPPRESS_HELP
from samba_utils import os_path_relpath, TO_LIST
from samba_autoconf import library_flags
+
def SAMBA3_ADD_OPTION(opt, option, help=(), dest=None, default=True,
with_name="with", without_name="without"):
if default is None:
- default_str="auto"
- elif default == True:
- default_str="yes"
- elif default == False:
- default_str="no"
+ default_str = "auto"
+ elif default is True:
+ default_str = "yes"
+ elif default is False:
+ default_str = "no"
else:
- default_str=str(default)
+ default_str = str(default)
if help == ():
help = ("Build with %s support (default=%s)" % (option, default_str))
diff --git a/buildtools/wafsamba/test_duplicate_symbol.sh b/buildtools/wafsamba/test_duplicate_symbol.sh
new file mode 100755
index 0000000..712c7e6
--- /dev/null
+++ b/buildtools/wafsamba/test_duplicate_symbol.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+# Run the waf duplicate symbol check, wrapped in subunit.
+
+. lib/subunit/shell/share/subunit.sh
+
+subunit_start_test duplicate_symbols
+
+if ./buildtools/bin/waf build --dup-symbol-check; then
+ subunit_pass_test duplicate_symbols
+else
+ echo | subunit_fail_test duplicate_symbols
+fi
diff --git a/buildtools/wafsamba/wafsamba.py b/buildtools/wafsamba/wafsamba.py
index f86ac61..b68b9d2 100644
--- a/buildtools/wafsamba/wafsamba.py
+++ b/buildtools/wafsamba/wafsamba.py
@@ -349,10 +349,10 @@ def SAMBA_BINARY(bld, binname, source,
# only specify PIE flags for binaries
pie_cflags = cflags
pie_ldflags = TO_LIST(ldflags)
- if bld.env['ENABLE_PIE'] == True:
+ if bld.env['ENABLE_PIE'] is True:
pie_cflags += ' -fPIE'
pie_ldflags.extend(TO_LIST('-pie'))
- if bld.env['ENABLE_RELRO'] == True:
+ if bld.env['ENABLE_RELRO'] is True:
pie_ldflags.extend(TO_LIST('-Wl,-z,relro,-z,now'))
# first create a target for building the object files for this binary
@@ -726,7 +726,8 @@ sys.path.insert(1, "%s")""" % (task.env["PYTHONARCHDIR"], task.env["PYTHONDIR"])
lineno = 0
for line in source_file:
newline = line
- if lineno == 0 and task.env["PYTHON_SPECIFIED"] == True and line[:2] == "#!":
+ if (lineno == 0 and task.env["PYTHON_SPECIFIED"] is True and
+ line[:2] == "#!"):
newline = replacement_shebang
elif pattern in line:
newline = line.replace(pattern, replacement)
diff --git a/lib/pep8/pep8.py b/lib/pep8/pep8.py
index 227a9a3..b31a978 100755
--- a/lib/pep8/pep8.py
+++ b/lib/pep8/pep8.py
@@ -1,6 +1,7 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# pep8.py - Check Python source code formatting, according to PEP 8
-# Copyright (C) 2006 Johann C. Rocholl <johann at rocholl.net>
+# Copyright (C) 2006-2009 Johann C. Rocholl <johann at rocholl.net>
+# Copyright (C) 2009-2014 Florent Xicluna <florent.xicluna at gmail.com>
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation files
@@ -22,9 +23,8 @@
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
-"""
-Check Python source code formatting, according to PEP 8:
-http://www.python.org/dev/peps/pep-0008/
+r"""
+Check Python source code formatting, according to PEP 8.
For usage and a list of options, try this:
$ python pep8.py -h
@@ -42,57 +42,11 @@ W warnings
500 line length
600 deprecation
700 statements
-
-You can add checks to this program by writing plugins. Each plugin is
-a simple function that is called for each line of source code, either
-physical or logical.
-
-Physical line:
-- Raw line of text from the input file.
-
-Logical line:
-- Multi-line statements converted to a single line.
-- Stripped left and right.
-- Contents of strings replaced with 'xxx' of same length.
-- Comments removed.
-
-The check function requests physical or logical lines by the name of
-the first argument:
-
-def maximum_line_length(physical_line)
-def extraneous_whitespace(logical_line)
-def blank_lines(logical_line, blank_lines, indent_level, line_number)
-
-The last example above demonstrates how check plugins can request
-additional information with extra arguments. All attributes of the
-Checker object are available. Some examples:
-
-lines: a list of the raw lines from the input file
-tokens: the tokens that contribute to this logical line
-line_number: line number in the input file
-blank_lines: blank lines before this one
-indent_char: first indentation character in this file (' ' or '\t')
-indent_level: indentation (with tabs expanded to multiples of 8)
-previous_indent_level: indentation on previous line
-previous_logical: previous logical line
-
-The docstring of each check function shall be the relevant part of
-text from PEP 8. It is printed if the user enables --show-pep8.
-Several docstrings contain examples directly from the PEP 8 document.
-
-Okay: spam(ham[1], {eggs: 2})
-E201: spam( ham[1], {eggs: 2})
-
-These examples are verified automatically when pep8.py is run with the
---doctest option. You can add examples for your own check functions.
-The format is simple: "Okay" or error/warning code followed by colon
-and space, the rest of the line is example source code. If you put 'r'
-before the docstring, you can use \n for newline, \t for tab and \s
-for space.
-
+900 syntax error
"""
+from __future__ import with_statement
-__version__ = '0.5.1dev'
+__version__ = '1.6.0a0'
import os
import sys
@@ -104,42 +58,61 @@ import tokenize
from optparse import OptionParser
from fnmatch import fnmatch
try:
- frozenset
-except NameError:
- from sets import ImmutableSet as frozenset
-
-
-DEFAULT_EXCLUDE = '.svn,CVS,.bzr,.hg,.git'
-DEFAULT_IGNORE = 'E24'
+ from configparser import RawConfigParser
+ from io import TextIOWrapper
+except ImportError:
+ from ConfigParser import RawConfigParser
+
+DEFAULT_EXCLUDE = '.svn,CVS,.bzr,.hg,.git,__pycache__'
+DEFAULT_IGNORE = 'E123,E226,E24,E704'
+if sys.platform == 'win32':
+ DEFAULT_CONFIG = os.path.expanduser(r'~\.pep8')
+else:
+ DEFAULT_CONFIG = os.path.join(os.getenv('XDG_CONFIG_HOME') or
+ os.path.expanduser('~/.config'), 'pep8')
+PROJECT_CONFIG = ('setup.cfg', 'tox.ini', '.pep8')
+TESTSUITE_PATH = os.path.join(os.path.dirname(__file__), 'testsuite')
MAX_LINE_LENGTH = 79
+REPORT_FORMAT = {
+ 'default': '%(path)s:%(row)d:%(col)d: %(code)s %(text)s',
+ 'pylint': '%(path)s:%(row)d: [%(code)s] %(text)s',
+}
+
+PyCF_ONLY_AST = 1024
+SINGLETONS = frozenset(['False', 'None', 'True'])
+KEYWORDS = frozenset(keyword.kwlist + ['print']) - SINGLETONS
+UNARY_OPERATORS = frozenset(['>>', '**', '*', '+', '-'])
+ARITHMETIC_OP = frozenset(['**', '*', '/', '//', '+', '-'])
+WS_OPTIONAL_OPERATORS = ARITHMETIC_OP.union(['^', '&', '|', '<<', '>>', '%'])
+WS_NEEDED_OPERATORS = frozenset([
+ '**=', '*=', '/=', '//=', '+=', '-=', '!=', '<>', '<', '>',
+ '%=', '^=', '&=', '|=', '==', '<=', '>=', '<<=', '>>=', '='])
+WHITESPACE = frozenset(' \t')
+NEWLINE = frozenset([tokenize.NL, tokenize.NEWLINE])
+SKIP_TOKENS = NEWLINE.union([tokenize.INDENT, tokenize.DEDENT])
+# ERRORTOKEN is triggered by backticks in Python 3
+SKIP_COMMENTS = SKIP_TOKENS.union([tokenize.COMMENT, tokenize.ERRORTOKEN])
+BENCHMARK_KEYS = ['directories', 'files', 'logical lines', 'physical lines']
INDENT_REGEX = re.compile(r'([ \t]*)')
-RAISE_COMMA_REGEX = re.compile(r'raise\s+\w+\s*(,)')
-SELFTEST_REGEX = re.compile(r'(Okay|[EW]\d{3}):\s(.*)')
-ERRORCODE_REGEX = re.compile(r'[EW]\d{3}')
+RAISE_COMMA_REGEX = re.compile(r'raise\s+\w+\s*,')
+RERAISE_COMMA_REGEX = re.compile(r'raise\s+\w+\s*,.*,\s*\w+\s*$')
+ERRORCODE_REGEX = re.compile(r'\b[A-Z]\d{3}\b')
DOCSTRING_REGEX = re.compile(r'u?r?["\']')
-WHITESPACE_AROUND_OPERATOR_REGEX = \
- re.compile('([^\w\s]*)\s*(\t| )\s*([^\w\s]*)')
EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[[({] | []}),;:]')
-WHITESPACE_AROUND_NAMED_PARAMETER_REGEX = \
- re.compile(r'[()]|\s=[^=]|[^=!<>]=\s')
-
-
-WHITESPACE = ' \t'
+WHITESPACE_AFTER_COMMA_REGEX = re.compile(r'[,;:]\s*(?: |\t)')
+COMPARE_SINGLETON_REGEX = re.compile(r'([=!]=)\s*(None|False|True)')
+COMPARE_NEGATIVE_REGEX = re.compile(r'\b(not)\s+[^[({ ]+\s+(in|is)\s')
+COMPARE_TYPE_REGEX = re.compile(r'(?:[=!]=|is(?:\s+not)?)\s*type(?:s.\w+Type'
+ r'|\s*\(\s*([^)]*[^ )])\s*\))')
+KEYWORD_REGEX = re.compile(r'(\s*)\b(?:%s)\b(\s*)' % r'|'.join(KEYWORDS))
+OPERATOR_REGEX = re.compile(r'(?:[^,\s])(\s*)(?:[-+*/|!<=>%&^]+)(\s*)')
+LAMBDA_REGEX = re.compile(r'\blambda\b')
+HUNK_REGEX = re.compile(r'^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@.*$')
-BINARY_OPERATORS = frozenset(['**=', '*=', '+=', '-=', '!=', '<>',
- '%=', '^=', '&=', '|=', '==', '/=', '//=', '<=', '>=', '<<=', '>>=',
- '%', '^', '&', '|', '=', '/', '//', '<', '>', '<<'])
-UNARY_OPERATORS = frozenset(['>>', '**', '*', '+', '-'])
-OPERATORS = BINARY_OPERATORS | UNARY_OPERATORS
-SKIP_TOKENS = frozenset([tokenize.COMMENT, tokenize.NL, tokenize.INDENT,
- tokenize.DEDENT, tokenize.NEWLINE])
-E225NOT_KEYWORDS = (frozenset(keyword.kwlist + ['print']) -
- frozenset(['False', 'None', 'True']))
-BENCHMARK_KEYS = ('directories', 'files', 'logical lines', 'physical lines')
-
-options = None
-args = None
+# Work around Python < 2.6 behaviour, which does not generate NL after
+# a comment which is on a line by itself.
+COMMENT_WITH_NL = tokenize.generate_tokens(['#\n'].pop).send(None)[1] == '#\n'
##############################################################################
@@ -148,8 +121,7 @@ args = None
def tabs_or_spaces(physical_line, indent_char):
- r"""
- Never mix tabs and spaces.
+ r"""Never mix tabs and spaces.
The most popular way of indenting Python is with spaces only. The
second-most popular way is with tabs only. Code indented with a mixture
@@ -168,41 +140,30 @@ def tabs_or_spaces(physical_line, indent_char):
def tabs_obsolete(physical_line):
- r"""
- For new projects, spaces-only are strongly recommended over tabs. Most
- editors have features that make this easy to do.
+ r"""For new projects, spaces-only are strongly recommended over tabs.
Okay: if True:\n return
W191: if True:\n\treturn
"""
indent = INDENT_REGEX.match(physical_line).group(1)
- if indent.count('\t'):
+ if '\t' in indent:
return indent.index('\t'), "W191 indentation contains tabs"
def trailing_whitespace(physical_line):
- r"""
- JCR: Trailing whitespace is superfluous.
- FBM: Except when it occurs as part of a blank line (i.e. the line is
- nothing but whitespace). According to Python docs[1] a line with only
- whitespace is considered a blank line, and is to be ignored. However,
- matching a blank line to its indentation level avoids mistakenly
- terminating a multi-line statement (e.g. class declaration) when
- pasting code into the standard Python interpreter.
-
- [1] http://docs.python.org/reference/lexical_analysis.html#blank-lines
+ r"""Trailing whitespace is superfluous.
The warning returned varies on whether the line itself is blank, for easier
filtering for those who want to indent their blank lines.
- Okay: spam(1)
- W291: spam(1)\s
+ Okay: spam(1)\n#
+ W291: spam(1) \n#
W293: class Foo(object):\n \n bang = 12
"""
physical_line = physical_line.rstrip('\n') # chr(10), newline
physical_line = physical_line.rstrip('\r') # chr(13), carriage return
physical_line = physical_line.rstrip('\x0c') # chr(12), form feed, ^L
- stripped = physical_line.rstrip()
+ stripped = physical_line.rstrip(' \t\v')
if physical_line != stripped:
if stripped:
return len(stripped), "W291 trailing whitespace"
@@ -210,28 +171,24 @@ def trailing_whitespace(physical_line):
return 0, "W293 blank line contains whitespace"
-def trailing_blank_lines(physical_line, lines, line_number):
- r"""
- JCR: Trailing blank lines are superfluous.
+def trailing_blank_lines(physical_line, lines, line_number, total_lines):
+ r"""Trailing blank lines are superfluous.
Okay: spam(1)
W391: spam(1)\n
- """
- if physical_line.strip() == '' and line_number == len(lines):
- return 0, "W391 blank line at end of file"
-
-def missing_newline(physical_line):
- """
- JCR: The last line should have a newline.
+ However the last line should end with a new line (warning W292).
"""
- if physical_line.rstrip() == physical_line:
- return len(physical_line), "W292 no newline at end of file"
+ if line_number == total_lines:
+ stripped_last_line = physical_line.rstrip()
+ if not stripped_last_line:
+ return 0, "W391 blank line at end of file"
+ if stripped_last_line == physical_line:
+ return len(physical_line), "W292 no newline at end of file"
-def maximum_line_length(physical_line):
- """
- Limit all lines to a maximum of 79 characters.
+def maximum_line_length(physical_line, max_line_length, multiline):
+ r"""Limit all lines to a maximum of 79 characters.
There are still many devices around that are limited to 80 character
lines; plus, limiting windows to 80 characters makes it possible to have
@@ -239,19 +196,28 @@ def maximum_line_length(physical_line):
ugly. Therefore, please limit all lines to a maximum of 79 characters.
For flowing long blocks of text (docstrings or comments), limiting the
length to 72 characters is recommended.
+
+ Reports error E501.
"""
line = physical_line.rstrip()
length = len(line)
- if length > MAX_LINE_LENGTH:
- try:
+ if length > max_line_length and not noqa(line):
+ # Special case for long URLs in multi-line docstrings or comments,
+ # but still report the error when the 72 first chars are whitespaces.
+ chunks = line.split()
+ if ((len(chunks) == 1 and multiline) or
+ (len(chunks) == 2 and chunks[0] == '#')) and \
+ len(line) - len(chunks[-1]) < max_line_length - 7:
+ return
+ if hasattr(line, 'decode'): # Python 2
# The line could contain multi-byte characters
- if not hasattr(line, 'decode'): # Python 3
- line = line.encode('latin-1')
- length = len(line.decode('utf-8'))
- except UnicodeDecodeError:
- pass
- if length > MAX_LINE_LENGTH:
- return MAX_LINE_LENGTH, "E501 line too long (%d characters)" % length
+ try:
+ length = len(line.decode('utf-8'))
+ except UnicodeError:
+ pass
+ if length > max_line_length:
+ return (max_line_length, "E501 line too long "
+ "(%d > %d characters)" % (length, max_line_length))
##############################################################################
@@ -260,10 +226,8 @@ def maximum_line_length(physical_line):
def blank_lines(logical_line, blank_lines, indent_level, line_number,
- previous_logical, previous_indent_level,
- blank_lines_before_comment):
- r"""
- Separate top-level function and class definitions with two blank lines.
+ blank_before, previous_logical, previous_indent_level):
+ r"""Separate top-level function and class definitions with two blank lines.
Method definitions inside a class are separated by a single blank line.
@@ -282,31 +246,27 @@ def blank_lines(logical_line, blank_lines, indent_level, line_number,
E303: def a():\n\n\n\n pass
E304: @decorator\n\ndef a():\n pass
"""
- if line_number == 1:
+ if line_number < 3 and not previous_logical:
return # Don't expect blank lines before the first line
- max_blank_lines = max(blank_lines, blank_lines_before_comment)
if previous_logical.startswith('@'):
- if max_blank_lines:
- return 0, "E304 blank lines found after function decorator"
- elif max_blank_lines > 2 or (indent_level and max_blank_lines == 2):
- return 0, "E303 too many blank lines (%d)" % max_blank_lines
- elif (logical_line.startswith('def ') or
- logical_line.startswith('class ') or
- logical_line.startswith('@')):
+ if blank_lines:
+ yield 0, "E304 blank lines found after function decorator"
+ elif blank_lines > 2 or (indent_level and blank_lines == 2):
+ yield 0, "E303 too many blank lines (%d)" % blank_lines
+ elif logical_line.startswith(('def ', 'class ', '@')):
if indent_level:
- if not (max_blank_lines or previous_indent_level < indent_level or
+ if not (blank_before or previous_indent_level < indent_level or
DOCSTRING_REGEX.match(previous_logical)):
- return 0, "E301 expected 1 blank line, found 0"
- elif max_blank_lines != 2:
- return 0, "E302 expected 2 blank lines, found %d" % max_blank_lines
+ yield 0, "E301 expected 1 blank line, found 0"
+ elif blank_before != 2:
+ yield 0, "E302 expected 2 blank lines, found %d" % blank_before
def extraneous_whitespace(logical_line):
- """
- Avoid extraneous whitespace in the following situations:
+ r"""Avoid extraneous whitespace.
+ Avoid extraneous whitespace in these situations:
- Immediately inside parentheses, brackets or braces.
-
- Immediately before a comma, semicolon, or colon.
Okay: spam(ham[1], {eggs: 2})
@@ -326,18 +286,39 @@ def extraneous_whitespace(logical_line):
text = match.group()
char = text.strip()
found = match.start()
- if text == char + ' ' and char in '([{':
- return found + 1, "E201 whitespace after '%s'" % char
- if text == ' ' + char and line[found - 1] != ',':
- if char in '}])':
- return found, "E202 whitespace before '%s'" % char
- if char in ',;:':
- return found, "E203 whitespace before '%s'" % char
+ if text == char + ' ':
+ # assert char in '([{'
+ yield found + 1, "E201 whitespace after '%s'" % char
+ elif line[found - 1] != ',':
+ code = ('E202' if char in '}])' else 'E203') # if char in ',;:'
+ yield found, "%s whitespace before '%s'" % (code, char)
-def missing_whitespace(logical_line):
+def whitespace_around_keywords(logical_line):
+ r"""Avoid extraneous whitespace around keywords.
+
+ Okay: True and False
+ E271: True and False
+ E272: True and False
+ E273: True and\tFalse
+ E274: True\tand False
"""
- JCR: Each comma, semicolon or colon should be followed by whitespace.
+ for match in KEYWORD_REGEX.finditer(logical_line):
+ before, after = match.groups()
+
+ if '\t' in before:
+ yield match.start(1), "E274 tab before keyword"
+ elif len(before) > 1:
+ yield match.start(1), "E272 multiple spaces before keyword"
+
+ if '\t' in after:
+ yield match.start(2), "E273 tab after keyword"
+ elif len(after) > 1:
+ yield match.start(2), "E271 multiple spaces after keyword"
+
+
+def missing_whitespace(logical_line):
--
Samba Shared Repository
More information about the samba-cvs
mailing list