Skip to content
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

Modify ImportError traceback for _aligners #1736

Merged

Conversation

chris-rands
Copy link
Contributor

This pull request relates to an issue raised on the mailing list here. I also saw the same question asked on Stack overflow here, and I then later independently encountered the issue myself because I had used some soft links rather than doing a proper install. The error can occur on a few imports, for example:

>>> from Bio import SeqIO
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/path/biopython/Bio/SeqIO/__init__.py", line 375, in <module>
    from Bio.Align import MultipleSeqAlignment
  File "path/biopython/Bio/Align/__init__.py", line 22, in <module>
    from Bio.Align import _aligners
ImportError: cannot import name '_aligners'

I found the error slightly cryptic until I read through the mailing list thread, and perhaps I am not alone. Michiel noted in the mailing list thread here that numpy have a more informative traceback, I suggest modifying the traceback in this case in a similar way:

>>> from Bio import SeqIO
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/path/biopython/Bio/SeqIO/__init__.py", line 375, in <module>
    from Bio.Align import MultipleSeqAlignment
  File "/path/biopython/Bio/Align/__init__.py", line 29, in <module>
    raise new_exc
ImportError: cannot import name '_aligners': you should not import directly from the
                         biopython source directory; please exit the source
                         tree and re-launch your code from there

Thoughts?

  • 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 and understand that AppVeyor and
    TravisCI will be used to confirm the Biopython unit tests and flake8 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.)

try:
from Bio.Align import _aligners
except ImportError as e:
new_exc = ImportError("""{}: you should not import directly from the
Copy link
Member

Choose a reason for hiding this comment

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

Don't use a triple quote string, which inserts the new lines breaks as is. Use single quotes (which will auto-concatenate)

@codecov
Copy link

codecov bot commented Jul 16, 2018

Codecov Report

Merging #1736 into master will decrease coverage by 0.41%.
The diff coverage is 33.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1736      +/-   ##
==========================================
- Coverage   85.57%   85.15%   -0.42%     
==========================================
  Files         331      331              
  Lines       50086    50091       +5     
==========================================
- Hits        42859    42657     -202     
- Misses       7227     7434     +207
Impacted Files Coverage Δ
Bio/Align/__init__.py 84.57% <33.33%> (-0.88%) ⬇️
Bio/Phylo/CDAOIO.py 5.42% <0%> (-80.1%) ⬇️
Bio/Phylo/CDAO.py 42.85% <0%> (-57.15%) ⬇️
Bio/GA/Evolver.py 54.54% <0%> (-18.19%) ⬇️
Bio/Phylo/_cdao_owl.py 88.88% <0%> (-11.12%) ⬇️
BioSQL/DBUtils.py 68.49% <0%> (-6.85%) ⬇️
Bio/Phylo/_io.py 91.66% <0%> (-2.78%) ⬇️
Bio/_py3k/__init__.py 75% <0%> (-1.2%) ⬇️
Bio/Restriction/Restriction.py 82.93% <0%> (-0.46%) ⬇️
Bio/PopGen/GenePop/Controller.py 64.47% <0%> (-0.2%) ⬇️

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 d7789a5...ffc42e8. Read the comment docs.

Copy link
Member

@peterjc peterjc left a comment

Choose a reason for hiding this comment

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

Looks good to me in principle - over to @mdehoon

@peterjc
Copy link
Member

peterjc commented Jul 17, 2018

TravisCI failure linked to ReportLab, see #1737 1737

@peterjc
Copy link
Member

peterjc commented Jul 17, 2018

TravisCI failure caused by #1737 (latest ReportLab release).

@mdehoon
Copy link
Contributor

mdehoon commented Jul 17, 2018

Looks good to me.

As this error typically appears when a user runs "python setup.py install" and directly afterwards tries to import Bio, some day we should reorganize the directory structure such that Bio/ etc. is not a direct subdirectory of biopython, then this error is unlikely to happen at all.

@peterjc peterjc merged commit 8efbf6d into biopython:master Jul 17, 2018
brandoninvergo pushed a commit to brandoninvergo/biopython that referenced this pull request Jul 17, 2018
@chris-rands chris-rands deleted the improve_tracback_for_aligners_ImportError branch July 17, 2018 08:10
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.

None yet

3 participants