示例#1
0
def check_modified_file(filename, errors):
    """Check each modified file to make sure it adheres to the standards"""
    # skip code that isn't ours
    if filename.find("dependency") != -1 or "/eigen3/" in filename:
        return
    # don't check header guard in template headers
    if filename.find("templates") != -1:
        return
    info = python_tools.get_project_info(filename)
    if filename.endswith('.h') or filename.endswith('.cpp') \
       or filename.endswith('.c'):
        check_c_file(filename, errors)
        # don't check header guard in template headers
        if cpp_format and filename.endswith('.h') and filename.find("templates") == -1:
            cpp_format.check_header_file(
                get_file(filename),
                info["name"],
                errors)
        elif cpp_format and filename.endswith('.cpp'):
            cpp_format.check_cpp_file(
                get_file(filename),
                info["name"],
                errors)
    elif filename.endswith('.py'):
        check_python_file(filename, errors)
示例#2
0
def check_modified_file(filename, errors):
    """Check each modified file to make sure it adheres to the standards"""
    # skip code that isn't ours
    if filename.find("dependency") != -1 or "/eigen3/" in filename:
        return
    # don't check header guard in template headers
    if filename.find("templates") != -1:
        return
    info = python_tools.get_project_info(filename)
    if filename.endswith('.h') or filename.endswith('.cpp') \
       or filename.endswith('.c'):
        check_c_file(filename, errors)
        # don't check header guard in template headers
        if cpp_format and filename.endswith('.h') and filename.find("templates") == -1:
            cpp_format.check_header_file(
                get_file(filename),
                info["name"],
                errors)
        elif cpp_format and filename.endswith('.cpp'):
            cpp_format.check_cpp_file(
                get_file(filename),
                info["name"],
                errors)
    elif filename.endswith('.py'):
        check_python_file(filename, errors)
示例#3
0
def check_c_file(filename, errors):
    """Check each modified C file to make sure it adheres to the standards"""
    info = python_tools.get_project_info(filename)
    docname = info["name"].replace(".", "/")
    filepath = os.path.split(filename)[0]
    if filepath.find(docname) != -1:
        docname = filepath[filepath.find(docname):]
    elif filepath.find("include") != -1:
        docname = docname + "/" + \
            filepath[filepath.find("include") + len("include"):]
    cppprefix = info["name"].split('.')[0] + '_'
    altcppprefix = info["name"].replace(".", "").upper()
    fh = file(filename, "r").read().split("\n")
    srch = re.compile('\s+$')
    url = re.compile('https?://')
    configh = False
    blank = False
    file_line = False
    exported = filename.find("internal") == - \
        1 and filename.endswith(
            ".h") and filename.find(
            "include") != -1
    name = os.path.split(filename)[1]
    file_line_string = "\\file %s" % (
        "/".join([docname, name])).replace("//", "/")
    for (num, line) in enumerate(fh):
        line = line.rstrip('\r\n')
        if line.find(file_line_string) != -1:
            file_line = True
        # No way to split URLs, so let them exceed 80 characters:
        if line.startswith(">>>>>>> "):
            errors.append(
                "%s:%d: error: Incomplete merge found." %
                (filename, num + 1))
        _check_do_not_commit(line, filename, num, errors)
        if not filename.endswith(".cpp") and line.startswith("#define ") \
           and not line.startswith("#define %s" % cppprefix) \
           and not line.startswith("#define %s" % altcppprefix) \
           and not line.startswith("#define EIGEN_YES_I_KNOW_SPARSE_"
                                   "MODULE_IS_NOT_STABLE_YET"):
            found = False
            fline = line.replace("#define", "#undef")
            for (onum, oline) in enumerate(fh):
                if onum > num and oline.startswith(fline):
                    found = True
            if not found:
                errors.append('%s:%d: error: Preprocessor symbols must start with %s or %s'
                              % (filename, num + 1, cppprefix, altcppprefix))
        blank = (len(line) == 0)
        if line.startswith('#include "'):
            configh = True
        if blank and num == 0:
            errors.append('%s:1: File has leading blank line(s)' % filename)
    if exported and filename.endswith(".h") and not file_line:
        # lazy hack with the replace
        errors.append(
            '%s:2: Exported header must have a line  %s' % (filename, file_line_string))
