~ubuntu-branches/ubuntu/raring/nova/raring-proposed

« back to all changes in this revision

Viewing changes to .pc/fix-ubuntu-tests.patch/tools/hacking.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, James Page
  • Date: 2013-03-20 12:59:22 UTC
  • mfrom: (1.1.69)
  • Revision ID: package-import@ubuntu.com-20130320125922-ohvfav96lemn9wlz
Tags: 1:2013.1~rc1-0ubuntu1
[ Chuck Short ]
* New upstream release.
* debian/patches/avoid_setuptools_git_dependency.patch: Refreshed.
* debian/control: Clean up dependencies:
  - Dropped python-gflags no longer needed.
  - Dropped python-daemon no longer needed.
  - Dropped python-glance no longer needed.
  - Dropped python-lockfile no longer needed.
  - Dropped python-simplejson no longer needed.
  - Dropped python-tempita no longer needed.
  - Dropped python-xattr no longer needed.
  - Add sqlite3 required for the testsuite.

[ James Page ]
* d/watch: Update uversionmangle to deal with upstream versioning
  changes, remove tarballs.openstack.org. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
import subprocess
30
30
import sys
31
31
import tokenize
 
32
import traceback
32
33
 
33
34
import pep8
34
35
 
176
177
 
177
178
    Examples:
178
179
    Okay: from os import path
 
180
    Okay: from os import path as p
 
181
    Okay: from os import (path as p)
179
182
    Okay: import os.path
180
183
    Okay: from nova.compute import rpcapi
181
184
    N302: from os.path import dirname as dirname2
 
185
    N302: from os.path import (dirname as dirname2)
182
186
    N303: from os.path import *
183
187
    N304: from .compute import rpcapi
184
188
    """
186
190
    # pass the doctest, since the relativity depends on the file's locality
187
191
 
188
192
    def is_module_for_sure(mod, search_path=sys.path):
 
193
        mod = mod.replace('(', '')  # Ignore parentheses
189
194
        try:
190
195
            mod_name = mod
191
196
            while '.' in mod_name:
201
206
                # NOTE(vish): the import error might be due
202
207
                #             to a missing dependency
203
208
                missing = str(exc).split()[-1]
204
 
                if missing != mod.split('.')[-1]:
 
209
                if (missing != mod.split('.')[-1] or
 
210
                        "cannot import" in str(exc)):
205
211
                    _missingImport.add(missing)
206
212
                    return True
207
213
                return False
 
214
            except Exception, exc:
 
215
                # NOTE(jogo) don't stack trace if unexpected import error,
 
216
                # log and continue.
 
217
                traceback.print_exc()
 
218
                return False
208
219
        return True
209
220
 
210
221
    def is_module(mod):
302
313
            yield (0, "N307: nova.db import not allowed in nova/virt/*")
303
314
 
304
315
 
305
 
def in_docstring_position(previous_logical):
306
 
    return (previous_logical.startswith("def ") or
307
 
        previous_logical.startswith("class "))
 
316
def is_docstring(physical_line, previous_logical):
 
317
    """Return True if found docstring
 
318
    'A docstring is a string literal that occurs as the first statement in a
 
319
    module, function, class,'
 
320
    http://www.python.org/dev/peps/pep-0257/#what-is-a-docstring
 
321
    """
 
322
    line = physical_line.lstrip()
 
323
    start = max([line.find(i) for i in START_DOCSTRING_TRIPLE])
 
324
    end = max([line[-4:-1] == i for i in END_DOCSTRING_TRIPLE])
 
325
    if (previous_logical.startswith("def ") or
 
326
            previous_logical.startswith("class ")):
 
327
        if start is 0:
 
328
            return True
 
329
        else:
 
330
            # Handle multi line comments
 
331
            return end and start in (-1, len(line) - 4)
308
332
 
309
333
 
310
334
def nova_docstring_start_space(physical_line, previous_logical):
314
338
    Docstring should not start with space
315
339
 
316
340
    Okay: def foo():\n    '''This is good.'''
 
341
    Okay: def foo():\n    a = ''' This is not a docstring.'''
 
342
    Okay: def foo():\n    pass\n    ''' This is not.'''
317
343
    N401: def foo():\n    ''' This is not.'''
318
344
    """
319
345
    # short circuit so that we don't fail on our own fail test
324
350
    # it's important that we determine this is actually a docstring,
325
351
    # and not a doc block used somewhere after the first line of a
326
352
    # function def
327
 
    if in_docstring_position(previous_logical):
 
353
    if is_docstring(physical_line, previous_logical):
328
354
        pos = max([physical_line.find(i) for i in START_DOCSTRING_TRIPLE])
329
 
        if pos != -1 and len(physical_line) > pos + 4:
330
 
            if physical_line[pos + 3] == ' ':
331
 
                return (pos, "N401: docstring should not start with"
332
 
                        " a space")
333
 
 
334
 
 
335
 
def nova_docstring_one_line(physical_line):
 
355
        if physical_line[pos + 3] == ' ':
 
356
            return (pos, "N401: docstring should not start with"
 
357
                    " a space")
 
