-
Notifications
You must be signed in to change notification settings - Fork 179
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
fix(api): keep proto contents in bytes for longer #14446
Conversation
When we parse python protocols, we were doing it by (1) making it into a string with decode('utf-8') and then (2) passing the string ast.parse(). The problem with this is that decode('utf-8') does not apply "universal newlines", which means that the code object created by compiling the ast will have line numbers that are around twice what they should be under certain circumstances (windows machine, crlf file, mercury in the seventh house, etc). Then, when we go and display a nice error message about a syntax error or whatever, the user says "why is this error message pointing to a place past the end of my protocol". This should fix that by keeping the protocol contents in bytes form all the way through to passing ast.parse() a bytes that _has never been through str.decode('utf-8')_ which should preserve everything.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## chore_release-7.2.0 #14446 +/- ##
=======================================================
- Coverage 68.10% 68.03% -0.08%
=======================================================
Files 2518 2518
Lines 72031 72027 -4
Branches 9245 9245
=======================================================
- Hits 49059 49003 -56
- Misses 20770 20822 +52
Partials 2202 2202
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, juicy.
Very happy to have less encoding/decoding. Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! CI is failing but it looks like some Python environment thing unrelated to this PR. This LGTM if tests and linting pass locally.
When we parse python protocols, we were doing it by (1) making it into a string with decode('utf-8') and then (2) passing the string ast.parse(). The problem with this is that decode('utf-8') does not apply "universal newlines", which means that the code object created by compiling the ast will have line numbers that are around twice what they should be under certain circumstances (windows machine, crlf file, mercury in the seventh house, etc). Then, when we go and display a nice error message about a syntax error or whatever, the user says "why is this error message pointing to a place past the end of my protocol". This should fix that by keeping the protocol contents in bytes form all the way through to passing ast.parse() a bytes that _has never been through str.decode('utf-8')_ which should preserve everything.
When we parse python protocols, we were doing it by (1) making it into a string with decode('utf-8') and then (2) passing the string ast.parse(). The problem with this is that decode('utf-8') does not apply "universal newlines", which means that the code object created by compiling the ast will have line numbers that are around twice what they should be under certain circumstances (windows machine, crlf file, mercury in the seventh house, etc). Then, when we go and display a nice error message about a syntax error or whatever, the user says "why is this error message pointing to a place past the end of my protocol".
This should fix that by keeping the protocol contents in bytes form all the way through to passing ast.parse() a bytes that has never been through str.decode('utf-8') which should preserve everything.
Testing
flex_mag_mod.py.zip (unzip it first) that has (1) an error and (2) crlf newlines
opentrons_simulate
and in the app