pyproject_parser

Parser for pyproject.toml.

Classes:

PyProject([build_system, project, tool])

Represents a pyproject.toml file.

PyProjectTomlEncoder([preserve])

Custom TOML encoder supporting types in pyproject_parser.classes and packaging.

Data:

_PP

Invariant TypeVar bound to pyproject_parser.PyProject.

class PyProject(build_system=None, project=None, tool={})[source]

Bases: object

Represents a pyproject.toml file.

Parameters

Methods:

__eq__(other)

Return self == other.

__repr__()

Return a string representation of the PyProject.

dump(filename[, encoder])

Write as TOML to the given file.

dumps([encoder])

Serialise to TOML.

from_dict(d)

Construct an instance of PyProject from a dictionary.

load(filename[, set_defaults])

Load the pyproject.toml configuration mapping from the given file.

reformat(filename[, encoder])

Reformat the given pyproject.toml file.

resolve_files()

Resolve the file key in readme and license (if present) to retrieve the content of the file.

to_dict()

Returns a dictionary containing the contents of the class.

Attributes:

build_system

Represents the build-system table defined in PEP 517 and PEP 518.

build_system_table_parser

The AbstractConfigParser to parse the build-system table with.

project

Represents the project table defined in PEP 621.

project_table_parser

The AbstractConfigParser to parse the project table with.

tool

Represents the tool table defined in PEP 518.

tool_parsers

A mapping of subtable names to AbstractConfigParser objects to parse the tool table with.

__eq__(other)

Return self == other.

Return type

bool

__repr__()

Return a string representation of the PyProject.

Return type

str

build_system

Type:    Optional[BuildSystemDict]

Represents the build-system table defined in PEP 517 and PEP 518.

build_system_table_parser = <pyproject_parser.parsers.BuildSystemParser object>

Type:    ClassVar[BuildSystemParser]

The AbstractConfigParser to parse the build-system table with.

dump(filename, encoder=<class 'PyProjectTomlEncoder'>)[source]

Write as TOML to the given file.

Parameters
Return type

str

Returns

A string containing the TOML representation.

dumps(encoder=<class 'PyProjectTomlEncoder'>)[source]

Serialise to TOML.

Parameters

encoder (Union[Type[TomlEncoder], TomlEncoder]) – The TomlEncoder to use for constructing the output string. Default pyproject_parser.PyProjectTomlEncoder.

Return type

str

classmethod from_dict(d)[source]

Construct an instance of PyProject from a dictionary.

Parameters

d (Mapping[str, Any]) – The dictionary.

Return type

~_PP

classmethod load(filename, set_defaults=False)[source]

Load the pyproject.toml configuration mapping from the given file.

Parameters
Return type

~_PP

project

Type:    Optional[ProjectDict]

Represents the project table defined in PEP 621.

project_table_parser = <pyproject_parser.parsers.PEP621Parser object>

Type:    ClassVar[PEP621Parser]

The AbstractConfigParser to parse the project table with.

classmethod reformat(filename, encoder=<class 'PyProjectTomlEncoder'>)[source]

Reformat the given pyproject.toml file.

Parameters
Return type

str

Returns

A string containing the reformatted TOML.

Changed in version 0.2.0:
resolve_files()[source]

Resolve the file key in readme and license (if present) to retrieve the content of the file.

Calling this method may mean it is no longer possible to recreate the original TOML file from this object.

to_dict()[source]

Returns a dictionary containing the contents of the class.

See also

attr.asdict()

Return type

MutableMapping[str, Any]

tool

Type:    Dict[str, Dict[str, Any]]

Represents the tool table defined in PEP 518.

tool_parsers = {}

Type:    ClassVar[Mapping[str, AbstractConfigParser]]

A mapping of subtable names to AbstractConfigParser objects to parse the tool table with.

For example, to parse [tool.whey]:

class WheyParser(AbstractConfigParser):
        pass

class CustomPyProject(PyProject):
        tool_parsers = {"whey": WheyParser()}
class PyProjectTomlEncoder(preserve=False)[source]

Bases: TomlEncoder

Custom TOML encoder supporting types in pyproject_parser.classes and packaging.

Methods:

dump_packaging_types(obj)

Convert types in packaging to TOML.

dumps(table, *, name[, inside_aot])

Serialise the given table.

format_inline_array(obj, nest_level)

Format an inline array.

format_literal(obj, *[, nest_level])

Format a literal value.

static dump_packaging_types(obj)[source]

Convert types in packaging to TOML.

Parameters

obj (Union[Version, Requirement, Marker, SpecifierSet])

Return type

str

dumps(table, *, name, inside_aot=False)[source]

Serialise the given table.

Parameters
  • name (str) – The table name.

  • inside_aot (bool) – Default False.

Return type

Iterator[str]

New in version 0.11.0.

format_inline_array(obj, nest_level)[source]

Format an inline array.

Parameters
Return type

str

New in version 0.11.0.

format_literal(obj, *, nest_level=0)[source]

Format a literal value.

Parameters
  • obj (object)

  • nest_level (int) – Default 0.

Return type

str

New in version 0.11.0.

_PP = TypeVar(_PP, bound=PyProject)

Type:    TypeVar

Invariant TypeVar bound to pyproject_parser.PyProject.