Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Profiler doesn't like UTF8 BOM #663

Closed
huguesv opened this issue Jul 29, 2015 · 8 comments
Closed

Profiler doesn't like UTF8 BOM #663

huguesv opened this issue Jul 29, 2015 · 8 comments
Assignees
Labels
Milestone

Comments

@huguesv
Copy link
Contributor

huguesv commented Jul 29, 2015

Example output of what happens when your startup file has a BOM and you start profiling:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio - Profil
ing\2.2\proflaun.py", line 35, in <module>
    vspyprof.profile(__file__, globals(), locals(), profdll)
  File "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio - Profil
ing\2.2\vspyprof.py", line 56, in profile
    code = compile(f.read(), file, 'exec')
  File "C:\Projects\Azure\DatasetReader\DatasetReader.py", line 1
    import os
            ^
SyntaxError: invalid character in identifier
Press any key to continue . . .
@zooba
Copy link
Member

zooba commented Jul 29, 2015

We should use tokenize.open where possible, or the runner helpers from the debugger.

As part of a debugger refactor, we may be able to improve overlap with the profiler.

@ariccio
Copy link

ariccio commented Oct 3, 2015

I hit this too:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio - Profiling\2.2\proflaun.py", line 35, in <module>
    vspyprof.profile(__file__, globals(), locals(), profdll)
  File "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio - Profiling\2.2\vspyprof.py", line 56, in profile
    code = compile(f.read(), file, 'exec')
  File "C:\Users\Alexander Riccio\Documents\GitHub\Golf-Analyzer\GolfAnalyzer.py", line 1
    '''
      ^
SyntaxError: invalid character in identifier
Press any key to continue . . .

Sidenote: You're not using a with open(file, "r") as f: context manager in vspyprof.py?:

            f = open(file, "r")
            code = compile(f.read(), file, 'exec')

Eh? Is that a ancient-version-of-python-compatibility thing?

@zooba
Copy link
Member

zooba commented Oct 5, 2015

Yes, we support back to Python 2.5 (which wasn't quite as ancient when that code was first written), and so we can't assume the with statement is available.

It should certainly be in a try/finally though...

@zooba zooba self-assigned this Oct 5, 2015
@zooba zooba added this to the 2.2.1 milestone Oct 5, 2015
zooba added a commit to zooba/PTVS that referenced this issue Oct 5, 2015
Switches to using tokenize.open or tokenize.detect_encoding for reading source files.
@zooba zooba mentioned this issue Oct 5, 2015
@ariccio
Copy link

ariccio commented Oct 5, 2015

Wow, I didn't realize that PTVS was that old! ...but the docs appear to say that the with statement is supported in 2.5?

Also a side note: How many PTVS users actually use Python 2.5?

@zooba
Copy link
Member

zooba commented Oct 5, 2015

It's available, but requires the use of a __future__ import. Not sure why we don't just use that, but IIRC there was some issue we encountered (it predates me :) ).

I suspect not many use Python 2.5 at this stage, but since we don't have to do much to keep supporting it we just keep it around.

@ariccio
Copy link

ariccio commented Oct 6, 2015

Ahh OK, that makes sense.

I see that the fix is committed. When will it be available as an update?

@zooba
Copy link
Member

zooba commented Oct 6, 2015

About the same time as VS 2015 Update 1 (though it'll be available for both VS 2013 and VS 2015, and we'll release a dev build and an RC sooner than that).

@zooba
Copy link
Member

zooba commented Oct 6, 2015

That said, it's a pure-Python change (other than the test), so if you click through to the commit you can copy the contents of the Python files into your installed files and get the fix straight away.

@zooba zooba closed this as completed Oct 6, 2015
zooba added a commit to zooba/PTVS that referenced this issue Oct 6, 2015
Switches to using tokenize.open or tokenize.detect_encoding for reading source files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants