Navigation Menu

Skip to content

Commit

Permalink
Add: from __future__ import print_statement
Browse files Browse the repository at this point in the history
This is currently redundant as we are carefully only
using this simple print style which is both a print
statement (with redundant brackets) under Python 2
and a print function under Python 3:

print(variable)

However, adding the __future__ import to any file using
a print should catch any accidental usage of the print
statement in the near future (even if not testing under
Python 3 where it would be spotted since we've turned
off the print fixer during the 2to3 conversion).

This was automated as follows:

<python>
MAGIC = "from __future__ import print_function"

import os
import sys

def should_mark(filename):
    handle = open(filename, "rU")
    lines = [line.strip() for line in handle if "print" in line]
    handle.close()
    if MAGIC in lines:
        #print("%s is marked" % filename)
        return False
    if "print" in lines:
        print("TODO - %s has a naked print" % filename)
        sys.exit(1)
    for line in lines:
        if "print" not in line:
            continue
        #print(line)
        line = line.strip(" #")
        if line.startswith(">>>") or line.startswith("..."):
            #doctest
            line = line[3:].strip()
        if line.startswith("print ") or line.startswith("print("):
            return True
    print("%s has no print statements" % filename)
    return False

def mark_file(filename, marker=MAGIC):
    with open(filename, "rU") as h:
        lines = list(h.readlines())
    with open(filename, "w") as h:
        while (lines[0].startswith("#") or not lines[0].strip()):
            h.write(lines.pop(0))
        if lines[0].startswith('"""') or lines[0].startswith('r"""'):
            # Module docstring
            if lines[0].strip() == '"""':
                print("Non-PEP8 module docstring in %s" % filename)
            if lines[0].rstrip().endswith('"""') and lines[0].strip() != '"""':
                # One liner
                print("One line module docstring in %s" % filename)
                h.write(lines.pop(0))
            else:
                h.write(lines.pop(0))
                while not lines[0].strip().endswith('"""'):
                    h.write(lines.pop(0))
                h.write(lines.pop(0))
        while (lines[0].startswith("#") or not lines[0].strip()):
            h.write(lines.pop(0))
        h.write(marker + "\n\n")
        h.write("".join(lines))

for dirpath, dirnames, filenames in os.walk("."):
    if dirpath.startswith("./build/"):
        continue
    for f in filenames:
        if not f.endswith(".py"):
            continue
        f = os.path.join(dirpath, f)
        if should_mark(f):
            print("Marking %s" % f)
            mark_file(f)
</python>
  • Loading branch information
