docstripy API#

docstripy.difference#

Classes and functions to manage difference between files.

satenize_ranges(ranges, to_insert_list)#

Check if the ranges are overlapping.

Return type:

List[List[int]]

order_lists(ranges, lines, to_insert)#

Order the ranges in descending order and lines accordingly.

Return type:

Tuple[List[List[int]], List[str], List[bool]]

split_line(line)#

Split a line in multiple lines using ‘n’.

Return type:

List[str]

apply_diff(ranges, lines, old_lines, *, to_insert=False)#

Apply the difference to a list of lines.

Parameters:
  • ranges (List[List[int]]) – List of ranges of docstring line numbers [start, end]. Includes line at start, excludes line at end.

  • lines (List[str]) – List of lines to add to the file.

  • old_lines (List[str]) – List of lines of the original file.

  • to_insert (Union[bool, List[bool]], optional) – Whether to insert the lines or overwrite them instead. If a list is given, it should have the same length as ranges. Otherwise, the same value will be used for all ranges. By default, False.

Return type:

List[str]

docstripy.file_parser#

File parsing functions.

parse_ranges(lines)#

Parse source code lines ranges.

Parameters:

lines (List[str]) – List of lines to parse.

Return type:

Tuple[List[List[int]], List[List[int]]]

Returns:

  • ranges_docstr (List[List[int]]) – Ranges of lines containing docstrings.

  • ranges_def (List[List[int]]) – Ranges of lines containing function definitions.

docstring_parse_range(line, ind_line, states)#

Parse docstring lines range from source code.

Return type:

dict

is_def_line(strip_line)#

Return whether the line is a function or class definition.

Return type:

bool

def_parse_range(line, ind_line, states)#

Parse signature lines range from source code.

Return type:

dict

docstripy.line_break#

Line break function.

line_break(lines, max_line_length, num_add_char=0)#

Break lines at a given length.

Parameters:
  • lines (List[str]) – List of lines to break.

  • max_line_length (int) – Maximum line length.

  • num_add_char (int, optional) – Number of additional characters to add at the first line that are not on the lines list. By default, 0.

Return type:

List[str]

break_sentences(sentences, max_line_length)#

Break sentences at a given length.

Return type:

List[str]

docstripy.lines_routines#

Routines on code source lines.

add_eol(lines)#

Add end of lines.

Return type:

List[str]

remove_indent(lines)#

Remove indent from lines.

Return type:

List[str]

add_indent(lines, indent)#

Add indent from lines.

Return type:

List[str]

find_indent(lines)#

Find indentation of a docstring.

Return type:

int

find_prefix(lines, prefix_start, prefix_continue, *, dash=False)#

Find the index of consecutive lines starting with prefix.

Parameters:
  • lines (List[str]) – Lines of the docstring.

  • prefix_start (Tuple[str, ...]) – Prefixes string of the first line.

  • prefix_continue (Tuple[str, ...]) – Prefixes string of the following lines.

  • dash (bool, optional) – Whether to expect a dash line after the first line. By default, False.

Return type:

Tuple[int, int]

Returns:

  • start (int) – Index of the first line (or -1 if not found).

  • end (int) – Index of the last line (or -1 if not found).

clean_leading_empty(lines)#

Clean leading empty lines.

Return type:

List[str]

clean_trailing_empty(lines)#

Clean trailing empty lines.

Return type:

List[str]

remove_quotes(lines)#

Remove triple quotes and return whether the docstring is escaped or not.

Return type:

Tuple[List[str], bool]

clean_trailing_spaces(lines)#

Clean trailing spaces.

Return type:

List[str]

clean_comment(lines)#

Clean comment lines.

Return type:

List[str]

split_first_line(lines, max_line_length)#

Split first line of a docstring.

Return type:

List[str]

docstripy.main#

Main functions for parsing and building docstrings.

parse_args()#

Command line parser for docstripy.

Return type:

dict

main()#

Rewrite file(s) docstrings main function.

Return type:

None

docstripy.write#

Main functions for parsing and building docstrings.

generate_new_file(file_lines, docstr_config)#

Generate new file with the updated docstrings.

Return type:

List[str]

write_file_py(in_path, out_path, *, overwrite, docstr_config)#

Write new docstrings on a file.

Return type:

None

write_file_ipynb(in_path, out_path, *, overwrite, docstr_config)#

Write new docstrings on a file.

Return type:

None

write_files_recursive(in_path, out_path, *, overwrite, docstr_config)#

Write new docstrings on all files in a folder.

Return type:

None