pyproject_parser.utils

Utility functions.

Exceptions:

PyProjectDeprecationWarning

Warning for the use of deprecated features in pyproject.toml.

Functions:

content_type_from_filename(filename)

Return the inferred content type for the given (readme) filename.

indent_join(iterable)

Join an iterable of strings with newlines, and indent each line with a tab if there is more then one element.

indent_with_tab(text[, depth, predicate])

Adds '\t' to the beginning of selected lines in ‘text’.

render_markdown(content)

Attempt to render the given content as Markdown.

render_rst(content[, filename])

Attempt to render the given content as ReStructuredText.

exception PyProjectDeprecationWarning[source]

Bases: Warning

Warning for the use of deprecated features in pyproject.toml.

This is a user-facing warning which will be shown by default. For developer-facing warnings intended for direct consumers of this library, use a standard DeprecationWarning.

New in version 0.5.0.

content_type_from_filename(filename)[source]

Return the inferred content type for the given (readme) filename.

Parameters

filename (Union[str, Path, PathLike])

Return type

Literal['text/markdown', 'text/x-rst', 'text/plain']

indent_join(iterable)[source]

Join an iterable of strings with newlines, and indent each line with a tab if there is more then one element.

Parameters

iterable (Iterable[str])

Return type

str

New in version 0.14.0.

indent_with_tab(text, depth=1, predicate=None)[source]

Adds '\t' to the beginning of selected lines in ‘text’.

Parameters
  • text (str) – The text to indent.

  • depth (int) – The depth of the indentation. Default 1.

  • predicate (Optional[Callable[[str], bool]]) – If given, '\t' will only be added to the lines where predicate(line) is :py:obj`True`. If predicate is not provided, it will default to adding '\t' to all non-empty lines that do not consist solely of whitespace characters. Default None.

Return type

str

New in version 0.14.0.

render_markdown(content)[source]

Attempt to render the given content as Markdown.

Attention

This function has the following additional requirements:

docutils<0.22,>=0.16
readme-renderer[md]>=27.0

These can be installed as follows:

python -m pip install pyproject-parser[readme]
Parameters

content (str)

render_rst(content, filename='<string>')[source]

Attempt to render the given content as ReStructuredText.

Attention

This function has the following additional requirements:

docutils<0.22,>=0.16
readme-renderer[md]>=27.0

These can be installed as follows:

python -m pip install pyproject-parser[readme]
Parameters

Changed in version 0.8.0: Added the filename argument.