~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to release/test/pep8.py

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# ##### BEGIN GPL LICENSE BLOCK #####
2
 
#
3
 
#  This program is free software; you can redistribute it and/or
4
 
#  modify it under the terms of the GNU General Public License
5
 
#  as published by the Free Software Foundation; either version 2
6
 
#  of the License, or (at your option) any later version.
7
 
#
8
 
#  This program is distributed in the hope that it will be useful,
9
 
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
#  GNU General Public License for more details.
12
 
#
13
 
#  You should have received a copy of the GNU General Public License
14
 
#  along with this program; if not, write to the Free Software Foundation,
15
 
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16
 
#
17
 
# ##### END GPL LICENSE BLOCK #####
18
 
 
19
 
# <pep8 compliant>
20
 
 
21
 
import os
22
 
 
23
 
# depends on pep8, pyflakes, pylint
24
 
# for ubuntu
25
 
#
26
 
#   sudo apt-get install pylint pyflakes
27
 
#
28
 
#   sudo apt-get install python-setuptools python-pip
29
 
#   sudo pip install pep8
30
 
#
31
 
# in debian install pylint pyflakes pep8 with apt-get/aptitude/etc
32
 
#
33
 
# on *nix run
34
 
#   python release/test/pep8.py > pep8_error.txt 2>&1
35
 
 
36
 
# how many lines to read into the file, pep8 comment
37
 
# should be directly after the licence header, ~20 in most cases
38
 
PEP8_SEEK_COMMENT = 40
39
 
SKIP_PREFIX = "./tools", "./config", "./scons", "./extern"
40
 
 
41
 
 
42
 
def file_list_py(path):
43
 
    for dirpath, dirnames, filenames in os.walk(path):
44
 
        for filename in filenames:
45
 
            if filename.endswith(".py"):
46
 
                yield os.path.join(dirpath, filename)
47
 
 
48
 
 
49
 
def is_pep8(path):
50
 
    f = open(path, 'r')
51
 
    for i in range(PEP8_SEEK_COMMENT):
52
 
        line = f.readline()
53
 
        if line.startswith("# <pep8"):
54
 
            if line.startswith("# <pep8 compliant>"):
55
 
                return 1
56
 
            elif line.startswith("# <pep8-80 compliant>"):
57
 
                return 2
58
 
    f.close()
59
 
    return 0
60
 
 
61
 
 
62
 
def main():
63
 
    files = []
64
 
    files_skip = []
65
 
    for f in file_list_py("."):
66
 
        pep8_type = is_pep8(f)
67
 
 
68
 
        if pep8_type:
69
 
            # so we can batch them for each tool.
70
 
            files.append((os.path.abspath(f), pep8_type))
71
 
        else:
72
 
            if not [None for prefix in SKIP_PREFIX if f.startswith(prefix)]:
73
 
                files_skip.append(f)
74
 
 
75
 
    print("\nSkipping...")
76
 
    for f in files_skip:
77
 
        print("    %s" % f)
78
 
 
79
 
    # pyflakes
80
 
    print("\n\n\n# running pep8...")
81
 
    for f, pep8_type in files:
82
 
        if pep8_type == 1:
83
 
            # E501:80 line length
84
 
            os.system("pep8 --repeat --ignore=E501 '%s'" % (f))
85
 
        else:
86
 
            os.system("pep8 --repeat '%s'" % (f))
87
 
 
88
 
    print("\n\n\n# running pyflakes...")
89
 
    for f, pep8_type in files:
90
 
        os.system("pyflakes '%s'" % f)
91
 
 
92
 
    print("\n\n\n# running pylint...")
93
 
    for f, pep8_type in files:
94
 
        # let pep8 complain about line length
95
 
        os.system("pylint --reports=n --max-line-length=1000 '%s'" % f)
96
 
 
97
 
if __name__ == "__main__":
98
 
    main()