Skip to content

Compatibility with Python 3.7.0 #1693

Closed

Description

@sagitter

Setup

I am reporting a problem with Biopython version, Python version, and operating
system as follows:

Python 3.7.0
GCC 8.1.1
Linux 4.18.0-0.rc1 fedora
Biopython 1.71

Probably, Biopython is not ready yet for Python 3.7.0 but unfortunately on Fedora 29 (devel branch) we are already using it.

Expected behaviour

All tests passed.

Actual behaviour

At least, test_AlignIO (link) and test_bgzf (link on ARM64) are failing.

Steps to reproduce

Compiling with Python 3.7.0.

Activity

  1. peterjc commented on Jun 21, 2018

    @peterjc
    Member

    Part of this is RuntimeError: generator raised StopIteration from test_AlignIO,
    https://www.python.org/dev/peps/pep-0479/

    The BGZF problem might be ARM specific - I've not run Biopython on an Raspberry Pi recently, but that might be the easiest way for me to reproduce this.

  2. peterjc commented on Jun 21, 2018

    @peterjc
    Member

    There is an (internal) use of StopIteration in Bio/bgzf.py which could be in a round-about-way causing the failing on ARM...

  3. peterjc commented on Jun 21, 2018

    @peterjc
    Member

    The reported AlignIO failure,

    test_AlignIO ... ERROR
    ======================================================================
    ERROR: test_AlignIO
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/builddir/build/BUILD/python-biopython-1.71/python3/build/lib.linux-x86_64-3.7/Bio/AlignIO/NexusIO.py", line 42, in NexusIterator
        n = Nexus.Nexus(handle)
      File "/builddir/build/BUILD/python-biopython-1.71/python3/build/lib.linux-x86_64-3.7/Bio/Nexus/Nexus.py", line 623, in __init__
        self.read(input)
      File "/builddir/build/BUILD/python-biopython-1.71/python3/build/lib.linux-x86_64-3.7/Bio/Nexus/Nexus.py", line 657, in read
        commandlines = _get_command_lines(file_contents)
      File "/builddir/build/BUILD/python-biopython-1.71/python3/build/lib.linux-x86_64-3.7/Bio/Nexus/Nexus.py", line 1898, in _get_command_lines
        lines = _kill_comments_and_break_lines(file_contents)
      File "/builddir/build/BUILD/python-biopython-1.71/python3/build/lib.linux-x86_64-3.7/Bio/Nexus/Nexus.py", line 454, in _kill_comments_and_break_lines
        t2 = next(contents)
    StopIteration
    The above exception was the direct cause of the following exception:
    Traceback (most recent call last):
      File "run_tests.py", line 451, in runTest
        suite = loader.loadTestsFromName(name)
      File "/usr/lib64/python3.7/unittest/loader.py", line 154, in loadTestsFromName
        module = __import__(module_name)
      File "/builddir/build/BUILD/python-biopython-1.71/python3/Tests/test_AlignIO.py", line 237, in <module>
        alignments = list(AlignIO.parse(handle, t_format))
      File "/builddir/build/BUILD/python-biopython-1.71/python3/build/lib.linux-x86_64-3.7/Bio/AlignIO/__init__.py", line 376, in parse
        for a in i:
    RuntimeError: generator raised StopIteration
    ----------------------------------------------------------------------
    Ran 1 test in 0.294 seconds
    

    is from this code snippet where I just updated the comment in d59d74a

            # TODO: As of Python 3.3, can write "yield from i" instead. See PEP380.
            # For loop imposes some overhead... wait until we drop Python 2.7 to fix it.
            for a in i:
                yield a

    In this case, the StopIteration is from within the comment parsing with Bio/Nexus/Nexus.py - which is currently puzzling me.

  4. peterjc commented on Jun 21, 2018

    @peterjc
    Member

    I can reproduce the reported (non-ARM) failures under macOS with Python 3.7.0rc1,

    ======================================================================
    ERROR: test_AlignIO
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/Users/pc40583/repositories/biopython/build/lib.macosx-10.9-x86_64-3.7/Bio/AlignIO/NexusIO.py", line 42, in NexusIterator
        n = Nexus.Nexus(handle)
      File "/Users/pc40583/repositories/biopython/build/lib.macosx-10.9-x86_64-3.7/Bio/Nexus/Nexus.py", line 623, in __init__
        self.read(input)
      File "/Users/pc40583/repositories/biopython/build/lib.macosx-10.9-x86_64-3.7/Bio/Nexus/Nexus.py", line 657, in read
        commandlines = _get_command_lines(file_contents)
      File "/Users/pc40583/repositories/biopython/build/lib.macosx-10.9-x86_64-3.7/Bio/Nexus/Nexus.py", line 1898, in _get_command_lines
        lines = _kill_comments_and_break_lines(file_contents)
      File "/Users/pc40583/repositories/biopython/build/lib.macosx-10.9-x86_64-3.7/Bio/Nexus/Nexus.py", line 454, in _kill_comments_and_break_lines
        t2 = next(contents)
    StopIteration
    
    The above exception was the direct cause of the following exception:
    
    Traceback (most recent call last):
      File "run_tests.py", line 458, in runTest
        suite = loader.loadTestsFromName(name)
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/loader.py", line 154, in loadTestsFromName
        module = __import__(module_name)
      File "/Users/pc40583/repositories/biopython/Tests/test_AlignIO.py", line 238, in <module>
        alignments = list(AlignIO.parse(handle, t_format))
      File "/Users/pc40583/repositories/biopython/build/lib.macosx-10.9-x86_64-3.7/Bio/AlignIO/__init__.py", line 380, in parse
        yield from i
    RuntimeError: generator raised StopIteration
    ======================================================================
    ERROR: test_empty_file_read (test_Nexus.TestSelf)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/Users/pc40583/repositories/biopython/build/lib.macosx-10.9-x86_64-3.7/Bio/AlignIO/NexusIO.py", line 42, in NexusIterator
        n = Nexus.Nexus(handle)
      File "/Users/pc40583/repositories/biopython/build/lib.macosx-10.9-x86_64-3.7/Bio/Nexus/Nexus.py", line 623, in __init__
        self.read(input)
      File "/Users/pc40583/repositories/biopython/build/lib.macosx-10.9-x86_64-3.7/Bio/Nexus/Nexus.py", line 657, in read
        commandlines = _get_command_lines(file_contents)
      File "/Users/pc40583/repositories/biopython/build/lib.macosx-10.9-x86_64-3.7/Bio/Nexus/Nexus.py", line 1898, in _get_command_lines
        lines = _kill_comments_and_break_lines(file_contents)
      File "/Users/pc40583/repositories/biopython/build/lib.macosx-10.9-x86_64-3.7/Bio/Nexus/Nexus.py", line 454, in _kill_comments_and_break_lines
        t2 = next(contents)
    StopIteration
    
    The above exception was the direct cause of the following exception:
    
    Traceback (most recent call last):
      File "/Users/pc40583/repositories/biopython/Tests/test_Nexus.py", line 668, in test_empty_file_read
        self.assertEqual([], list(NexusIterator(StringIO())))
    RuntimeError: generator raised StopIteration
    
    ----------------------------------------------------------------------
    Ran 273 tests in 578.328 seconds
    

    The AlignIO error is exposed via this snippet of code, where I just updated the comment in d59d74a

            # TODO: As of Python 3.3, can write "yield from i" instead. See PEP380.
            # For loop imposes some overhead... wait until we drop Python 2.7 to fix it.
            for a in i:
                yield a

    However, both stem from the same issue in the Nexus comment parsing.

  5. peterjc commented on Jun 21, 2018

    @peterjc
    Member

    I have a possible fix in #1695, which might also fix the ARM-specific BGZF issue which I have not yet been able to reproduce.

    For the Nexus/AlignIO fix, if you wanted to patch this for Fedora, all you need is:

    diff --git a/Bio/Nexus/Nexus.py b/Bio/Nexus/Nexus.py
    index 18b0a9f9c7..6faf95e569 100644
    --- a/Bio/Nexus/Nexus.py
    +++ b/Bio/Nexus/Nexus.py
    @@ -444,6 +444,8 @@ def _kill_comments_and_break_lines(text):
     
         NOTE: this function is very slow for large files, and obsolete when using C extension cnexus
         """
    +    if not text:
    +        return ""
         contents = iter(text)
         newtext = []
         newline = []

    https://github.com/biopython/biopython/commit/86eb2275448da22aa6976c6c7c46f9779af95cf1.patch

    Could you point me at the Fedora package recipe source? I am puzzled by the lines like this in your output which seems to be deliberately skipping lots of our tests (and explains why your logs didn't report the test_Nexus.py failure):

    for test in `ls test_*.py | grep -v chapter | grep -v NCBIXML | grep -v Nexus | grep -v Phylo | grep -v SeqIO | grep -v Tutorial`
    
  6. sagitter commented on Jun 21, 2018

    @sagitter
    ContributorAuthor

    It's Python-3.7.0rc1.

    I have a possible fix in #1695, which might also fix the ARM-specific BGZF issue which I have not yet been able to reproduce.

    test_AlignIO is fixed; ARM-specific BGZF issue is not resolved yet: https://kojipkgs.fedoraproject.org//work/tasks/9804/27769804/build.log

    Could you point me at the Fedora package recipe source? I am puzzled by the lines like this in your output which seems to be deliberately skipping lots of our tests (and explains why your logs didn't report the test_Nexus.py failure):

    for test in ls test_*.py | grep -v chapter | grep -v NCBIXML | grep -v Nexus | grep -v Phylo | grep -v SeqIO | grep -v Tutorial

    Spec file and patches for creating Biopython RPMs: https://src.fedoraproject.org/rpms/python-biopython/tree/master

    All RPM builds: https://koji.fedoraproject.org/koji/packageinfo?packageID=3567

    I skipped those tests because of UnicodeDecodeError. Is it resolved in Biopython-1.71?

  7. vielmetti commented on Jun 21, 2018

    @vielmetti

    Just to be super clear, are you targeting 32-bit armhf, or 64-bit arm64, or both?

  8. peterjc commented on Jun 21, 2018

    @peterjc
    Member

    Excellent, thank you for confirming #1695 fixes AlignIO test failure for you too. That is further encouragement for us to include it in Biopython 1.72.

    Thank you also for the Fedora packing details. Regarding to the tests you are skipping, the specific UnicodeDecodeError you linked to, issue #855, should have been fixed by aa94ebc which was in the Biopython 1.71 release. There are other issues with UnicodeDecodeError which are still open though...

    Further details of the ARM setup would be appreciated. Let's focus on that with this issue?

  9. sagitter commented on Jun 22, 2018

    @sagitter
    ContributorAuthor

    @vielmetti
    Both, only ARM64 is broken: https://koji.fedoraproject.org/koji/taskinfo?taskID=27769777

    @peterjc

    Thank you also for the Fedora packing details. Regarding to the tests you are skipping, the specific UnicodeDecodeError you linked to, issue #855, should have been fixed by aa94ebc which was in the Biopython 1.71 release. There are other issues with UnicodeDecodeError which are still open though...

    Okay, let me test again for UnicodeDecodeError.

  10. sagitter commented on Jun 22, 2018

    @sagitter
    ContributorAuthor

    Here all RPM builds i'm doing for testing; please, follow f29-python tag.

  11. peterjc commented on Jun 22, 2018

    @peterjc
    Member

    I've logged #1696 for the ARM64 specific failure in test_bgzf.py

    We should have open issues for any remaining UnicodeDecodeError cases, additional reports welcome - as is any insight into fixing them.

    The other issue raised here was with the Nexus / AlignIO test failure, was fixed via #1695. I am therefore closing this. Thank you, it delayed the Biopython 1.72 release but now that ought to work on Python 3.7.0 which is good news 👍

  12. peterjc commented on Oct 25, 2018

    @peterjc
    Member

    As noted on #1832 (comment) a recently merged pull request #1635 (comment) has sadly reintroduced this problem under Python 3.7

    It should be a simple enough fix...

  13. chris-rands commented on Oct 25, 2018

    @chris-rands
    Contributor

    I am not using Python 3.7 yet myself I'm not familiar with the Biopython PDB modules, but it might be as simple as this here?

    try:
        token = next(tokens)
    except StopIteration:
        return
    
  14. peterjc commented on Oct 26, 2018

    @peterjc
    Member

    @chris-rands quite possibly - if you try it on a pull request, we'll find out 👍

  15. chris-rands commented on Dec 17, 2018

    @chris-rands
    Contributor

    I suggest we can close this as fixed on #1835

  16. peterjc commented on Dec 17, 2018

    @peterjc
    Member

    Thanks, closing.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions