-
Notifications
You must be signed in to change notification settings - Fork 391
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 shebang handling for languages with non-# comments #434
Conversation
Codecov Report
@@ Coverage Diff @@
## master #434 +/- ##
==========================================
+ Coverage 98.94% 98.94% +<.01%
==========================================
Files 75 75
Lines 7646 7651 +5
==========================================
+ Hits 7565 7570 +5
Misses 81 81
Continue to review full report at Codecov.
|
Oh that's interesting! Thank you @jonasbb for pointing this out. |
@@ -144,7 +144,7 @@ def header_to_metadata_and_cell(lines, header_prefix, ext=None): | |||
encoding_re = re.compile(r'^[ \t\f]*{}.*?coding[:=][ \t]*([-_.a-zA-Z0-9]+)'.format(comment)) |
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.
Regarding the encoding, do you know it it should use the language line comment, or #
?
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.
I only know the encoding line from Python 2 programs, so I am not sure if other languages use this feature as well.
tests/test_read_simple_rust.py
Outdated
|
||
# remove version information | ||
def remove_version_info(text): | ||
return '\n'.join([line for line in text.splitlines() if 'version' not in line]) |
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.
For this, typically I use the fixture no_jupytext_version_number
(you just need to add that argument to the test function, and remove the version information in the text)... If that's not clear I can also do it from here.
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.
Thanks, I didn't know this feature exists. I push a new version to use it.
FYI: I copied this test, which is where I found this remove_version_info
function.
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.
Thanks! Oh interesting, later on I will update that other test.
The shebang always starts with the sequence "#!" independend of the comment symbol of the programming language. Add a test with Rust, which uses "//" as the comment symbol.
The shebang always starts with the sequence
#!
independent of the comment symbol of the programming language. Add a test with Rust, which uses//
as the comment symbol.The problem with the existing code is that it uses the comment symbol in the shebang line. The shebang can only start with
#!
though. This leads to two problems.When parsing the shebang, when converting from text to notebook format, it uses a fixed offset of two characters to take the executable path (
line[2:]
), which fails if the comment is not only one character, like the two characters of//
.Similarly, when converting from notebook to text, it uses the comment symbol again and writes an invalid shebang.
The new test is mostly copied from the Python version with slight adaptions.