pyproject_parser
¶
Parser for pyproject.toml
.
Classes:
|
Represents a |
|
Custom TOML encoder supporting types in |
Data:
Invariant |
-
class
PyProject
(build_system=None, project=None, tool={})[source]¶ Bases:
object
Represents a
pyproject.toml
file.- Parameters
build_system (
Optional
[BuildSystemDict
]) – Represents the build-system table defined in PEP 517 and PEP 518. DefaultNone
.project (
Optional
[ProjectDict
]) – Represents the project table defined in PEP 621. DefaultNone
.tool (
Dict
[str
,Dict
[str
,Any
]]) – Represents the tool table defined in PEP 518. Default{}
.
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 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:
Represents the build-system table defined in PEP 517 and PEP 518.
The
AbstractConfigParser
to parse the build-system table with.Represents the project table defined in PEP 621.
The
AbstractConfigParser
to parse the project table with.Represents the tool table defined in PEP 518.
A mapping of subtable names to
AbstractConfigParser
objects to parse the tool table with.-
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
filename (
Union
[str
,Path
,PathLike
]) – The filename to write to.encoder (
Union
[Type
[TomlEncoder
],TomlEncoder
]) – TheTomlEncoder
to use for constructing the output string. Defaultpyproject_parser.PyProjectTomlEncoder
.
- Return type
- Returns
A string containing the TOML representation.
-
dumps
(encoder=<class 'PyProjectTomlEncoder'>)[source]¶ Serialise to TOML.
- Parameters
encoder (
Union
[Type
[TomlEncoder
],TomlEncoder
]) – TheTomlEncoder
to use for constructing the output string. Defaultpyproject_parser.PyProjectTomlEncoder
.- Return type
-
classmethod
load
(filename, set_defaults=False)[source]¶ Load the
pyproject.toml
configuration mapping from the given file.
-
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
filename (
Union
[str
,Path
,PathLike
]) – The file to reformat.encoder (
Union
[Type
[TomlEncoder
],TomlEncoder
]) – TheTomlEncoder
to use for constructing the output string. Defaultpyproject_parser.PyProjectTomlEncoder
.
- Return type
- Returns
A string containing the reformatted TOML.
Changed in version 0.2.0:Added the
encoder
argument.The parser configured as
project_table_parser
is now used to parse the project table, rather than always usingPEP621Parser
.
-
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.
-
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
-
dumps
(table, *, name, inside_aot=False)[source]¶ Serialise the given table.
- Parameters
- Return type
New in version 0.11.0.
-
static
-
_PP
= TypeVar(_PP, bound=PyProject)¶ Type:
TypeVar
Invariant
TypeVar
bound topyproject_parser.PyProject
.