Changeset 159

Show
Ignore:
Timestamp:
12/22/06 22:42:05 (2 years ago)
Author:
grig
Message:

Added pep8.py from Johann Rocholl and corresponding IndexPEP8 as part of the code kwalitee index.

Corrected minor misspellings.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cheesecake/cheesecake_index.py

    r156 r159  
    3333from util import time_function 
    3434from codeparser import CodeParser 
    35 from cheesecake import __version__ as VERSION 
     35from __init__ import __version__ as VERSION 
     36import pep8  
    3637 
    3738__docformat__ = 'reStructuredText en' 
     
    9091        * special: .py file for special purposes 
    9192 
    92     :Note: This function only check file's name, and doesn't touch the 
     93    :Note: This function only checks file's name, and doesn't touch the 
    9394           filesystem. If you have to, check if file exists by yourself. 
    9495 
     
    507508        """ 
    508509        if not isinstance(index, Index): 
    509             raise ValueError("subindex have to be instance of Index") 
     510            raise ValueError("subindex has to be instance of Index") 
    510511 
    511512        self.subindices.append(index) 
     
    579580        >>> opt_ext = WithOptionalExt('readme', ['html', 'txt']) 
    580581 
    581     It means the same! (representation have a meaning) 
     582    It means the same! (representation has a meaning) 
    582583        >>> str(one_of) == str(opt_ext) 
    583584        True 
     
    760761    and how far from it actual package was. 
    761762 
    762     Distance is number of links user have to follow to download 
     763    Distance is number of links user has to follow to download 
    763764    a given software package. 
    764765    """ 
     
    989990 
    990991class IndexUnitTested(Index): 
    991     """Check if the package have unit tests which can be easily found by 
     992    """Check if the package has unit tests which can be easily found by 
    992993    any of known test frameworks. 
    993994    """ 
     
    10021003 
    10031004        if unittests_count > 0: 
    1004             self.add_info("Package have tests that inherit from unittest.TestCase.") 
     1005            self.add_info("Package has tests that inherit from unittest.TestCase.") 
    10051006            unit_tested = True 
    10061007 
    10071008        if get_files_of_type(files_list, 'test'): 
    1008             self.add_info("Package have filenames which probably contain tests (in format test_* or *_test)") 
     1009            self.add_info("Package has filenames which probably contain tests (in format test_* or *_test)") 
    10091010            unit_tested = True 
    10101011 
     
    11191120        return not cheesecake.lite 
    11201121 
     1122class IndexPEP8(Index): 
     1123    """Compute PEP8 index for the modules in the package. 
     1124    """ 
     1125    name = "pep8" 
     1126    max_value = 0 
     1127    error_score = -2 
     1128    warning_score = -1 
     1129 
     1130 
     1131    def compute(self, files_list, package_dir): 
     1132        files_to_score = get_files_of_type(files_list, 'module') 
     1133        if len(files_to_score) == 0: 
     1134            self.value = 0 
     1135            self.details = "no modules found" 
     1136            return self.value 
     1137 
     1138        full_paths = [os.path.join(package_dir, file) for file in files_to_score] 
     1139        arglist = ["-qq"] + full_paths 
     1140        pep8.process_options(arglist) 
     1141        for file in files_to_score: 
     1142            fullpath = os.path.join(package_dir, file) 
     1143            pep8.input_file(fullpath) 
     1144        error_stats = pep8.get_error_statistics() 
     1145        warning_stats = pep8.get_warning_statistics() 
     1146        errors = len(error_stats) 
     1147        warnings = len(warning_stats) 
     1148        total_error_score = self.error_score * errors 
     1149        total_warning_score = self.warning_score * warnings 
     1150        score = total_error_score + total_warning_score 
     1151 
     1152        self.add_info("Errors:") 
     1153        self.add_info("Count   Details") 
     1154        for stat in error_stats: 
     1155            self.add_info(stat) 
     1156        self.add_info("pep8.py found %d error types; we're scoring %d per error type" % (errors, self.error_score)) 
     1157        self.add_info("Error score: %d" % total_error_score) 
     1158        self.add_info("Warnings:") 
     1159        self.add_info("Count   Details") 
     1160        for stat in warning_stats: 
     1161            self.add_info(stat) 
     1162        self.add_info("pep8.py found %d warning types; we're scoring %d per warning type" % (warnings, self.warning_score)) 
     1163        self.add_info("Warning score: %d" % total_warning_score) 
     1164        self.add_info("Total pep8 score: %d" % score) 
     1165 
     1166        self.value = score 
     1167        self.details = "pep8.py check: %d error types, %d warning types" % (errors, warnings) 
     1168        return self.value 
     1169 
    11211170class IndexCodeKwalitee(Index): 
    11221171    name = "CODE KWALITEE" 
    11231172 
    11241173    subindices = [ 
    1125         IndexPyLint, 
    11261174        #IndexUnitTests, 
    11271175        IndexUnitTested, 
     1176        IndexPyLint, 
     1177        IndexPEP8, 
    11281178    ] 
    11291179 
  • trunk/tests/unit/test_index_class.py

    r98 r159  
    3535    Traceback (most recent call last): 
    3636      ... 
    37     ValueError: subindex have to be instance of Index 
     37    ValueError: subindex has to be instance of Index 
    3838 
    3939Now remove subindex.