SonarQube Plugins
  1. SonarQube Plugins
  2. SONARPLUGINS-1721

pygenie stops the code analyse if it tries to analyse a file not ending with a empty row

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: PYTHON-1.0
    • Component/s: Python
    • Labels:
      None
    • Number of attachments :
      1

      Description

      I found this issue when trying to add our code base to a sonar installation. Several of our files does not end properly, ie the last line of the file is not an empty row. Ive attached a sample of a file not ending with an empty row.

      It seems that the transformer.py can not handle those cases which means that pygenie module crashes with a

      Traceback (most recent call last):
        File "pygenie.py", line 79, in <module>
          main()
        File "pygenie.py", line 73, in main
          stats = cc.measure_complexity(code, item)
        File "/nfs/vm/hudson/home/manpower/jobs/test-sonar/workspace/cc.py", line 92, in measure_complexity
          return CCVisitor(ast, description=module_name).stats
        File "/nfs/vm/hudson/home/manpower/jobs/test-sonar/workspace/cc.py", line 46, in __init__
          ast = compiler.parse(ast)
        File "/usr/lib64/python2.6/compiler/transformer.py", line 51, in parse
          return Transformer().parsesuite(buf)
        File "/usr/lib64/python2.6/compiler/transformer.py", line 128, in parsesuite
          return self.transform(parser.suite(text))
        File "<string>", line 146
      

      I managed to fix this with a simple string.strip() on the file content in pygenie.py, before the file content sent into the cc.py module.

      --- pygenie.py.org      2012-03-29 15:29:59.808375000 +0200
      +++ pygenie.py  2012-03-29 15:30:08.959415000 +0200
      @@ -68,7 +68,7 @@
                   items.add(find_module(arg))
      
           for item in items:
      -        code = open(item).read()
      +        code = open(item).read().strip()
               if command in ('all', 'complexity'):
                   stats = cc.measure_complexity(code, item)
                   pp = cc.PrettyPrinter(sys.stdout, verbose=options.verbose)
      

      As ive been unable to find the source of the pygenie file, I hope that my attached patch can be applied to the supplied version in the plugin. This will fix our problem that we are currently unable to use the python plugin as we have too many files to update to fix this issue.

        Issue Links

          Activity

          Hide
          Evgeny Mandrikov added a comment -

          pygenie can be fully removed after implementation of own parser and complexity analyser - SONARPLUGINS-1830

          Show
          Evgeny Mandrikov added a comment - pygenie can be fully removed after implementation of own parser and complexity analyser - SONARPLUGINS-1830
          Hide
          Eric Hartmann added a comment -

          Closing issues before the release.

          Show
          Eric Hartmann added a comment - Closing issues before the release.

            People

            • Assignee:
              Evgeny Mandrikov
              Reporter:
              Erik Ramfelt
            • Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: