Repository navigation
Add checks for unicode byte order marks - #241
evolvedmicrobe wants to merge 9 commits into
Conversation
|
Hi Nigel, Code point: The string Style points: Please use spaces either side of the assignment (equals), and after the commas in the unicode markers. Also remove the trailing semi-colon on the I'd also really like to see a unit test for this - do you have a small real world example file? |
|
Hi Peter, Code point: The string startswith method accepts a tuple of prefixes (since Python 2.5), so you only need to call it once with your four unicode markers - making this much simpler. See http://docs.python.org/2/library/stdtypes.html Oh nice. One of these days I would spend time setting up the vim autocomplete so it tells me about changes like this. Right now I am writing code assuming methods can take the same arguments I heard of, good to know! Style points: Please use spaces either side of the assignment (equals), and after the commas in the unicode markers. Also remove the trailing semi-colon on the raise line. See PEP8 Style Guide http://www.python.org/dev/peps/pep-0008/ Simple enough. One other style point as well, the string in the exception goes past 80 characters per line, I have found editors can be very brittle in how they handle strings split across lines in white space aware languages so left it that way, but if you have a preferred way of breaking it up let me know. I'd also really like to see a unit test for this - do you have a small real world example file? Yep, in fact this problem came up when I was cross validating the .NET Bio unit tests against the BioPython library (had some failed tests there when I implemented the extended newick format and so was curious about accepted practices to date). Does Biopython have a unit test framework setup? If you can point me towards some documentation I can drop the .newick file and a unit test in. -N — |
|
Minor code point: Move the definition of Minor style point: We're not strict about the 80 line thing but I would split the exception text up something like this: For an introduction to our test framework, see the chapter in the main Tutorial, http://biopython.org/DIST/docs/tutorial/Tutorial.html or http://biopython.org/DIST/docs/tutorial/Tutorial.pdf |
|
Nigel - could you point us at a (small) public sample data file that could be used to create a unit test? Thanks! |
|
Hi Peter, Sorry for leaving that hanging, am traveling and haven’t had time to take a look at the unit tests. I can’t actually seem to get the unit tests framework to work from here (some import problems), but I uploaded an example file and the skeleton of one which I gather should work (does the build process on github check for the test automatically?) Out of curiosity, can I also ask why you wanted the array initialization lifted out of the loop? I would normally have placed it inside to keep all the data relevant to the exception next to it in and as local as possible, and since that branch only executes once I would also have assumed that any performance increment would be trivial. I don’t think it matters either way, but would be curious if there is something about the python internals that makes this a good idea. Cheers, From: Peter Cock [mailto:[email protected]] Nigel - could you point us at a (small) public sample data file that could be used to create a unit test? Thanks! |
hmm… hex editor on mac shows that this file contains unicode characters EF BB BF which open().read() interprets as \xef\xbb\xbf, however unlike on my other machine this is parsed okay, and only throws an error at tree.get_terminals() about it being unicode, this is very annoying.
|
Okay, it looks like there wasn't a way to do this without avoiding the unicode hell. The exception is raised in 2.X versions of python as it should be, but it appears no exception is raised in the 3.X versions, causing the test to fail. I assume this is because 2.X often uses ASCII while 3.X uses unicode-8. My guess would be that the unicode works just fine in 3.X, but don't have an install of that to test. I think it would be nice to leave this in for the 2.X users and maybe skip the test for 3.X, but don't have an install of 3.X to test with so will leave this lie for now. |
|
OK, I'll look at #310 now. P.S. What was did "array initialization lifted out of the loop? " refer to? |
|
Sorry, just saw this email, the array initialization referred to moving this tuple outside of the for loop. |
|
Thanks - it is outside the loop now :) |
|
@evolvedmicrobe would you agree to dual license your contributions to Biopython to date (including this and #239) as per #898? |
|
@peterjc absolutely! |
|
Thank you 👍 |
Original author Eric Talevich, authors on whose code it was based (Frank and Cymon), and contributors since as tracked with version control have agreed: - Aaron Gallagher (@habnabit) biopython#898 (comment) - Allis Tauri (@allista) biopython#898 (comment) - Ben Morris (@bendmorris) biopython#898 (comment) - Byron Smith (@bsmith89) biopython#898 (comment) - Chris Rands (@chris-rands) biopython#1301 - Christian Brueffer (@cbrueffer) biopython#898 (comment) - Cymon J. Cox (@cymon) biopython#898 (comment) - Eric Talevich (@etal) biopython#898 (comment) - Frank Kauff (@frankkl) biopython#2246 (comment) - Francesco Gastaldello (@Gasta88) biopython#1063 - @morrme biopython#1172 (comment) - Nigel Delaney (@evolvedmicrobe) biopython#241 (comment) - Peter Cock (@peterjc) biopython#898 (comment) - Sergio Valqui (@svalqui) biopython#1749 - Sourav Singh (@souravsingh) biopython#957 - Suresh Panneerselvam (@Amrithasuresh) biopython#1575 - Vishnu Chilakamarri (@vvc11) biopython#898 (comment)
Original author Eric Talevich, authors on whose code it was based (Frank and Cymon), and contributors since as tracked with version control have agreed: - Aaron Gallagher (@habnabit) biopython#898 (comment) - Allis Tauri (@allista) biopython#898 (comment) - Ben Morris (@bendmorris) biopython#898 (comment) - Byron Smith (@bsmith89) biopython#898 (comment) - Chris Rands (@chris-rands) biopython#1301 - Christian Brueffer (@cbrueffer) biopython#898 (comment) - Cymon J. Cox (@cymon) biopython#898 (comment) - Eric Talevich (@etal) biopython#898 (comment) - Frank Kauff (@frankkl) biopython#2246 (comment) - Francesco Gastaldello (@Gasta88) biopython#1063 - @morrme biopython#1172 (comment) - Nigel Delaney (@evolvedmicrobe) biopython#241 (comment) - Peter Cock (@peterjc) biopython#898 (comment) - Sergio Valqui (@svalqui) biopython#1749 - Sourav Singh (@souravsingh) biopython#957 - Suresh Panneerselvam (@Amrithasuresh) biopython#1575 - Vishnu Chilakamarri (@vvc11) biopython#898 (comment)
Original author Eric Talevich, authors on whose code it was based (Frank and Cymon), and contributors since as tracked with version control have agreed: - Aaron Gallagher (@habnabit) #898 (comment) - Allis Tauri (@allista) #898 (comment) - Ben Morris (@bendmorris) #898 (comment) - Byron Smith (@bsmith89) #898 (comment) - Chris Rands (@chris-rands) #1301 - Christian Brueffer (@cbrueffer) #898 (comment) - Cymon J. Cox (@cymon) #898 (comment) - Eric Talevich (@etal) #898 (comment) - Frank Kauff (@frankkl) #2246 (comment) - Francesco Gastaldello (@Gasta88) #1063 - @morrme #1172 (comment) - Nigel Delaney (@evolvedmicrobe) #241 (comment) - Peter Cock (@peterjc) #898 (comment) - Sergio Valqui (@svalqui) #1749 - Sourav Singh (@souravsingh) #957 - Suresh Panneerselvam (@Amrithasuresh) #1575 - Vishnu Chilakamarri (@vvc11) #898 (comment)
Original author Eric Talevich and contributors since as tracked by version control have agreed: - Adhemar Zerlotini (@azneto) biopython#1412 (comment) - Andrey Raspopov (@Andrey-Raspopov) biopython#2444 - Carlos Pena (@carlosp420) biopython#898 (comment) - Chris Rands (@chris-rands) biopython#1301 - Christian Brueffer (@cbrueffer) biopython#898 (comment) - Eric Talevich (@etal) biopython#898 (comment) - Michiel de Hoon (@mdehoon) biopython#898 (comment) - @morrme biopython#1172 (comment) - Nick Negretti (@nimne) biopython#1768 (comment) - Nigel Delaney (@evolvedmicrobe) biopython#241 (comment) - Peter Cock (@peterjc) biopython#898 (comment) - Sergio Valqui (@svalqui) biopython#1749 - Suresh Panneerselvam (@Amrithasuresh) biopython#1575
Original author Eric Talevich and contributors since as tracked by version control have agreed: - Adhemar Zerlotini (@azneto) #1412 (comment) - Andrey Raspopov (@Andrey-Raspopov) #2444 - Carlos Pena (@carlosp420) #898 (comment) - Chris Rands (@chris-rands) #1301 - Christian Brueffer (@cbrueffer) #898 (comment) - Eric Talevich (@etal) #898 (comment) - Michiel de Hoon (@mdehoon) #898 (comment) - @morrme #1172 (comment) - Nick Negretti (@nimne) #1768 (comment) - Nigel Delaney (@evolvedmicrobe) #241 (comment) - Peter Cock (@peterjc) #898 (comment) - Sergio Valqui (@svalqui) #1749 - Suresh Panneerselvam (@Amrithasuresh) #1575
Original author Eric Talevich and contributors since as tracked by version control have agreed: - Adhemar Zerlotini (@azneto) biopython#1412 (comment) - Andrey Raspopov (@Andrey-Raspopov) biopython#2444 - Carlos Pena (@carlosp420) biopython#898 (comment) - Chris Rands (@chris-rands) biopython#1301 - Christian Brueffer (@cbrueffer) biopython#898 (comment) - Eric Talevich (@etal) biopython#898 (comment) - Michiel de Hoon (@mdehoon) biopython#898 (comment) - @morrme biopython#1172 (comment) - Nick Negretti (@nimne) biopython#1768 (comment) - Nigel Delaney (@evolvedmicrobe) biopython#241 (comment) - Peter Cock (@peterjc) biopython#898 (comment) - Sergio Valqui (@svalqui) biopython#1749 - Suresh Panneerselvam (@Amrithasuresh) biopython#1575
No description provided.