there is no flexibility with different python versions.

Issue #655 closed
Abel Asefa
created an issue

When the main process is running with python3. But some other subprocesses were running with python2, it could not get the correct result and produce a SyntaxError.

  File ".../python/python3.5.2/python3.5/site-packages/coverage/parser.py", line 363, in __init__
    self.code = compile_unicode(text, filename, "exec")
  File ".../python/python3.5.2/lib/python3.5/site-packages/coverage/phystokens.py", line 286, in compile_unicode
    code = compile(source, filename, mode)
  File ".../constructor.py", line 130
    except TypeError, exc:
                    ^
SyntaxError: invalid syntax


During handling of the above exception, another exception occurred:

  File "/lab/python/python3.5.2/lib/python3.5/site-packages/coverage/control.py", line 1095, in html_report
    return reporter.report(morfs)
  File "/lab/python/python3.5.2/lib/python3.5/site-packages/coverage/html.py", line 139, in report
    self.report_files(self.html_file, morfs, self.config.html_dir)
  File "/lab/python/python3.5.2/lib/python3.5/site-packages/coverage/report.py", line 91, in report_files
    report_fn(fr, self.coverage._analyze(fr))
  File "/lab/python/python3.5.2/lib/python3.5/site-packages/coverage/control.py", line 968, in _analyze
    return Analysis(self.data, it)
  File "/lab/python/python3.5.2/lib/python3.5/site-packages/coverage/results.py", line 19, in __init__
    self.statements = self.file_reporter.lines()
  File "/lab/python/python3.5.2/lib/python3.5/site-packages/coverage/python.py", line 186, in lines
    return self.parser.statements
  File "/lab/python/python3.5.2/lib/python3.5/site-packages/coverage/python.py", line 181, in parser
    self._parser.parse_source()
  File "/lab/python/python3.5.2/lib/python3.5/site-packages/coverage/parser.py", line 237, in parse_source
    self._raw_parse()
File "/lab/python/python3.5.2/lib/python3.5/site-packages/coverage/parser.py", line 206, in _raw_parse
    self.raw_statements.update(self.byte_parser._find_statements())
  File "/lab/python/python3.5.2/lib/python3.5/site-packages/coverage/parser.py", line 96, in byte_parser
    self._byte_parser = ByteParser(self.text, filename=self.filename)
  File "/lab/python/python3.5.2/lib/python3.5/site-packages/coverage/parser.py", line 367, in __init__
    filename, synerr.msg, synerr.lineno

coverage.misc.NotPython: Couldn't parse '.../python2/yaml/constructor.py' as Python source: 'invalid syntax' at line 130 

Comments (6)

  1. Ned Batchelder repo owner

    This is an interesting use. Can you provide me with details of how you are running your code? Is your code online, or can you give me a way to reproduce it?

  2. Abel Asefa reporter

    unfortunately, the code is not online. The easiest way to reproduce the issue is to have 2 python versions (2 and 3) and two different scripts (with python 2 and 3). And run the script in V3. The script which runs V3 should call the other script running V2 as a subprocess. Note here, Both scripts have their own python executor (python 3 for the script written in python 3 and python 2 for the script written in python 2).

    Is this useful to reproduce it?

  3. Ned Batchelder repo owner

    @Abel Asefa If you could whip up a small repo that does what you're describing, that would be very helpful. I don't understand how you are getting coverage measurement on the subprocess, for example? If I try to make something like you are describing, we are going to go back and forth a few times in order to get it right. Please make something with all of the code, and an explicit set of commands to run to make the problem appear.

  4. Abel Asefa reporter

    Hi Ned,

    Here is an example code.

    https://bitbucket.org/abelandk/coverage-test/src

    The error is

    $ ./python3_script.py
    python2 - v 2.7 (r27:82525, Jul  4 2010, 07:43:08) [MSC v.1500 64 bit (AMD64)]
    1
    python3 - v 3.6.3 (v3.6.3:2c5fed8, Oct  3 2017, 17:26:49) [MSC v.1900 32 bit (Intel)]
    dummy method output is : 4950
    Traceback (most recent call last):
      File "C:\Lib\site-packages\coverage\parser.py", line 363, in __init__
        self.code = compile_unicode(text, filename, "exec")
      File "C:\Lib\site-packages\coverage\phystokens.py", line 286, in compile_unicode
        code = compile(source, filename, mode)
      File "C:\Users\EABEASE.ERICSSON\Desktop\coverage_multiple_v\coverage-test\python2_script.py", line 5
        print 3/2
              ^
    SyntaxError: Missing parentheses in call to 'print'. Did you mean print(int 3/2)?
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "./python3_script.py", line 28, in <module>
        cov.html_report()
      File "C:\Lib\site-packages\coverage\control.py", line 1095, in html_report
        return reporter.report(morfs)
      File "C:\Lib\site-packages\coverage\html.py", line 139, in report
        self.report_files(self.html_file, morfs, self.config.html_dir)
      File "C:\Lib\site-packages\coverage\report.py", line 91, in report_files
        report_fn(fr, self.coverage._analyze(fr))
      File "C:\Lib\site-packages\coverage\control.py", line 968, in _analyze
        return Analysis(self.data, it)
      File "C:\Lib\site-packages\coverage\results.py", line 19, in __init__
        self.statements = self.file_reporter.lines()
      File "C:\Lib\site-packages\coverage\python.py", line 186, in lines
        return self.parser.statements
      File "C:\Lib\site-packages\coverage\python.py", line 181, in parser
        self._parser.parse_source()
      File "C:\Lib\site-packages\coverage\parser.py", line 237, in parse_source
        self._raw_parse()
      File "C:\Lib\site-packages\coverage\parser.py", line 206, in _raw_parse
        self.raw_statements.update(self.byte_parser._find_statements())
      File "C:\Lib\site-packages\coverage\parser.py", line 96, in byte_parser
        self._byte_parser = ByteParser(self.text, filename=self.filename)
      File "C:\Lib\site-packages\coverage\parser.py", line 367, in __init__
        filename, synerr.msg, synerr.lineno
    coverage.misc.NotPython: Couldn't parse 'C:\Users\EABEASE.ERICSSON\Desktop\coverage_multiple_v\coverage-test\python2_script.py' as Python source: 'Missing parentheses in call to 'print'. Did you mean print(int 3/2)?' at line 5
    
  5. Ned Batchelder repo owner

    Thanks for the code. It has some Windows specifics, so I can't quite run it as-is, but I'm trying to understand it. You are using subprocess.call with shell=True. On Windows, will that use the shebang line to find the interpreter?

    You say to run the python3_script.py with Python 3, but then why is the first line of your output above the Python 2 output line?

    I tried adjusting the details to work on my Mac, and I got this when I ran it:

    $ python python3_script.py
    python3 - v 3.6.5 (default, Mar 28 2018, 22:07:42)
    [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]
    dummy method output is : 4950
    python2 - v 2.7.14 (default, Oct  4 2017, 09:45:53)
    [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)]
    1
    

    The resulting data file has the python3 lines, but no python2 lines, so something is still not right here. I created the 00coverage.pth file in both Python installations. I assume you have some python2 lines in your data file?

  6. Log in to comment