peterjc committed Sep 9, 2013
1 parent b758767 commit de12c5e
Show file tree
Hide file tree
Showing 211 changed files with 422 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Bio/Align/AlignInfo.py
Expand Up @@ -10,6 +10,8 @@
"""

# standard library
from __future__ import print_function

import math
import sys

Expand Down
2 changes: 2 additions & 0 deletions Bio/Align/Applications/_ClustalOmega.py
Expand Up @@ -11,6 +11,8 @@
"""Command line wrapper for the multiple alignment program Clustal Omega.
"""

from __future__ import print_function

__docformat__ = "epytext en" # Don't just use plain text in epydoc API pages!

from Bio.Application import _Option, _Switch, AbstractCommandline
Expand Down
2 changes: 2 additions & 0 deletions Bio/Align/Applications/_Clustalw.py
Expand Up @@ -5,6 +5,8 @@
"""Command line wrapper for the multiple alignment program Clustal W.
"""

from __future__ import print_function

__docformat__ = "epytext en" # Don't just use plain text in epydoc API pages!

import os
Expand Down
2 changes: 2 additions & 0 deletions Bio/Align/Applications/_Dialign.py
Expand Up @@ -5,6 +5,8 @@
"""Command line wrapper for the multiple alignment program DIALIGN2-2.
"""

from __future__ import print_function

__docformat__ = "epytext en" # Don't just use plain text in epydoc API pages!

from Bio.Application import _Option, _Argument, _Switch, AbstractCommandline
Expand Down
2 changes: 2 additions & 0 deletions Bio/Align/Applications/_Mafft.py
Expand Up @@ -5,6 +5,8 @@
"""Command line wrapper for the multiple alignment programme MAFFT.
"""

from __future__ import print_function

__docformat__ = "epytext en" # Don't just use plain text in epydoc API pages!

import os
Expand Down
2 changes: 2 additions & 0 deletions Bio/Align/Applications/_Muscle.py
Expand Up @@ -5,6 +5,8 @@
"""Command line wrapper for the multiple alignment program MUSCLE.
"""

from __future__ import print_function

__docformat__ = "epytext en" # Don't just use plain text in epydoc API pages!

from Bio.Application import _Option, _Switch, AbstractCommandline
Expand Down
2 changes: 2 additions & 0 deletions Bio/Align/Applications/_Prank.py
Expand Up @@ -5,6 +5,8 @@
"""Command line wrapper for the multiple alignment program PRANK.
"""

from __future__ import print_function

__docformat__ = "epytext en" # Don't just use plain text in epydoc API pages!

from Bio.Application import _Option, _Switch, AbstractCommandline
Expand Down
2 changes: 2 additions & 0 deletions Bio/Align/Applications/_Probcons.py
Expand Up @@ -5,6 +5,8 @@
"""Command line wrapper for the multiple alignment program PROBCONS.
"""

from __future__ import print_function

__docformat__ = "epytext en" # Don't just use plain text in epydoc API pages!

from Bio.Application import _Option, _Switch, _Argument, AbstractCommandline
Expand Down
2 changes: 2 additions & 0 deletions Bio/Align/Applications/_TCoffee.py
Expand Up @@ -5,6 +5,8 @@
"""Command line wrapper for the multiple alignment program TCOFFEE.
"""

from __future__ import print_function

__docformat__ = "epytext en" # Don't just use plain text in epydoc API pages!

from Bio.Application import _Option, _Switch, AbstractCommandline
Expand Down
2 changes: 2 additions & 0 deletions Bio/Align/Generic.py
Expand Up @@ -13,6 +13,8 @@
Classes:
- Alignment
"""
from __future__ import print_function

__docformat__ = "epytext en" # Don't just use plain text in epydoc API pages!

# biopython
Expand Down
2 changes: 2 additions & 0 deletions Bio/Align/__init__.py
Expand Up @@ -9,6 +9,8 @@
class, used in the Bio.AlignIO module.
"""
from __future__ import print_function

__docformat__ = "epytext en" # Don't just use plain text in epydoc API pages!

from Bio.Seq import Seq
Expand Down
2 changes: 2 additions & 0 deletions Bio/AlignIO/ClustalIO.py
Expand Up @@ -9,6 +9,8 @@
Bio.SeqIO functions if you want to work directly with the gapped sequences).
"""

from __future__ import print_function

from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord
from Bio.Align import MultipleSeqAlignment
Expand Down
2 changes: 2 additions & 0 deletions Bio/AlignIO/EmbossIO.py
Expand Up @@ -12,6 +12,8 @@
example from the alignret, water and needle tools.
"""

from __future__ import print_function

from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord
from Bio.Align import MultipleSeqAlignment
Expand Down
2 changes: 2 additions & 0 deletions Bio/AlignIO/FastaIO.py
Expand Up @@ -19,6 +19,8 @@
which can also be used to store a multiple sequence alignments.
"""

from __future__ import print_function

from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord
from Bio.Align import MultipleSeqAlignment
Expand Down
2 changes: 2 additions & 0 deletions Bio/AlignIO/Interfaces.py
Expand Up @@ -8,6 +8,8 @@
use this module. It provides base classes to try and simplify things.
"""

from __future__ import print_function

from Bio.Alphabet import single_letter_alphabet

# TODO - Review self.next() method for Python 3 support...
Expand Down
2 changes: 2 additions & 0 deletions Bio/AlignIO/NexusIO.py
Expand Up @@ -13,6 +13,8 @@
sequences as SeqRecord objects.
"""

from __future__ import print_function

from Bio.SeqRecord import SeqRecord
from Bio.Nexus import Nexus
from Bio.Align import MultipleSeqAlignment
Expand Down
2 changes: 2 additions & 0 deletions Bio/AlignIO/PhylipIO.py
Expand Up @@ -31,6 +31,8 @@
Biopython 1.58 or later treats dots/periods in the sequence as invalid, both
for reading and writing. Older versions did nothing special with a dot/period.
"""
from __future__ import print_function

import string

from Bio.Seq import Seq
Expand Down
2 changes: 2 additions & 0 deletions Bio/AlignIO/StockholmIO.py
Expand Up @@ -128,6 +128,8 @@
>>> print(sub_record.letter_annotations['secondary_structure'])
-------<<<
"""
from __future__ import print_function

