pyproject_parser¶
Parser for pyproject.toml.
Classes:
|
Represents a |
|
Custom TOML encoder supporting types in |
Data:
Invariant |
-
class
PyProject(build_system=None, dependency_groups=None, project=None, tool={})[source]¶ Bases:
objectRepresents a
pyproject.tomlfile.- Parameters
build_system (
Optional[BuildSystemDict]) – Represents the build-system table defined in PEP 517 and PEP 518. DefaultNone.dependency_groups (
Optional[Dict[str,List[Union[str,IncludeGroupDict]]]]) – Represents the dependency groups table defined in PEP 735. 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{}.
Changed in version 0.13.0: Added
dependency_groupsanddependency_groups_table_parserproperties.Methods:
dump(filename[, encoder])Write as TOML to the given file.
dumps([encoder])Serialise to TOML.
from_dict(d)Construct an instance of
PyProjectfrom a dictionary.load(filename[, set_defaults])Load the
pyproject.tomlconfiguration mapping from the given file.reformat(filename[, encoder])Reformat the given
pyproject.tomlfile.Resolve the
filekey 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
AbstractConfigParserto parse the build-system table with.Represents the dependency groups table defined in PEP 735.
The
AbstractConfigParserto parse the dependency groups table with.Represents the project table defined in PEP 621.
The
AbstractConfigParserto parse the project table with.Represents the tool table defined in PEP 518.
A mapping of subtable names to
AbstractConfigParserobjects 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
AbstractConfigParserto parse the build-system table with.
-
dependency_groups¶ Type:
Optional[Dict[str,List[Union[str,IncludeGroupDict]]]]Represents the dependency groups table defined in PEP 735.
-
dependency_groups_table_parser= <pyproject_parser.parsers.DependencyGroupsParser object>¶ Type:
ClassVar[DependencyGroupsParser]The
AbstractConfigParserto parse the dependency groups table with.New in version 0.13.0.
-
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]) – TheTomlEncoderto 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]) – TheTomlEncoderto use for constructing the output string. Defaultpyproject_parser.PyProjectTomlEncoder.- Return type
-
classmethod
load(filename, set_defaults=False)[source]¶ Load the
pyproject.tomlconfiguration 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
AbstractConfigParserto parse the project table with.
-
classmethod
reformat(filename, encoder=<class 'PyProjectTomlEncoder'>)[source]¶ Reformat the given
pyproject.tomlfile.- Parameters
filename (
Union[str,Path,PathLike]) – The file to reformat.encoder (
Union[Type[TomlEncoder],TomlEncoder]) – TheTomlEncoderto 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
encoderargument.The parser configured as
project_table_parseris now used to parse the project table, rather than always usingPEP621Parser.
-
resolve_files()[source]¶ Resolve the
filekey 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
TOMLfile from this object.
-
tool_parsers= {}¶ Type:
ClassVar[Mapping[str,AbstractConfigParser]]A mapping of subtable names to
AbstractConfigParserobjects 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:
TomlEncoderCustom TOML encoder supporting types in
pyproject_parser.classesand 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:
TypeVarInvariant
TypeVarbound topyproject_parser.PyProject.