diff options
Diffstat (limited to 'tools')
| -rwxr-xr-x | tools/hacking.py | 16 | ||||
| -rwxr-xr-x | tools/mock-meta.py | 27 | ||||
| -rwxr-xr-x | tools/run-pep8 | 51 | ||||
| -rwxr-xr-x | tools/run-pyflakes | 18 | ||||
| -rwxr-xr-x | tools/run-pyflakes3 | 2 | ||||
| -rwxr-xr-x | tools/validate-yaml.py | 2 | 
6 files changed, 61 insertions, 55 deletions
| diff --git a/tools/hacking.py b/tools/hacking.py index 3175df38..716c1154 100755 --- a/tools/hacking.py +++ b/tools/hacking.py @@ -47,10 +47,10 @@ def import_normalize(line):      # handle "from x import y as z" to "import x.y as z"      split_line = line.split()      if (line.startswith("from ") and "," not in line and -           split_line[2] == "import" and split_line[3] != "*" and -           split_line[1] != "__future__" and -           (len(split_line) == 4 or -           (len(split_line) == 6 and split_line[4] == "as"))): +       split_line[2] == "import" and split_line[3] != "*" and +       split_line[1] != "__future__" and +       (len(split_line) == 4 or (len(split_line) == 6 and +                                 split_line[4] == "as"))):          return "import %s.%s" % (split_line[1], split_line[3])      else:          return line @@ -74,7 +74,7 @@ def cloud_import_alphabetical(physical_line, line_number, lines):              split_line[0] == "import" and split_previous[0] == "import"):          if split_line[1] < split_previous[1]:              return (0, "N306: imports not in alphabetical order (%s, %s)" -                % (split_previous[1], split_line[1])) +                    % (split_previous[1], split_line[1]))  def cloud_docstring_start_space(physical_line): @@ -87,8 +87,8 @@ def cloud_docstring_start_space(physical_line):      pos = max([physical_line.find(i) for i in DOCSTRING_TRIPLE])  # start      if (pos != -1 and len(physical_line) > pos + 1):          if (physical_line[pos + 3] == ' '): -            return (pos, "N401: one line docstring should not start with" -                " a space") +            return (pos, +                    "N401: one line docstring should not start with a space")  def cloud_todo_format(physical_line): @@ -167,4 +167,4 @@ if __name__ == "__main__":      finally:          if len(_missingImport) > 0:              print >> sys.stderr, ("%i imports missing in this test environment" -                    % len(_missingImport)) +                                  % len(_missingImport)) diff --git a/tools/mock-meta.py b/tools/mock-meta.py index dfbc2a71..1c746f17 100755 --- a/tools/mock-meta.py +++ b/tools/mock-meta.py @@ -126,11 +126,11 @@ class WebException(Exception):  def yamlify(data):      formatted = yaml.dump(data, -        line_break="\n", -        indent=4, -        explicit_start=True, -        explicit_end=True, -        default_flow_style=False) +                          line_break="\n", +                          indent=4, +                          explicit_start=True, +                          explicit_end=True, +                          default_flow_style=False)      return formatted @@ -282,7 +282,7 @@ class MetaDataHandler(object):          else:              log.warn(("Did not implement action %s, "                        "returning empty response: %r"), -                      action, NOT_IMPL_RESPONSE) +                     action, NOT_IMPL_RESPONSE)              return NOT_IMPL_RESPONSE @@ -404,14 +404,17 @@ def setup_logging(log_level, fmt='%(levelname)s: @%(name)s : %(message)s'):  def extract_opts():      parser = OptionParser()      parser.add_option("-p", "--port", dest="port", action="store", type=int, -        default=80, metavar="PORT", -        help="port from which to serve traffic (default: %default)") +                      default=80, metavar="PORT", +                      help=("port from which to serve traffic" +                            " (default: %default)"))      parser.add_option("-a", "--addr", dest="address", action="store", type=str, -        default='0.0.0.0', metavar="ADDRESS", -        help="address from which to serve traffic (default: %default)") +                      default='0.0.0.0', metavar="ADDRESS", +                      help=("address from which to serve traffic" +                            " (default: %default)"))      parser.add_option("-f", '--user-data-file', dest='user_data_file', -        action='store', metavar='FILE', -        help="user data filename to serve back to incoming requests") +                      action='store', metavar='FILE', +                      help=("user data filename to serve back to" +                            "incoming requests"))      (options, args) = parser.parse_args()      out = dict()      out['extra'] = args diff --git a/tools/run-pep8 b/tools/run-pep8 index ccd6be5a..086400fc 100755 --- a/tools/run-pep8 +++ b/tools/run-pep8 @@ -1,39 +1,22 @@  #!/bin/bash -if [ $# -eq 0 ]; then -   files=( bin/cloud-init $(find * -name "*.py" -type f) ) +pycheck_dirs=( "cloudinit/" "bin/" "tests/" "tools/" ) +# FIXME: cloud-init modifies sys module path, pep8 does not like +# bin_files=( "bin/cloud-init" ) +CR=" +" +[ "$1" = "-v" ] && { verbose="$1"; shift; } || verbose="" + +set -f +if [ $# -eq 0 ]; then unset IFS +   IFS="$CR" +   files=( "${bin_files[@]}" "${pycheck_dirs[@]}" ) +   unset IFS  else -   files=( "$@" ); +   files=( "$@" )  fi -if [ -f 'hacking.py' ] -then -    base=`pwd` -else -    base=`pwd`/tools/ -fi - -IGNORE="" - -# King Arthur: Be quiet! ... Be Quiet! I Order You to Be Quiet. -IGNORE="$IGNORE,E121" # Continuation line indentation is not a multiple of four -IGNORE="$IGNORE,E123" # Closing bracket does not match indentation of opening bracket's line -IGNORE="$IGNORE,E124" # Closing bracket missing visual indentation -IGNORE="$IGNORE,E125" # Continuation line does not distinguish itself from next logical line -IGNORE="$IGNORE,E126" # Continuation line over-indented for hanging indent -IGNORE="$IGNORE,E127" # Continuation line over-indented for visual indent -IGNORE="$IGNORE,E128" # Continuation line under-indented for visual indent -IGNORE="$IGNORE,E502" # The backslash is redundant between brackets -IGNORE="${IGNORE#,}"  # remove the leading ',' added above - -cmd=( -    ${base}/hacking.py - -    --ignore="$IGNORE" - -    "${files[@]}" -) - -echo -e "\nRunning 'cloudinit' pep8:" -echo "${cmd[@]}" -"${cmd[@]}" +myname=${0##*/} +cmd=( "${myname#run-}" $verbose "${files[@]}" ) +echo "Running: " "${cmd[@]}" 1>&2 +exec "${cmd[@]}" diff --git a/tools/run-pyflakes b/tools/run-pyflakes new file mode 100755 index 00000000..4bea17f4 --- /dev/null +++ b/tools/run-pyflakes @@ -0,0 +1,18 @@ +#!/bin/bash + +PYTHON_VERSION=${PYTHON_VERSION:-2} +CR=" +" +pycheck_dirs=( "cloudinit/" "bin/" "tests/" "tools/" ) + +set -f +if [ $# -eq 0 ]; then +   files=( "${pycheck_dirs[@]}" ) +else +   files=( "$@" ) +fi + +cmd=( "python${PYTHON_VERSION}" -m "pyflakes" "${files[@]}" ) + +echo "Running: " "${cmd[@]}" 1>&2 +exec "${cmd[@]}" diff --git a/tools/run-pyflakes3 b/tools/run-pyflakes3 new file mode 100755 index 00000000..e9f0863d --- /dev/null +++ b/tools/run-pyflakes3 @@ -0,0 +1,2 @@ +#!/bin/sh +PYTHON_VERSION=3 exec "${0%/*}/run-pyflakes" "$@" diff --git a/tools/validate-yaml.py b/tools/validate-yaml.py index 6e164590..ed9037d9 100755 --- a/tools/validate-yaml.py +++ b/tools/validate-yaml.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3  """Try to read a YAML file and report any errors.  """ | 
