Skip to content

Python 3 updates for SFF support and tests - #2499

Merged
peterjc merged 5 commits into
biopython:masterfrom
peterjc:test_index_py3
Jan 7, 2020
Merged

peterjc merged 5 commits into
biopython:masterfrom
peterjc:test_index_py3

Conversation

@peterjc

@peterjc peterjc commented Jan 6, 2020

Copy link
Copy Markdown
Member

This pull request addresses in part issue #2490.

See also discussion on #2496.

  • I hereby agree to dual licence this and any previous contributions under both
    the Biopython License Agreement AND the BSD 3-Clause License.

  • I have read the CONTRIBUTING.rst file, have run flake8 locally, and
    understand that AppVeyor and TravisCI will be used to confirm the Biopython unit
    tests and style checks pass with these changes.

  • I have added my name to the alphabetical contributors listings in the files
    NEWS.rst and CONTRIB.rst as part of this pull request, am listed
    already, or do not wish to be listed. (This acknowledgement is optional.)

The existing method for checking text vs binary
mode needed a substantial rewrite for Python 3,
and this way is simpler and more pythonic.
@peterjc
peterjc requested a review from mdehoon January 6, 2020 15:11
@peterjc peterjc mentioned this pull request Jan 6, 2020
3 tasks done
@codecov

codecov Bot commented Jan 6, 2020 •

Copy link
Copy Markdown

Codecov Report

Merging #2499 into master will increase coverage by 0.16%.
The diff coverage is 50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2499      +/-   ##
==========================================
+ Coverage   84.77%   84.94%   +0.16%     
==========================================
  Files         322      322              
  Lines       52437    53234     +797     
==========================================
+ Hits        44456    45217     +761     
- Misses       7981     8017      +36
Impacted Files Coverage Δ
Bio/SeqIO/SffIO.py 85.71% <50%> (-0.54%) ⬇️
Bio/Wise/psw.py 68.18% <0%> (-1.16%) ⬇️
Bio/Statistics/__init__.py 100% <0%> (ø) ⬆️
Bio/CAPS/__init__.py 100% <0%> (ø) ⬆️
Bio/Sequencing/Applications/_bwa.py 100% <0%> (ø) ⬆️
Bio/motifs/__init__.py 83.62% <0%> (+0.05%) ⬆️
Bio/Application/__init__.py 88.48% <0%> (+0.74%) ⬆️
Bio/Affy/CelFile.py 97.5% <0%> (+0.76%) ⬆️
Bio/Data/IUPACData.py 98.75% <0%> (+0.83%) ⬆️
Bio/SwissProt/__init__.py 91.33% <0%> (+1.31%) ⬆️
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2748e0e...91c2dcb. Read the comment docs.

Comment thread Bio/SeqIO/SffIO.py Outdated
data = handle.read(31)
if not data:
raise ValueError("Empty file.")
elif isinstance(data, str):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pythonic way would be to call struct.unpack(fmt, data) below in a try: except: block. struct.unpack will raise a TypeError if data is not a bytes-like object. Then you don't need to use isinstance here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, that makes sense.

Comment thread Tests/test_SeqIO_index.py
handle.close()
return StringIO(data.decode())
"""Open gzip file in either binary or text mode as needed."""
if format in SeqIO._BinaryFormats:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some day we should try and get rid of SeqIO._BinaryFormats

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and this pull request is a small step in that direction.

@mdehoon mdehoon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than my comment on _sff_file_header, I am OK with this.

Comment thread Bio/SeqIO/SffIO.py Outdated
except TypeError:
# Good, we wanted a binary handle:
# e.g. TypeError: a bytes-like object is required, not 'str'
pass

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually here you could use handle.write(b"") to explicitly test if the handle was opened in binary mode.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't think of that - almost but not quite a NOP (no operation), that does seem more elegant.

Thank you to Michiel de Hoon.
@peterjc
peterjc merged commit b000475 into biopython:master Jan 7, 2020
@peterjc
peterjc deleted the test_index_py3 branch January 7, 2020 12:42
@peterjc

peterjc commented Jan 7, 2020

Copy link
Copy Markdown
Member Author

Thank you - your input definitely improved this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants