~ubuntu-branches/ubuntu/quantal/nova/quantal-proposed

« back to all changes in this revision

Viewing changes to tools/hacking.py

  • Committer: Package Import Robot
  • Author(s): Adam Gandelman, Adam Gandelman, Chuck Short
  • Date: 2012-08-27 15:37:18 UTC
  • mfrom: (1.1.60)
  • Revision ID: package-import@ubuntu.com-20120827153718-lj8er44eqqz1gsrj
Tags: 2012.2~rc1~20120827.15815-0ubuntu1
[ Adam Gandelman ]
* New upstream release.

[ Chuck Short ]
* debian/patches/0001-Update-tools-hacking-for-pep8-1.2-and-
  beyond.patch: Dropped we dont run pep8 tests anymore.
* debian/control: Drop pep8 build depends
* debian/*.upstart.in: Make sure we transition correctly from runlevel
  1 to 2. (LP: #820694)

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
 
48
48
IMPORT_EXCEPTIONS = ['sqlalchemy', 'migrate', 'nova.db.sqlalchemy.session']
49
49
DOCSTRING_TRIPLE = ['"""', "'''"]
50
 
VERBOSE_MISSING_IMPORT = False
 
50
VERBOSE_MISSING_IMPORT = os.getenv('HACKING_VERBOSE_MISSING_IMPORT', 'False')
51
51
 
52
52
 
53
53
# Monkey patch broken excluded filter in pep8
137
137
    N201
138
138
    """
139
139
    if logical_line.startswith("except:"):
140
 
        yield 6, "NOVA N201: no 'except:' at least use 'except Exception:'"
 
140
        return 6, "NOVA N201: no 'except:' at least use 'except Exception:'"
141
141
 
142
142
 
143
143
def nova_except_format_assert(logical_line):
148
148
    N202
149
149
    """
150
150
    if logical_line.startswith("self.assertRaises(Exception"):
151
 
        yield 1, "NOVA N202: assertRaises Exception too broad"
 
151
        return 1, "NOVA N202: assertRaises Exception too broad"
152
152
 
153
153
 
154
154
def nova_one_import_per_line(logical_line):
166
166
    if (pos > -1 and (parts[0] == "import" or
167
167
                      parts[0] == "from" and parts[2] == "import") and
168
168
        not is_import_exception(parts[1])):
169
 
        yield pos, "NOVA N301: one import per line"
 
169
        return pos, "NOVA N301: one import per line"
170
170
 
171
171
_missingImport = set([])
172
172
 
218
218
            else:
219
219
                name = logical_line.split()[1]
220
220
                if name not in _missingImport:
221
 
                    if VERBOSE_MISSING_IMPORT:
222
 
                        print >> sys.stderr, ("ERROR: import '%s' failed: %s" %
223
 
                            (name, exc))
 
221
                    if VERBOSE_MISSING_IMPORT != 'False':
 
222
                        print >> sys.stderr, ("ERROR: import '%s' in %s "
 
223
                                              "failed: %s" %
 
224
                            (name, pep8.current_file, exc))
224
225
                    _missingImport.add(name)
225
226
                added = False
226
227
                sys.path.pop()
240
241
            (len(split_line) == 2 or
241
242
            (len(split_line) == 4 and split_line[2] == "as"))):
242
243
        mod = split_line[1]
243
 
        rval = importModuleCheck(mod)
244
 
        if rval != None:
245
 
            yield rval
 
244
        return importModuleCheck(mod)
246
245
 
247
246
    # TODO(jogo) handle "from x import *"
248
247
 
399
398
        map(gen.send, tokens)
400
399
        gen.close()
401
400
    except LocalizationError as e:
402
 
        yield e.args
 
401
        return e.args
403
402
 
404
403
#TODO(jogo) Dict and list objects
405
404
 
437
436
    """
438
437
    #Get title of most recent commit
439
438
 
440
 
    subp = subprocess.Popen(['git', 'log', '--pretty=%s', '-1'],
 
439
    subp = subprocess.Popen(['git', 'log', '--no-merges', '--pretty=%s', '-1'],
441
440
            stdout=subprocess.PIPE)
442
441
    title = subp.communicate()[0]
443
442
    if subp.returncode:
451
450
                    '([Bb]lue[Pp]rint|[Bb][Pp])[\s\#:]*([A-Za-z0-9\\-]+)')
452
451
    GIT_REGEX = re.compile(git_keywords)
453
452
 
 
453
    error = False
454
454
    #NOTE(jogo) if match regex but over 3 words, acceptable title
455
455
    if GIT_REGEX.search(title) is not None and len(title.split()) <= 3:
456
456
        print ("N801: git commit title ('%s') should provide an accurate "
457
457
               "description of the change, not just a reference to a bug "
458
458
               "or blueprint" % title.strip())
 
459
        error = True
459
460
    if len(title.decode('utf-8')) > 72:
460
461
        print ("N802: git commit title ('%s') should be under 50 chars"
461
462
                % title.strip())
 
463
        error = True
 
464
    return error
462
465
 
463
466
if __name__ == "__main__":
464
467
    #include nova path
465
468
    sys.path.append(os.getcwd())
466
469
    #Run once tests (not per line)
467
 
    once_git_check_commit_title()
 
470
    once_error = once_git_check_commit_title()
468
471
    #NOVA error codes start with an N
469
472
    pep8.ERRORCODE_REGEX = re.compile(r'[EWN]\d{3}')
470
473
    add_nova()
474
477
    pep8.input_dir = input_dir
475
478
    try:
476
479
        pep8._main()
 
480
        sys.exit(once_error)
477
481
    finally:
478
482
        if len(_missingImport) > 0:
479
483
            print >> sys.stderr, ("%i imports missing in this test environment"