-
Notifications
You must be signed in to change notification settings - Fork 317
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
Resolves issues with UTF-8 #906
Conversation
Oh good, I'm really glad this resolved the issue!
I just did a quick grep through the source code there aren't really any other places in the main code base, but there are a few places in the tests that could probably be fixed. Here is a patch that fixes all the places I think might be susceptible to this issue (it also modifies the header notebook used in the tests to include special characters, so hopefully we won't get a recurrence of this bug again): You can apply it with Thanks for working on this! |
I'll look into this test failure: def test_collect_timestamp_skip_older(self, course_dir, archive_dir):
extracted_dir = join(archive_dir, "..", "extracted")
submitted_dir = join(course_dir, "submitted")
# submissions are sorted so a before b
os.makedirs(join(archive_dir, 'ps1_hacker_a_2017-01-30-15-30-10'))
with io.open(join(archive_dir, 'ps1_hacker_a_2017-01-30-15-30-10', 'problem1.ipynb'), mode='w', encoding='utf-8') as fh:
fh.write('') E TypeError: write() argument 1 must be unicode, not str |
Oops, sorry. I tested my patch on python 3 but not python 2, which is where it seems the test failures are coming from... I should have known better! Thanks for looking into it regardless. |
It seems Python 2's string literals are not Unicode literals, while Python 3's string literals are by default Unicode encoded with utf-8. This test was actually passing on Windows 10. So, if nbgrader is run on Linux, with Python 27, then this is an issue it seems. The fix is probably to include the following in one of the first two lines of some files, (perhaps only the files where string literals is written to files?). Perhaps someone with previous know-how of encoding issues can suggest a clear line of action?
ReferencePython 2: https://docs.python.org/2/howto/unicode.html#unicode-literals-in-python-source-code |
What I've learnedTo analyze the error...Use Linux and Python 2 and run the following test.
Difference between Unicode and utf-8
What
|
Ugh, yeah, dealing with unicode support between python 2 and 3 can be a real pain---thanks for looking into this so thoroughly! I think using the I am currently working on finishing up another PR but I'll look into this some more when I'm done with that. |
@jhamrick okay! I went with it (using the
Pweh! Closer... perhaps... at least :) |
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, this looks great! I will merge once the tests pass.
@@ -1,3 +1,5 @@ | |||
# coding: utf-8 |
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 think these lines aren't strictly necessary since this will only make a difference if the special characters are in the python source code itself, and I don't think this is the case anywhere in nbgrader. But I don't think it hurts to have these lines, so it's fine for them to be there.
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.
Ah, I was uncertain about this myself, thanks for the feedback!
Tests are passing! Thanks for putting in so much work for this 🎉 |
@jhamrick Thanks for the encouragement and guidance! I really appreciate Jupyter and the tools surrounding it such as the nbgrader project - so thanks for your work as well :D |
Thanks! 😄 |
Issue #902 is resolved by this PR, but this PR isn't very thorough yet, the fix of clarifying what encoding to use when reading a file on windows (10) might need to be applied at more places in the nbgrader project.
@jhamrick correctly guessed that this change would resolve the issue, I just tried it.