示例#4
0
def check_c_file(filename, errors):
    """Check each modified C file to make sure it adheres to the standards"""
    info = python_tools.get_project_info(filename)
    docname = info["name"].replace(".", "/")
    filepath = os.path.split(filename)[0]
    if filepath.find(docname) != -1:
        docname = filepath[filepath.find(docname):]
    elif filepath.find("include") != -1:
        docname = docname + "/" + \
            filepath[filepath.find("include") + len("include"):]
    cppprefix = info["name"].split('.')[0] + '_'
    altcppprefix = info["name"].replace(".", "").upper()
    fh = file(filename, "r").read().split("\n")
    srch = re.compile('\s+$')
    url = re.compile('https?://')
    configh = False
    blank = False
    file_line = False
    exported = filename.find("internal") == - \
        1 and filename.endswith(
            ".h") and filename.find(
            "include") != -1
    name = os.path.split(filename)[1]
    file_line_string = "\\file %s" % ("/".join([docname, name])).replace(
        "//", "/")
    for (num, line) in enumerate(fh):
        line = line.rstrip('\r\n')
        if line.find(file_line_string) != -1:
            file_line = True
        # No way to split URLs, so let them exceed 80 characters:
        if line.startswith(">>>>>>> "):
            errors.append("%s:%d: error: Incomplete merge found." %
                          (filename, num + 1))
        _check_do_not_commit(line, filename, num, errors)
        if not filename.endswith(".cpp") and line.startswith("#define ") \
           and not line.startswith("#define %s" % cppprefix) \
           and not line.startswith("#define %s" % altcppprefix) \
           and not line.startswith("#define EIGEN_YES_I_KNOW_SPARSE_"
                                   "MODULE_IS_NOT_STABLE_YET"):
            found = False
            fline = line.replace("#define", "#undef")
            for (onum, oline) in enumerate(fh):
                if onum > num and oline.startswith(fline):
                    found = True
            if not found:
                errors.append(
                    '%s:%d: error: Preprocessor symbols must start with %s or %s'
                    % (filename, num + 1, cppprefix, altcppprefix))
        blank = (len(line) == 0)
        if line.startswith('#include "'):
            configh = True
        if blank and num == 0:
            errors.append('%s:1: File has leading blank line(s)' % filename)
    if exported and filename.endswith(".h") and not file_line:
        # lazy hack with the replace
        errors.append('%s:2: Exported header must have a line  %s' %
                      (filename, file_line_string))
示例#5
0
 def test_get_project_info(self):
     """Test get_project_info()"""
     with utils.TempDir() as tmpdir:
         subdir = os.path.join(tmpdir, 'subdir')
         os.mkdir(subdir)
         fname = os.path.join(tmpdir, '.imp_info.py')
         utils.write_file(fname, '{\n"name": "foo"\n}\n')
         for d in subdir, tmpdir:
             self.assertEqual(python_tools.get_project_info(d),
                              {'name': 'foo'})
         self.assertRaises(ValueError, python_tools.get_project_info,
                           '/not/exist')
 def test_get_project_info(self):
     """Test get_project_info()"""
     with utils.TempDir() as tmpdir:
         subdir = os.path.join(tmpdir, 'subdir')
         os.mkdir(subdir)
         fname = os.path.join(tmpdir, '.imp_info.py')
         utils.write_file(fname, '{\n"name": "foo"\n}\n')
         for d in subdir, tmpdir:
             self.assertEqual(python_tools.get_project_info(d),
                              {'name':'foo'})
         self.assertRaises(ValueError, python_tools.get_project_info,
                           '/not/exist')