~ubuntu-branches/ubuntu/natty/python-distutils-extra/natty-updates

« back to all changes in this revision

Viewing changes to .pc/debian-changes-2.22-3/DistUtilsExtra/command/check.py

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt, Didier Roche
  • Date: 2010-11-18 11:39:08 UTC
  • mfrom: (18.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20101118113908-djxv5m9au6fv5tk7
Tags: 2.23-1
[ Didier Roche ]
* debian/local/python-mkdebian: (LP: #625581)
  - add --force-rules to force the rules file to be recreated
  - add --prefix to force a prefix other than /usr for installing your python
    modules
* debian/local/python-mkdebian.1:
  - add man for --force-copyright
  - add man for --force-rules and --prefix

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# DistUtilsExtra.command.check - check command for DistUtilsExtra
2
 
#
3
 
# Author: Rodney Dawes <rodney.dawes@canonical.com>
4
 
#
5
 
# Copyright 2009 Canonical Ltd.
6
 
#
7
 
# This program is free software: you can redistribute it and/or modify it 
8
 
# under the terms of the GNU General Public License version 3, as published 
9
 
# by the Free Software Foundation.
10
 
#
11
 
# This program is distributed in the hope that it will be useful, but 
12
 
# WITHOUT ANY WARRANTY; without even the implied warranties of 
13
 
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
14
 
# PURPOSE.  See the GNU General Public License for more details.
15
 
#
16
 
# You should have received a copy of the GNU General Public License along 
17
 
# with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 
 
19
 
"""DistUtilsExtra.command.check
20
 
 
21
 
Implements the DistUtilsExtra 'check' command.
22
 
"""
23
 
 
24
 
import os
25
 
import subprocess
26
 
 
27
 
from distutils.core import Command
28
 
 
29
 
 
30
 
class check (Command):
31
 
    """Command to run lint and tests on a module."""
32
 
 
33
 
    description = "integrate pylint checks"
34
 
 
35
 
    user_options = [("config-file=", None,
36
 
                     "pylint config file to use"),
37
 
                    ("exclude-files=", None,
38
 
                     "list of files to exclude from lint checks"),
39
 
                    ("lint-files=", None,
40
 
                     "list of modules or packages to run lint checks on")
41
 
                   ]
42
 
 
43
 
    def initialize_options (self):
44
 
        self.config_file = None
45
 
        self.exclude_files = None
46
 
        self.lint_files = None
47
 
 
48
 
    def finalize_options (self):
49
 
        if self.config_file is None:
50
 
            self.config_file = ""
51
 
        if self.exclude_files is None:
52
 
            self.exclude_files = "[]"
53
 
        if self.lint_files is None:
54
 
            self.lint_files = "[" + self.__find_files() + "]"
55
 
 
56
 
    def run (self):
57
 
        pylint_args = ["--output-format=parseable",
58
 
                       "--include-ids=yes"]
59
 
 
60
 
        if self.config_file:
61
 
            pylint_args.append("--rcfile=" + self.config_file)
62
 
 
63
 
        for file in eval(self.lint_files):
64
 
            pylint_args.append(file)
65
 
 
66
 
        p = subprocess.Popen(["pylint"] + pylint_args,
67
 
                             bufsize=4096, stdout=subprocess.PIPE)
68
 
        notices = p.stdout
69
 
 
70
 
        output = "".join(notices.readlines())
71
 
        if output != "":
72
 
            print "== Pylint notices =="
73
 
            print self.__group_lines_by_file(output)
74
 
 
75
 
    def __group_lines_by_file(self, input):
76
 
        """Format file:line:message output as lines grouped by file."""
77
 
        outputs = []
78
 
        filename = ""
79
 
        excludes = eval(self.exclude_files)
80
 
        for line in input.splitlines():
81
 
            current = line.split(":", 3)
82
 
            if line.startswith("    "):
83
 
                outputs.append("    " + current[0] + "")
84
 
            elif line.startswith("build/") or current[0] in excludes or \
85
 
                    len(current) < 3:
86
 
                pass
87
 
            elif filename == current[0]:
88
 
                outputs.append("    " + current[1] + ": " + current[2])
89
 
            elif filename != current[0]:
90
 
                filename = current[0]
91
 
                outputs.append("")
92
 
                outputs.append(filename + ":")
93
 
                outputs.append("    " + current[1] + ": " + current[2])
94
 
 
95
 
        return "\n".join(outputs)
96
 
 
97
 
    def __find_files(self):
98
 
        """Find all Python files under the current tree."""
99
 
        pyfiles = []
100
 
        for root, dirs, files in os.walk(os.getcwd(), topdown=False):
101
 
            for file in files:
102
 
                if file.endswith(".py"):
103
 
                    pyfiles.append("'" + os.path.join(root, file) + "'")
104
 
        pyfiles.sort()
105
 
        return ",".join(pyfiles)