__docformat__ = "epytext en" # not just plaintext
from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord
Expand Down
2 changes: 2 additions & 0 deletions Bio/AlignIO/__init__.py
Expand Up @@ -121,6 +121,8 @@
"""


from __future__ import print_function

__docformat__ = "epytext en" # not just plaintext

#TODO
Expand Down
2 changes: 2 additions & 0 deletions Bio/Application/__init__.py
Expand Up @@ -19,6 +19,8 @@
The finished command line strings are then normally invoked via the built-in
Python module subprocess.
"""
from __future__ import print_function

import os
import sys
import subprocess
Expand Down
2 changes: 2 additions & 0 deletions Bio/Blast/Applications.py
Expand Up @@ -32,6 +32,8 @@
BMC Bioinformatics 2009, 10:421
doi:10.1186/1471-2105-10-421
"""
from __future__ import print_function

from Bio import BiopythonDeprecationWarning

from Bio.Application import _Option, AbstractCommandline, _Switch
Expand Down
2 changes: 2 additions & 0 deletions Bio/Blast/NCBIStandalone.py
Expand Up @@ -49,6 +49,8 @@
are likely to be deprecated and then removed in future releases.
"""

from __future__ import print_function

from Bio import BiopythonDeprecationWarning
import warnings
warnings.warn("This module has been deprecated. Consider Bio.SearchIO for "
Expand Down
2 changes: 2 additions & 0 deletions Bio/Blast/NCBIWWW.py
Expand Up @@ -16,6 +16,8 @@
qblast Do a BLAST search using the QBLAST API.
"""

from __future__ import print_function

from Bio._py3k import StringIO
from Bio._py3k import _as_string, _as_bytes

Expand Down
2 changes: 2 additions & 0 deletions Bio/Blast/NCBIXML.py
Expand Up @@ -21,6 +21,8 @@
Blast records. It uses the BlastParser internally.
read Returns a single Blast record. Uses the BlastParser internally.
"""
from __future__ import print_function

from Bio.Blast import Record
import xml.sax
from xml.sax.handler import ContentHandler
Expand Down
2 changes: 2 additions & 0 deletions Bio/Data/CodonTable.py
Expand Up @@ -9,6 +9,8 @@
Last updated for Version 3.9
"""

from __future__ import print_function

from Bio import Alphabet
from Bio.Alphabet import IUPAC
from Bio.Data import IUPACData
Expand Down
2 changes: 2 additions & 0 deletions Bio/DocSQL.py
Expand Up @@ -23,6 +23,8 @@
CreatePeople(message=Success)
"""

from __future__ import print_function

import sys

from Bio import MissingPythonDependencyError
Expand Down
2 changes: 2 additions & 0 deletions Bio/Emboss/Applications.py
Expand Up @@ -12,6 +12,8 @@
programs.
"""

from __future__ import print_function

from Bio.Application import _Option, _Switch, AbstractCommandline


Expand Down
2 changes: 2 additions & 0 deletions Bio/Entrez/__init__.py
Expand Up @@ -68,6 +68,8 @@
_open Internally used function.
"""
from __future__ import print_function

import urllib
import urllib2
import time
Expand Down
2 changes: 2 additions & 0 deletions Bio/FSSP/__init__.py
Expand Up @@ -10,6 +10,8 @@
tuple of two instances.
mult_align: returns a Biopython alignment object
"""
from __future__ import print_function

import re
import fssp_rec
from Bio.Align import Generic
Expand Down
2 changes: 2 additions & 0 deletions Bio/File.py
Expand Up @@ -15,6 +15,8 @@
files are also defined under Bio.File but these are not intended for direct
use.
"""
from __future__ import print_function

import codecs
import os
import contextlib
Expand Down
2 changes: 2 additions & 0 deletions Bio/GA/Evolver.py
Expand Up @@ -4,6 +4,8 @@
for taking care of the transition from one generation to the next.
"""
# standard modules
from __future__ import print_function

import sys


Expand Down
2 changes: 2 additions & 0 deletions Bio/GenBank/Scanner.py
Expand Up @@ -26,6 +26,8 @@
# for more details of this format, and an example.
# Added by Ying Huang & Iddo Friedberg

from __future__ import print_function

import warnings
import re
from Bio.Seq import Seq
Expand Down
2 changes: 2 additions & 0 deletions Bio/GenBank/__init__.py
Expand Up @@ -38,6 +38,8 @@
location parser.
"""
from __future__ import print_function

import re

# other Biopython stuff
Expand Down
2 changes: 2 additions & 0 deletions Bio/Geo/Record.py
Expand Up @@ -13,6 +13,8 @@
"""


from __future__ import print_function

class Record(object):
"""Hold GEO information in a format similar to the original record.
Expand Down
2 changes: 2 additions & 0 deletions Bio/Graphics/GenomeDiagram/_AbstractDrawer.py
Expand Up @@ -40,6 +40,8 @@
"""

# ReportLab imports
from __future__ import print_function

from reportlab.lib import pagesizes
from reportlab.lib import colors
from reportlab.graphics.shapes import *
Expand Down
2 changes: 2 additions & 0 deletions Bio/Graphics/GenomeDiagram/_CircularDrawer.py
Expand Up @@ -12,6 +12,8 @@
"""CircularDrawer module for GenomeDiagram."""

# ReportLab imports
from __future__ import print_function

from reportlab.graphics.shapes import *
from reportlab.lib import colors
from reportlab.pdfbase import _fontdata
Expand Down
2 changes: 2 additions & 0 deletions Bio/Graphics/GenomeDiagram/_Colors.py
Expand Up @@ -21,6 +21,8 @@
"""

# ReportLab imports
from __future__ import print_function

from reportlab.lib import colors


Expand Down
2 changes: 2 additions & 0 deletions Bio/Graphics/GenomeDiagram/_FeatureSet.py
Expand Up @@ -34,6 +34,8 @@
# IMPORTS

# ReportLab
from __future__ import print_function

from reportlab.pdfbase import _fontdata
from reportlab.lib import colors

Expand Down
2 changes: 2 additions & 0 deletions Bio/Graphics/GenomeDiagram/_Graph.py
Expand Up @@ -28,6 +28,8 @@
"""

# ReportLab imports
from __future__ import print_function

from reportlab.lib import colors

from math import sqrt
Expand Down
2 changes: 2 additions & 0 deletions Bio/Graphics/GenomeDiagram/_GraphSet.py
Expand Up @@ -30,6 +30,8 @@
"""

# ReportLab imports
from __future__ import print_function

from reportlab.lib import colors

from _Graph import GraphData
Expand Down
2 changes: 2 additions & 0 deletions Bio/Graphics/GenomeDiagram/_LinearDrawer.py
Expand Up @@ -27,6 +27,8 @@
"""

# ReportLab imports
from __future__ import print_function

from reportlab.graphics.shapes import *
from reportlab.lib import colors

Expand Down
2 changes: 2 additions & 0 deletions Bio/Graphics/GenomeDiagram/_Track.py
Expand Up @@ -28,6 +28,8 @@
"""

# ReportLab imports
from __future__ import print_function

from reportlab.lib import colors

# GenomeDiagram imports
Expand Down
2 changes: 2 additions & 0 deletions Bio/HMM/Utilities.py
Expand Up @@ -5,6 +5,8 @@
"""


from __future__ import print_function

def pretty_print_prediction(emissions, real_state, predicted_state,
emission_title = "Emissions",
real_title = "Real State",
Expand Down
2 changes: 2 additions & 0 deletions Bio/HotRand.py
Expand Up @@ -8,6 +8,8 @@
support biosimulations that rely on random numbers.
"""

from __future__ import print_function

import urllib
from Bio import BiopythonDeprecationWarning
import warnings
Expand Down

1 comment on commit de12c5e

@peterjc
Copy link
Member Author

@peterjc peterjc commented on de12c5e Sep 9, 2013

Choose a reason for hiding this comment

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

There is an unfortunate typo in the commit comment's first line,

from __future__ import print_statement

should have been:

from __future__ import print_function

Please sign in to comment.