358
 
 
359
 
 
360
def nova_docstring_one_line(physical_line, previous_logical):
336
361
    r"""Check one line docstring end.
337
362
 
338
363
    nova HACKING guide recommendation for one line docstring:
339
364
    A one line docstring looks like this and ends in punctuation.
340
365
 
341
 
    Okay: '''This is good.'''
342
 
    Okay: '''This is good too!'''
343
 
    Okay: '''How about this?'''
344
 
    N402: '''This is not'''
345
 
    N402: '''Bad punctuation,'''
 
366
    Okay: def foo():\n    '''This is good.'''
 
367
    Okay: def foo():\n    '''This is good too!'''
 
368
    Okay: def foo():\n    '''How about this?'''
 
369
    Okay: def foo():\n    a = '''This is not a docstring'''
 
370
    Okay: def foo():\n    pass\n    '''This is not a docstring'''
 
371
    Okay: class Foo:\n    pass\n    '''This is not a docstring'''
 
372
    N402: def foo():\n    '''This is not'''
 
373
    N402: def foo():\n    '''Bad punctuation,'''
 
374
    N402: class Foo:\n    '''Bad punctuation,'''
346
375
    """
347
376
    #TODO(jogo) make this apply to multi line docstrings as well
348
377
    line = physical_line.lstrip()
349
 
 
350
 
    if line.startswith('"') or line.startswith("'"):
 
378
    if is_docstring(physical_line, previous_logical):
351
379
        pos = max([line.find(i) for i in START_DOCSTRING_TRIPLE])  # start
352
380
        end = max([line[-4:-1] == i for i in END_DOCSTRING_TRIPLE])  # end
353
381
 
356
384
                return pos, "N402: one line docstring needs punctuation."
357
385
 
358
386
 
359
 
def nova_docstring_multiline_end(physical_line, previous_logical):
 
387
def nova_docstring_multiline_end(physical_line, previous_logical, tokens):
360
388
    r"""Check multi line docstring end.
361
389
 
362
390
    nova HACKING guide recommendation for docstring:
363
391
    Docstring should end on a new line
364
392
 
365
393
    Okay: '''foobar\nfoo\nbar\n'''
366
 
    N403: def foo():\n'''foobar\nfoo\nbar\n   d'''\n\n
 
394
    Okay: def foo():\n    '''foobar\nfoo\nbar\n'''
 
395
    Okay: class Foo:\n    '''foobar\nfoo\nbar\n'''
 
396
    Okay: def foo():\n    a = '''not\na\ndocstring'''
 
397
    Okay: def foo():\n    pass\n'''foobar\nfoo\nbar\n   d'''
 
398
    N403: def foo():\n    '''foobar\nfoo\nbar\ndocstring'''
 
399
    N403: class Foo:\n    '''foobar\nfoo\nbar\ndocstring'''\n\n
367
400
    """
368
 
    if in_docstring_position(previous_logical):
 
401
    # if find OP tokens, not a docstring
 
402
    ops = [t for t, _, _, _, _ in tokens if t == tokenize.OP]
 
403
    if (is_docstring(physical_line, previous_logical) and len(tokens) > 0 and
 
404
            len(ops) == 0):
369
405
        pos = max(physical_line.find(i) for i in END_DOCSTRING_TRIPLE)
370
 
        if pos != -1 and len(physical_line) == pos + 4:
371
 
            if physical_line.strip() not in START_DOCSTRING_TRIPLE:
372
 
                return (pos, "N403: multi line docstring end on new line")
 
406
        if physical_line.strip() not in START_DOCSTRING_TRIPLE:
 
407
            return (pos, "N403: multi line docstring end on new line")
373
408
 
374
409
 
375
410
def nova_docstring_multiline_start(physical_line, previous_logical, tokens):
379
414
    Docstring should start with A multi line docstring has a one-line summary
380
415
 
381
416
    Okay: '''foobar\nfoo\nbar\n'''
382
 
    N404: def foo():\n'''\nfoo\nbar\n''' \n\n
 
417
    Okay: def foo():\n    a = '''\nnot\na docstring\n'''
 
418
    N404: def foo():\n'''\nfoo\nbar\n'''\n\n
383
419
    """
384
 
    if in_docstring_position(previous_logical):
 
420
    if is_docstring(physical_line, previous_logical):
385
421
        pos = max([physical_line.find(i) for i in START_DOCSTRING_TRIPLE])
386
422
        # start of docstring when len(tokens)==0
387
423
        if len(tokens) == 0 and pos != -1 and len(physical_line) == pos + 4:
391
427
 
392
428
 
393
429
def nova_no_cr(physical_line):
394
 
    r"""Check that we only use newlines not cariage returns.
 
430
    r"""Check that we only use newlines not carriage returns.
395
431
 
396
432
    Okay: import os\nimport sys
397
433
    # pep8 doesn't yet replace \r in strings, will work on an
560
596
    nova HACKING recommends not referencing a bug or blueprint in first line,
561
597
    it should provide an accurate description of the change
562
598
    N801
563
 
    N802 Title limited to 50 chars
 
599
    N802 Title limited to 72 chars
564
600
    """
565
601
    #Get title of most recent commit
566
602
 
585
621
               "description of the change, not just a reference to a bug "
586
622
               "or blueprint" % title.strip())
587
623
        error = True
 
624
    # HACKING.rst recommends commit titles 50 chars or less, but enforces
 
625
    # a 72 character limit
588
626
    if len(title.decode('utf-8')) > 72:
589
627
        print ("N802: git commit title ('%s') should be under 50 chars"
590
628
                % title.strip())