sob/utilities/string.py
def split_long_docstring_lines(
    docstring: str, max_line_length: int = MAX_LINE_LENGTH
) -> str:
    """
    Split long docstring lines

    >>> print(split_long_docstring_lines(
    ...     '    Lorem ipsum dolor sit amet, consectetur adipiscing elit. '
    ...     'Nullam faucibu odio a urna elementum, eu tempor nisl efficitu'
    ... ))
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam faucibu
        odio a urna elementum, eu tempor nisl efficitu
    """
    line: str
    indent_: str = "    "
    if "\t" in docstring:
        docstring = docstring.replace("\t", indent_)
    lines: List[str] = docstring.split("\n")
    indentation_length: int = sys.maxsize
    for line in filter(lambda line: line, lines):
        matched = re.match(r"^[ ]+", line)
        if matched:
            indentation_length = min(indentation_length, len(matched.group()))
        else:
            indentation_length = 0
            break
    if indentation_length < sys.maxsize:
        wrapped_lines: List[str] = []
        for line in lines:
            wrapped_lines.append(
                split_long_comment_line(
                    indent_ + line[indentation_length:],
                    max_line_length,
                    prefix="",
                )
            )
        docstring = "\n".join(wrapped_lines)
    # Strip trailing whitespace and empty lines
    return re.sub(r"[ ]+(\n|$)", r"\1", docstring)

    Split long docstring lines

    >>> print(split_long_docstring_lines(
    ...     '    Lorem ipsum dolor sit amet, consectetur adipiscing elit. '
    ...     'Nullam faucibu odio a urna elementum, eu tempor nisl efficitu'
    ... ))
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam faucibu
        odio a urna elementum, eu tempor nisl efficitu
    
Split long docstring lines
>>> print(split_long_docstring_lines(
'    Lorem ipsum dolor sit amet, consectetur adipiscing elit. '
'Nullam faucibu odio a urna elementum, eu tempor nisl efficitu'
))
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam faucibu
odio a urna elementum, eu tempor nisl efficitu
Split long docstring lines >>> print ( split_long_docstring_lines ( ' Lorem ipsum dolor sit amet consectetur adipiscing elit . ' ' Nullam faucibu odio a urna elementum eu tempor nisl efficitu ' )) Lorem ipsum dolor sit amet consectetur adipiscing elit . Nullam faucibu odio a urna elementum eu tempor nisl efficitu
def split_long_docstring_lines(
    docstring: str, max_line_length: int = MAX_LINE_LENGTH
) -> str:
    line: str
    indent_: str = "    "
    if "\t" in docstring:
        docstring = docstring.replace("\t", indent_)
    lines: List[str] = docstring.split("\n")
    indentation_length: int = sys.maxsize
    for line in filter(lambda line: line, lines):
        matched = re.match(r"^[ ]+", line)
        if matched:
            indentation_length = min(indentation_length, len(matched.group()))
        else:
            indentation_length = 0
            break
    if indentation_length < sys.maxsize:
        wrapped_lines: List[str] = []
        for line in lines:
            wrapped_lines.append(
                split_long_comment_line(
                    indent_ + line[indentation_length:],
                    max_line_length,
                    prefix="",
                )
            )
        docstring = "\n".join(wrapped_lines)
    return re.sub(r"[ ]+(\n|$)", r"\1", docstring)
def split_long_docstring_lines ( docstring : str , max_line_length : int = MAX_LINE_LENGTH ) -> str : line : str indent_ : str = "    " if "\t" in docstring : docstring = docstring . replace ( "\t" , indent_ ) lines : List [ str ] = docstring . split ( "\n" ) indentation_length : int = sys . maxsize for line in filter ( lambda line : line , lines ) : matched = re . match ( r"^[ ]+" , line ) if matched : indentation_length = min ( indentation_length , len ( matched . group ( ) ) ) else : indentation_length = 0 break if indentation_length < sys . maxsize : wrapped_lines : List [ str ] = [ ] for line in lines : wrapped_lines . append ( split_long_comment_line ( indent_ + line [ indentation_length : ] , max_line_length , prefix = "" , ) ) docstring = "\n" . join ( wrapped_lines ) return re . sub ( r"[ ]+(\n|$)" , r"\1" , docstring )
Split long docstring lines
>>> print(split_long_docstring_lines(
...     '    Lorem ipsum dolor sit amet, consectetur adipiscing elit. '
Split long docstring lines >>> print ( split_long_docstring_lines ( ... ' Lorem ipsum dolor sit amet consectetur adipiscing elit . '
"""
    Split long docstring lines

    >>> print(split_long_docstring_lines(
    ...     '    Lorem ipsum dolor sit amet, consectetur adipiscing elit. '
    ...     'Nullam faucibu odio a urna elementum, eu tempor nisl efficitu'
    ... ))
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam faucibu
        odio a urna elementum, eu tempor nisl efficitu
    """ # Strip trailing whitespace and empty lines
docstring
str
max_line_length
int