utils/checks.py
def sphinx_has_header(physical_line, filename, lines, line_number):
    """Check for correct headers.

    Make sure each Python file has a correct file header including
    copyright and license information.

    X101 invalid header found
    """
    # we have a state machine of sorts so we need to start on line 1. Also,
    # there's no point checking really short files
    if line_number != 1 or len(lines) < 10:
        return

    # this file uses a funky license but unfortunately it's not possible to
    # ignore specific errors on a file-level basis yet [1]. Simply skip it.
    #
    # [1] https://gitlab.com/pycqa/flake8/issues/347
    if os.path.samefile(filename, './sphinx/util/smartypants.py'):
        return

    # if the top-level package or not inside the package, ignore
    mod_name = os.path.splitext(filename)[0].strip('./\\').replace(
        '/', '.').replace('.__init__', '')
    if mod_name == 'sphinx' or not mod_name.startswith('sphinx.'):
        return

    # line number correction
    offset = 1
    if lines[0:1] == ['#!/usr/bin/env python3\n']:
        lines = lines[1:]
        offset = 2

    llist = []
    doc_open = False

    for lno, line in enumerate(lines):
        llist.append(line)
        if lno == 0:
            if line != '"""\n' and line != 'r"""\n':
                return 0, 'X101 missing docstring begin (""")'
            else:
                doc_open = True
        elif doc_open:
            if line == '"""\n':
                # end of docstring
                if lno <= 3:
                    return 0, 'X101 missing module name in docstring'
                break

            if line != '\n' and line[:4] != '    ' and doc_open:
                return 0, 'X101 missing correct docstring indentation'

            if lno == 1:
                mod_name_len = len(line.strip())
                if line.strip() != mod_name:
                    return 2, 'X101 wrong module name in docstring heading'
            elif lno == 2:
                if line.strip() != mod_name_len * '~':
                    return (3, 'X101 wrong module name underline, should be '
                            '~~~...~')
    else:
        return 0, 'X101 missing end and/or start of docstring...'

    # check for copyright and license fields
    license = llist[-2:-1]
    if not license or not license_re.match(license[0]):
        return 0, 'X101 no correct license info'

    offset = -3
    copyright = llist[offset:offset + 1]
    while copyright and copyright_2_re.match(copyright[0]):
        offset -= 1
        copyright = llist[offset:offset + 1]
    if not copyright or not copyright_re.match(copyright[0]):
        return 0, 'X101 no correct copyright info'
Check for correct headers.

    Make sure each Python file has a correct file header including
    copyright and license information.

    X101 invalid header found
    
Check for correct headers.
Make sure each Python file has a correct file header including
copyright and license information.

X101 invalid header found
Check for correct headers . Make sure each Python file has a correct file header including copyright and license information . X101 invalid header found
def sphinx_has_header(physical_line, filename, lines, line_number):
    if line_number != 1 or len(lines) < 10:
        return
     [1] https://gitlab.com/pycqa/flake8/issues/347
    if os.path.samefile(filename, './sphinx/util/smartypants.py'):
        return
     if the top-level package or not inside the package, ignore
    mod_name = os.path.splitext(filename)[0].strip('./\\').replace(
        '/', '.').replace('.__init__', '')
    if mod_name == 'sphinx' or not mod_name.startswith('sphinx.'):
        return
     line number correction
    offset = 1
    if lines[0:1] == ['!/usr/bin/env python3\n']:
        lines = lines[1:]
        offset = 2
    llist = []
    doc_open = False
    for lno, line in enumerate(lines):
        llist.append(line)
        if lno == 0:
            if line != '"""\n' and line != 'r"""\n':
                return 0, 'X101 missing docstring begin (""")'
            else:
                doc_open = True
        elif doc_open:
            if line == '"""\n':
                 end of docstring
                if lno <= 3:
                    return 0, 'X101 missing module name in docstring'
                break
            if line != '\n' and line[:4] != '    ' and doc_open:
                return 0, 'X101 missing correct docstring indentation'
            if lno == 1:
                mod_name_len = len(line.strip())
                if line.strip() != mod_name:
                    return 2, 'X101 wrong module name in docstring heading'
            elif lno == 2:
                if line.strip() != mod_name_len * '~':
                    return (3, 'X101 wrong module name underline, should be '
                            '~~~...~')
    else:
        return 0, 'X101 missing end and/or start of docstring...'
     check for copyright and license fields
    license = llist[-2:-1]
    if not license or not license_re.match(license[0]):
        return 0, 'X101 no correct license info'
    offset = -3
    copyright = llist[offset:offset + 1]
    while copyright and copyright_2_re.match(copyright[0]):
        offset -= 1
        copyright = llist[offset:offset + 1]
    if not copyright or not copyright_re.match(copyright[0]):
        return 0, 'X101 no correct copyright info'
def sphinx_has_header ( physical_line , filename , lines , line_number ) : if line_number != 1 or len ( lines ) < 10 : return if os . path . samefile ( filename , './sphinx/util/smartypants.py' ) : return mod_name = os . path . splitext ( filename ) [ 0 ] . strip ( './\\' ) . replace ( '/' , '.' ) . replace ( '.__init__' , '' ) if mod_name == 'sphinx' or not mod_name . startswith ( 'sphinx.' ) : return offset = 1 if lines [ 0 : 1 ] == [ '#!/usr/bin/env python3\n' ] : lines = lines [ 1 : ] offset = 2 llist = [ ] doc_open = False for lno , line in enumerate ( lines ) : llist . append ( line ) if lno == 0 : if line != '"""\n' and line != 'r"""\n' : return 0 , 'X101 missing docstring begin (""")' else : doc_open = True elif doc_open : if line == '"""\n' : if lno <= 3 : return 0 , 'X101 missing module name in docstring' break if line != '\n' and line [ : 4 ] != '    ' and doc_open : return 0 , 'X101 missing correct docstring indentation' if lno == 1 : mod_name_len = len ( line . strip ( ) ) if line . strip ( ) != mod_name : return 2 , 'X101 wrong module name in docstring heading' elif lno == 2 : if line . strip ( ) != mod_name_len * '~' : return ( 3 , 'X101 wrong module name underline, should be ' '~~~...~' ) else : return 0 , 'X101 missing end and/or start of docstring...' license = llist [ - 2 : - 1 ] if not license or not license_re . match ( license [ 0 ] ) : return 0 , 'X101 no correct license info' offset = - 3 copyright = llist [ offset : offset + 1 ] while copyright and copyright_2_re . match ( copyright [ 0 ] ) : offset -= 1 copyright = llist [ offset : offset + 1 ] if not copyright or not copyright_re . match ( copyright [ 0 ] ) : return 0 , 'X101 no correct copyright info'
Check for correct headers.
Check for correct headers .
"""Check for correct headers.

    Make sure each Python file has a correct file header including
    copyright and license information.

    X101 invalid header found
    """ # we have a state machine of sorts so we need to start on line 1. Also, # there's no point checking really short files # this file uses a funky license but unfortunately it's not possible to # ignore specific errors on a file-level basis yet [1]. Simply skip it. # # [1] https://gitlab.com/pycqa/flake8/issues/347 # if the top-level package or not inside the package, ignore # line number correction # end of docstring # check for copyright and license fields
physical_line
filename
lines
line_number